2011-06-21 13:48:27 +00:00
|
|
|
require 'guard/dsl'
|
|
|
|
|
|
|
|
module Guard
|
2011-09-20 09:49:05 +00:00
|
|
|
|
|
|
|
# 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`.
|
|
|
|
#
|
2011-09-20 19:52:59 +00:00
|
|
|
# @see Guard::Dsl
|
2011-09-20 09:49:05 +00:00
|
|
|
# @see Guard::CLI
|
|
|
|
#
|
2011-06-21 13:48:27 +00:00
|
|
|
class DslDescriber < Dsl
|
2011-09-20 09:49:05 +00:00
|
|
|
|
2011-06-21 13:48:27 +00:00
|
|
|
@@guardfile_structure = [ { :guards => [] } ]
|
|
|
|
|
|
|
|
class << self
|
2011-09-20 09:49:05 +00:00
|
|
|
|
|
|
|
# Get the Guardfile structure.
|
|
|
|
#
|
|
|
|
# @return [Array<Hash>] the structure
|
|
|
|
#
|
2011-06-21 13:48:27 +00:00
|
|
|
def guardfile_structure
|
|
|
|
@@guardfile_structure
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2011-09-20 09:49:05 +00:00
|
|
|
# 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 => [] }
|
2011-06-21 13:48:27 +00:00
|
|
|
@group = true
|
2011-09-20 09:49:05 +00:00
|
|
|
|
|
|
|
yield if block_given?
|
|
|
|
|
2011-06-21 13:48:27 +00:00
|
|
|
@group = false
|
|
|
|
end
|
|
|
|
|
2011-09-20 09:49:05 +00:00
|
|
|
# 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 = {})
|
2011-06-21 13:48:27 +00:00
|
|
|
node = (@group ? @@guardfile_structure.last : @@guardfile_structure.first)
|
|
|
|
|
|
|
|
node[:guards] << { :name => name, :options => options }
|
|
|
|
end
|
2011-09-20 09:49:05 +00:00
|
|
|
|
2011-06-21 13:48:27 +00:00
|
|
|
end
|
|
|
|
end
|