Add yardoc for the DslDescriber.

This commit is contained in:
Michael Kessler 2011-09-20 11:49:05 +02:00
parent d66a872f4a
commit dc009d445a
2 changed files with 43 additions and 7 deletions

View File

@ -250,7 +250,7 @@ module Guard
end
# Declares a group of guards to be run with `guard start --group group_name`
# Declares a group of guards to be run with `guard start --group group_name`.
#
# @example Declare two groups of Guards
# group 'backend' do
@ -267,14 +267,17 @@ module Guard
# @yield a block where you can declare several guards
#
# @see Dsl#guard
# @see Guard::DslDescriber
#
def group(name, &guard_definition)
def group(name)
@groups = @@options[:group] || []
name = name.to_sym
if guard_definition && (@groups.empty? || @groups.map(&:to_sym).include?(name))
@current_group = name
guard_definition.call
yield if block_given?
@current_group = nil
end
end
@ -295,6 +298,7 @@ module Guard
# @yield a block where you can declare several watch patterns and actions
#
# @see Dsl#watch
# @see Guard::DslDescriber
#
def guard(name, options = {})
@watchers = []

View File

@ -1,28 +1,60 @@
require 'guard/dsl'
module Guard
# The DslDescriber overrides methods to create an internal structure
# of the Guardfile that is used in some inspection utility methods
# like the CLI commands `show` and `list`.
#
# @see Guard::DSL
# @see Guard::CLI
#
class DslDescriber < Dsl
@@guardfile_structure = [ { :guards => [] } ]
class << self
# Get the Guardfile structure.
#
# @return [Array<Hash>] the structure
#
def guardfile_structure
@@guardfile_structure
end
end
private
def group(name, &guard_definition)
@@guardfile_structure << { :group => name.to_sym, :guards => [] }
# Declares a group of guards.
#
# @param [String] name the group's name called from the CLI
# @yield a block where you can declare several guards
#
# @see Guard::Dsl
#
def group(name)
@@guardfile_structure << { :group => name.to_sym, :guards => [] }
@group = true
guard_definition.call
yield if block_given?
@group = false
end
def guard(name, options = {}, &watch_definition)
# Declare a guard.
#
# @param [String] name the Guard name
# @param [Hash] options the options accepted by the Guard
# @yield a block where you can declare several watch patterns and actions
#
# @see Guard::Dsl
#
def guard(name, options = {})
node = (@group ? @@guardfile_structure.last : @@guardfile_structure.first)
node[:guards] << { :name => name, :options => options }
end
end
end