Add yardoc for the DslDescriber.
This commit is contained in:
parent
d66a872f4a
commit
dc009d445a
@ -250,7 +250,7 @@ module Guard
|
|||||||
|
|
||||||
end
|
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
|
# @example Declare two groups of Guards
|
||||||
# group 'backend' do
|
# group 'backend' do
|
||||||
@ -267,14 +267,17 @@ module Guard
|
|||||||
# @yield a block where you can declare several guards
|
# @yield a block where you can declare several guards
|
||||||
#
|
#
|
||||||
# @see Dsl#guard
|
# @see Dsl#guard
|
||||||
|
# @see Guard::DslDescriber
|
||||||
#
|
#
|
||||||
def group(name, &guard_definition)
|
def group(name)
|
||||||
@groups = @@options[:group] || []
|
@groups = @@options[:group] || []
|
||||||
name = name.to_sym
|
name = name.to_sym
|
||||||
|
|
||||||
if guard_definition && (@groups.empty? || @groups.map(&:to_sym).include?(name))
|
if guard_definition && (@groups.empty? || @groups.map(&:to_sym).include?(name))
|
||||||
@current_group = name
|
@current_group = name
|
||||||
guard_definition.call
|
|
||||||
|
yield if block_given?
|
||||||
|
|
||||||
@current_group = nil
|
@current_group = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -295,6 +298,7 @@ module Guard
|
|||||||
# @yield a block where you can declare several watch patterns and actions
|
# @yield a block where you can declare several watch patterns and actions
|
||||||
#
|
#
|
||||||
# @see Dsl#watch
|
# @see Dsl#watch
|
||||||
|
# @see Guard::DslDescriber
|
||||||
#
|
#
|
||||||
def guard(name, options = {})
|
def guard(name, options = {})
|
||||||
@watchers = []
|
@watchers = []
|
||||||
|
@ -1,28 +1,60 @@
|
|||||||
require 'guard/dsl'
|
require 'guard/dsl'
|
||||||
|
|
||||||
module Guard
|
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
|
class DslDescriber < Dsl
|
||||||
|
|
||||||
@@guardfile_structure = [ { :guards => [] } ]
|
@@guardfile_structure = [ { :guards => [] } ]
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
|
||||||
|
# Get the Guardfile structure.
|
||||||
|
#
|
||||||
|
# @return [Array<Hash>] the structure
|
||||||
|
#
|
||||||
def guardfile_structure
|
def guardfile_structure
|
||||||
@@guardfile_structure
|
@@guardfile_structure
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
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
|
@group = true
|
||||||
guard_definition.call
|
|
||||||
|
yield if block_given?
|
||||||
|
|
||||||
@group = false
|
@group = false
|
||||||
end
|
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 = (@group ? @@guardfile_structure.last : @@guardfile_structure.first)
|
||||||
|
|
||||||
node[:guards] << { :name => name, :options => options }
|
node[:guards] << { :name => name, :options => options }
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user