class Guard::Dsl


@see github.com/guard/guard/wiki/Guardfile-examples<br><br>found, it will be appended to the current project ‘Guardfile`.
In addition, if a user configuration `.guard.rb` in your home directory is
* The `.Guardfile` in your home directory.
* The `Guardfile` in the current directory where Guard has been started
There are two possible locations for the `Guardfile`:
The DSL will also evaluate normal Ruby code.
more details.
Wiki page](github.com/guard/guard/wiki/Hooks-and-callbacks) for
You can even insert more hooks inside these methods. Please [checkout the
Guard plugins method.
{Plugin::Base#run_on_modifications} and {Plugin::Base#run_on_removals}
{Plugin::Base#run_on_changes}, {Plugin::Base#run_on_additions},
{Plugin::Base#stop}, {Plugin::Base#reload}, {Plugin::Base#run_all},
execute arbitrary code before or after any of the {Plugin::Base#start},
A more advanced DSL use is the {#callback} keyword that allows you to
{Notifier} for more information about the supported libraries.
(if you don’t want notifications, specify ‘:off` as library). Please see
configure a library, Guard will automatically pick one with default options
and pass some optional configuration options for the library. If you don’t
You can set your preferred system notification library with {#notification}
ignore and filter certain paths with the {#ignore} and {#filter} keywords.
You can optionally group the Guard plugins with the {#group} keyword and
to define the used Guard plugins and the file changes they are watching.
The main keywords of the DSL are {#guard} and {#watch}. These are necessary
describe the behaviour of Guard.
The Dsl class provides the methods that are used in each ‘Guardfile` to

def self.evaluate_guardfile(options = {})

Other tags:
    See: https://github.com/guard/guard/wiki/Upgrading-to-Guard-2.0 - How to

Deprecated:
  • Use
def self.evaluate_guardfile(options = {})
  ::Guard::UI.deprecation(::Guard::Deprecator::EVALUATE_GUARDFILE_DEPRECATION)
  ::Guard::Guardfile::Evaluator.new(options).evaluate_guardfile
end

def callback(*args, &block)

Other tags:
    See: Guard::Hooker -

Other tags:
    Yield: - a callback block

Parameters:
  • args (Array) -- the callback arguments

Other tags:
    Example: Define a callback that'll be called before the `start` and `stop` actions. -
    Example: Define a callback that'll be called before the `reload` action. -
def callback(*args, &block)
  block, events = if args.size > 1
    # block must be the first argument in that case, the yielded block is
    # ignored
    args
  else
    [block, args[0]]
  end
  @callbacks << { events: events, listener: block }
end

def group(name, options = {})

Other tags:
    See: #guard -
    See: Guard.add_group -
    See: Group -

Other tags:
    Yield: - a block where you can declare several Guard plugins

Parameters:
  • options (Hash) -- the options accepted by the group
  • name (Symbol, String) -- the group name called from the CLI

Other tags:
    Example: Declare two groups of Guard plugins -
def group(name, options = {})
  raise ArgumentError, "'all' is not an allowed group name!" if name.to_sym == :all
  if block_given?
    ::Guard.add_group(name, options)
    @current_group = name
    yield
    @current_group = nil
  else
    ::Guard::UI.error "No Guard plugins found in the group '#{ name }', please add at least one."
  end
end

def guard(name, options = {})

Other tags:
    See: #group -
    See: #watch -
    See: Guard.add_plugin -
    See: Plugin -

Other tags:
    Yield: - a block where you can declare several watch patterns and actions

Parameters:
  • options (Hash) -- the options accepted by the Guard plugin
  • name (String) -- the Guard plugin name

Other tags:
    Example: Declare a Guard with a `watch` pattern -
    Example: Declare a Guard without `watch` patterns -
def guard(name, options = {})
  @watchers  = []
  @callbacks = []
  @current_group ||= :default
  yield if block_given?
  options.merge!(group: @current_group, watchers: @watchers, callbacks: @callbacks)
  ::Guard.add_plugin(name, options)
end

def ignore(*regexps)

Parameters:
  • regexps (Regexp) -- a pattern (or list of patterns) for ignoring paths

Other tags:
    Example: Ignore some paths -
def ignore(*regexps)
  ::Guard.listener.ignore(*regexps) if ::Guard.listener
end

def ignore!(*regexps)

Parameters:
  • regexps (Regexp) -- a pattern (or list of patterns) for ignoring paths

Other tags:
    Example: Ignore only these paths -
def ignore!(*regexps)
  @ignore_regexps ||= []
  @ignore_regexps << regexps
  ::Guard.listener.ignore!(@ignore_regexps) if ::Guard.listener
end

def interactor(options)

Parameters:
  • options (Symbol, Hash) -- either `:off` or a Hash with interactor

Other tags:
    Example: Turn off interactions -
    Example: Pass options to the interactor -
def interactor(options)
  case options
  when :off
    ::Guard::Interactor.enabled = false
  when Hash
    ::Guard::Interactor.options = options
  end
end

def logger(options)

Options Hash: (**options)
  • except (Regexp) -- does not show messages from the matching
  • only (Regexp) -- show only messages from the matching Guard
  • time_format (String, Symbol) -- the time format
  • template (String) -- the logger template
  • level (String, Symbol) -- the log level

Parameters:
  • options (Hash) -- the log options

Other tags:
    Example: Log all but not the messages from a specific Guard plugin -
    Example: Limit logging to a Guard plugin -
    Example: Set a custom time format -
    Example: Set a custom log template -
    Example: Set the log level -
def logger(options)
  if options[:level]
    options[:level] = options[:level].to_sym
    unless [:debug, :info, :warn, :error].include? options[:level]
      ::Guard::UI.warning "Invalid log level `#{ options[:level] }` ignored. Please use either :debug, :info, :warn or :error."
      options.delete :level
    end
  end
  if options[:only] && options[:except]
    ::Guard::UI.warning 'You cannot specify the logger options :only and :except at the same time.'
    options.delete :only
    options.delete :except
  end
  # Convert the :only and :except options to a regular expression
  [:only, :except].each do |name|
    if options[name]
      list = [].push(options[name]).flatten.map { |plugin| Regexp.escape(plugin.to_s) }.join('|')
      options[name] = Regexp.new(list, Regexp::IGNORECASE)
    end
  end
  ::Guard::UI.options.merge!(options)
end

def notification(notifier, options = {})

Other tags:
    See: Guard::Notifier - for available notifier and its options.

Parameters:
  • options (Hash) -- the notification library options
  • notifier (Symbol, String) -- the name of the notifier to use

Other tags:
    Example: Define multiple notifications -
def notification(notifier, options = {})
  ::Guard::Notifier.add_notifier(notifier.to_sym, options.merge(silent: false))
end

def scope(scope = {})

Parameters:
  • scopes (Hash) -- the scope for the groups and plugins

Other tags:
    Example: Scope Guard to multiple plugins -
    Example: Scope Guard to a single plugin -
    Example: Scope Guard to multiple groups -
    Example: Scope Guard to a single group -
def scope(scope = {})
  scope[:plugins] = Array(scope[:plugins] || scope[:plugin] || [])
  scope[:groups] = Array(scope[:groups] || scope[:group] || [])
  ::Guard.setup_scope(scope)
end

def watch(pattern, &action)

Other tags:
    See: #guard -
    See: Guard::Watcher -

Other tags:
    Yieldreturn: - a directory, a filename, an array of directories / filenames, or nothing (can be an arbitrary command)

Other tags:
    Yieldparam: m - matches of the pattern

Other tags:
    Yield: - a block to be run when the pattern is matched

Parameters:
  • pattern (String, Regexp) -- the pattern that Guard must watch for modification

Other tags:
    Example: Declare watchers for a Guard -
def watch(pattern, &action)
  @watchers << ::Guard::Watcher.new(pattern, action)
end