class Guard::Plugin


plugins.
the ‘Guard::GuardName` instance will be removed from the active Guard
If one of those methods raises an exception other than `:task_has_failed`,
from a watcher, you can set the `any_return` option to true.
paths to Guard, but if your Guard plugin wants to allow any return value
Watchers for a Guard plugin should return a file path or an array of files
at `lib/guard/guard-name/templates/Guardfile`.
Each Guard plugin should provide a template Guardfile located within the Gem
end
end
throw :task_has_failed
if !runner.run()
def run_all
@example Throw :task_has_failed
@see Guard::Group
tasks will be aborted when the group has set the `:halt_on_fail` option.
your Guard plugin method was not successful, and successive Guard plugin
for further evaluation. You can throw `:task_has_failed` to indicate that
method is not evaluated by Guard, but it’ll be passed to the “_end” hook
you want to support this kind of task. The return value of each Guard task
In each of these Guard task methods you have to implement some work when
implemented separately with a specific behavior.
(additions, modifications, removals) in once, or each task can be
{#run_on_changes} could be implemented to handle all the changes task case
modification.
{#run_on_removals}) task methods depending on user interaction and file
{#run_on_changes} ({#run_on_additions}, {#run_on_modifications} and
Guard will trigger the {#start}, {#stop}, {#reload}, {#run_all} and
Base class from which every Guard plugin implementation must inherit.

def self.add_callback(listener, guard_plugin, events)

Parameters:
  • events (Array) -- the events to register
  • guard_plugin (Guard::Plugin) -- the Guard plugin to add the callback
  • listener (Block) -- the listener to notify
def self.add_callback(listener, guard_plugin, events)
  Array(events).each do |event|
    callbacks[[guard_plugin, event]] << listener
  end
end

def self.callbacks


Guardfile.
Get all callbacks registered for all Guard plugins present in the
def self.callbacks
  @callbacks ||= Hash.new { |hash, key| hash[key] = [] }
end

def self.non_namespaced_classname

Returns:
  • (String) -

Other tags:
    Example: Non-namespaced class name for Guard::RSpec -
def self.non_namespaced_classname
  to_s.sub("Guard::", "")
end

def self.non_namespaced_name

Returns:
  • (String) -

Other tags:
    Example: Non-namespaced name for Guard::RSpec -
def self.non_namespaced_name
  non_namespaced_classname.downcase
end

def self.notify(guard_plugin, event, *args)

Parameters:
  • args (Array) -- the arguments for the listener
  • event (Symbol) -- the event to trigger
  • guard_plugin (Guard::Plugin) -- the Guard plugin to add the callback
def self.notify(guard_plugin, event, *args)
  callbacks[[guard_plugin, event]].each do |listener|
    listener.call(guard_plugin, event, *args)
  end
end

def self.reset_callbacks!

TODO: remove (not used anywhere)

Reset all callbacks.
def self.reset_callbacks!
  @callbacks = nil
end

def self.template(plugin_location)

Parameters:
  • plugin_location (String) -- the plugin location
def self.template(plugin_location)
  File.read(format(TEMPLATE_FORMAT, plugin_location, non_namespaced_name))
end

def _register_callbacks


that's used by Guard to know which callbacks to notify.
Add all the Guard::Plugin's callbacks to the global @callbacks array
def _register_callbacks
  callbacks.each do |callback|
    self.class.add_callback(callback[:listener], self, callback[:events])
  end
end

def hook(event, *args)

Parameters:
  • args (Array) -- the parameters are passed as is to the callbacks
  • event (Symbol, String) -- the name of the Guard event

Other tags:
    Example: Add a hook with a String -
    Example: Add a hook with a Symbol -
def hook(event, *args)
  hook_name = if event.is_a? Symbol
                calling_method = caller[0][/`([^']*)'/, 1]
                "#{ calling_method }_#{ event }"
              else
                event
              end
  UI.debug "Hook :#{ hook_name } executed for #{ self.class }"
  self.class.notify(self, hook_name.to_sym, *args)
end

def initialize(options = {})

Options Hash: (**options)
  • any_return (Boolean) -- allow any object to be returned from
  • group (Symbol) -- the group this Guard plugin belongs to
  • watchers (Array) -- the Guard plugin file

Parameters:
  • options (Hash) -- the Guard plugin options
def initialize(options = {})
  group_name = options.delete(:group) { :default }
  @group = Guard.state.session.groups.add(group_name)
  @watchers = options.delete(:watchers) { [] }
  @callbacks = options.delete(:callbacks) { [] }
  @options = options
  _register_callbacks
end

def name

Returns:
  • (String) -

Other tags:
    Example: Name for Guard::RSpec -
def name
  @name ||= self.class.non_namespaced_name
end

def title

Returns:
  • (String) -

Other tags:
    Example: Title for Guard::RSpec -
def title
  @title ||= self.class.non_namespaced_classname
end

def to_s

Returns:
  • (String) - the string representation

Other tags:
    Example: String representation of an instance of the Guard::RSpec plugin -
def to_s
  "#<#{self.class} @name=#{name} @group=#{group} @watchers=#{watchers}"\
    " @callbacks=#{callbacks} @options=#{options}>"
end