Module HookR::Hooks
In: lib/hookr.rb

Include this module to decorate your class with hookable goodness.

Note: remember to call super() if you define your own self.inherited().

Methods

Classes and Modules

Module HookR::Hooks::CallbackHelpers
Module HookR::Hooks::ClassMethods

Public Class methods

Public Instance methods

Add a listener object. The object should have a method defined for every hook this object publishes.

Execute all callbacks associated with the hook identified by hook_name, plus any wildcard callbacks.

When a block is supplied, this method functions differently. In that case the callbacks are executed recursively. The most recently defined callback is executed and passed an event and a set of arguments. Calling event.next will pass execution to the next most recently added callback, which again will be passed an event with a reference to the next callback, and so on. When the list of callbacks are exhausted, the block is executed as if it too were a callback. If at any point event.next is passed arguments, they will replace the value of the callback arguments for callbacks further down the chain.

In this way you can use callbacks as "around" advice to a block of code. For instance:

   execute_hook(:write_data, data) do |data|
     write(data)
   end

Here, the code exposes a :write_data hook. Any callbacks attached to the hook will "wrap" the data writing event. Callbacks might log when the data writing operation was started and stopped, or they might encrypt the data before it is written, etc.

returns the hooks exposed by this object

Remove a listener by handle or by the listener object itself

[Validate]