Module Hooks
In: lib/hooks.rb
lib/hooks/hook.rb
lib/hooks/version.rb
lib/hooks/instance_hooks.rb
lib/hooks/inheritable_attribute.rb

Almost like ActiveSupport::Callbacks but 76,6% less complex.

Example:

  class CatWidget < Apotomo::Widget
    define_hooks :before_dinner, :after_dinner

Now you can add callbacks to your hook declaratively in your class.

    before_dinner :wash_paws
    after_dinner { puts "Ice cream!" }
    after_dinner :have_a_desert   # => refers to CatWidget#have_a_desert

Running the callbacks happens on instances. It will run the block and have_a_desert from above.

  cat.run_hook :after_dinner

Methods

included   run_hook  

Classes and Modules

Module Hooks::ClassMethods
Module Hooks::InstanceHooks
Class Hooks::Hook
Class Hooks::HookSet

Constants

VERSION = "0.4.1"
InheritableAttribute = Uber::InheritableAttr

Public Class methods

Public Instance methods

Runs the callbacks (method/block) for the specified hook name. Additional arguments will be passed to the callback.

Example:

  cat.run_hook :after_dinner, "i want ice cream!"

will invoke the callbacks like

  desert("i want ice cream!")
  block.call("i want ice cream!")

[Validate]