class Guard::DslDescriber
@see Guard::CLI
@see Guard::Dsl
like the CLI commands ‘show` and `list`.
of the Guardfile that is used in some inspection utility methods
The DslDescriber overrides methods to create an internal structure
def evaluate_guardfile(options = {})
-
(ArgumentError)
- when options are not a Hash
Options Hash:
(**options)
-
guardfile_contents
(String
) -- a string representing the content of a valid Guardfile -
guardfile
(String
) -- the path to a valid Guardfile -
groups
(Array
) -- the groups to evaluate
def evaluate_guardfile(options = {}) @@guardfile_structure = [{ :guards => [] }] super options end
def group(name)
- See: Guard::Dsl#group -
Other tags:
- Yield: - a block where you can declare several guards
Parameters:
-
name
(String
) -- the group's name called from the CLI
def group(name) @@guardfile_structure << { :group => name.to_sym, :guards => [] } @group = true yield if block_given? @group = false end
def guard(name, options = { })
- See: Guard::Dsl#guard -
Other tags:
- Yield: - a block where you can declare several watch patterns and actions
Parameters:
-
options
(Hash
) -- the options accepted by the Guard -
name
(String
) -- the Guard name
def guard(name, options = { }) @group ||= false node = (@group ? @@guardfile_structure.last : @@guardfile_structure.first) node[:guards] << { :name => name, :options => options } end
def guardfile_structure
-
(Array
- the structure)
def guardfile_structure @@guardfile_structure end
def list(options)
-
options
(Hash
) -- the Guard options
Other tags:
- Example: Guard list output -
def list(options) evaluate_guardfile(options) installed_guards = guardfile_structure.inject([]) do |installed, group| group[:guards].each { |guard| installed << guard[:name].to_s } if group[:guards] installed end UI.info 'Available guards:' ::Guard.guard_gem_names.sort.uniq.each do |name| UI.info " #{ name }#{ installed_guards.include?(name) ? '*' : '' }" end UI.info '' UI.info 'See also https://github.com/guard/guard/wiki/List-of-available-Guards' UI.info '* denotes ones already in your Guardfile' end
def show(options)
-
options
(Hash
) -- the Guard options
Other tags:
- Example: guard show output -
def show(options) evaluate_guardfile(options) guardfile_structure.each do |group| unless group[:guards].empty? if group[:group] UI.info "Group #{ group[:group] }:" else UI.info '(global):' end group[:guards].each do |guard| line = " #{ guard[:name] }" unless guard[:options].empty? line += ": #{ guard[:options].sort.collect { |k, v| "#{ k } => #{ v.inspect }" }.join(', ') }" end UI.info line end end end UI.info '' end