Method: Guard.add_guard

Defined in:
lib/guard.rb

.add_guard(name, watchers = [], callbacks = [], options = {}) ⇒ Guard::Guard

Add a Guard to use.

Parameters:

  • name (String)

    the Guard name

  • watchers (Array<Watcher>) (defaults to: [])

    the list of declared watchers

  • callbacks (Array<Hash>) (defaults to: [])

    the list of callbacks

  • options (Hash) (defaults to: {})

    the Guard options (see the given Guard documentation)

Returns:



365
366
367
368
369
370
371
372
373
374
375
# File 'lib/guard.rb', line 365

def add_guard(name, watchers = [], callbacks = [], options = {})
  if name.to_sym == :ego
    UI.deprecation('Guard::Ego is now part of Guard. You can remove it from your Guardfile.')
  else
    guard_class = get_guard_class(name)
    callbacks.each { |callback| Hook.add_callback(callback[:listener], guard_class, callback[:events]) }
    guard = guard_class.new(watchers, options)
    @guards << guard
    guard
  end
end