Namespace

Guard::Hook

Guard has a hook mechanism that allows you to insert callbacks for individual Guards. By default, each of the Guard instance methods has a "_begin" and an "_end" hook. For example, the Guard::Guard#start method has a :start_begin hook that is runs immediately before Guard::Guard#start, and a :start_end hook that runs immediately after Guard::Guard#start.

Read more about [hooks and callbacks on the wiki](github.com/guard/guard/wiki/Hooks-and-callbacks).

Public Class Methods

add_callback(listener, guard_class, events) click to toggle source

Add a callback.

@param [Block] listener the listener to notify @param [Guard::Guard] guard_class the Guard class to add the callback @param [Array<Symbol>] events the events to register

# File lib/guard/hook.rb, line 80
def add_callback(listener, guard_class, events)
  _events = events.is_a?(Array) ? events : [events]
  _events.each do |event|
    callbacks[[guard_class, event]] << listener
  end
end
callbacks() click to toggle source

Get all callbacks.

# File lib/guard/hook.rb, line 70
def callbacks
  @callbacks ||= Hash.new { |hash, key| hash[key] = [] }
end
has_callback?(listener, guard_class, event) click to toggle source

Checks if a callback has been registered.

@param [Block] listener the listener to notify @param [Guard::Guard] guard_class the Guard class to add the callback @param [Symbol] event the event to look for

# File lib/guard/hook.rb, line 93
def has_callback?(listener, guard_class, event)
  callbacks[[guard_class, event]].include?(listener)
end
included(base) click to toggle source

The Hook module gets included.

@param [Class] base the class that includes the module

# File lib/guard/hook.rb, line 16
def self.included(base)
  base.send :include, InstanceMethods
end
notify(guard_class, event, *args) click to toggle source

Notify a callback.

@param [Guard::Guard] guard_class the Guard class to add the callback @param [Symbol] event the event to trigger @param [Array] args the arguments for the listener

# File lib/guard/hook.rb, line 103
def notify(guard_class, event, *args)
  callbacks[[guard_class, event]].each do |listener|
    listener.call(guard_class, event, *args)
  end
end
reset_callbacks!() click to toggle source

Reset all callbacks.

# File lib/guard/hook.rb, line 111
def reset_callbacks!
  @callbacks = nil
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.