Module: Spinach::Hookable::ClassMethods

Defined in:
lib/spinach/hookable.rb

Instance Method Summary collapse

Instance Method Details

#around_hook(hook) ⇒ Object

Adds a new around_hook to this class. Every hook defines two methods used to add new callbacks and to run them around a given block of code passing a bunch of parameters and invoking them in the order they were defined.

Examples:

class


39
40
41
42
43
44
45
46
# File 'lib/spinach/hookable.rb', line 39

def around_hook(hook)
  define_method hook do |&block|
    add_hook(hook, &block)
  end
  define_method "run_#{hook}" do |*args, &block|
    run_around_hook(hook, *args, &block)
  end
end

#hook(hook) ⇒ Object

Adds a new hook to this class. Every hook defines two methods used to add new callbacks and to run them passing a bunch of parameters.

Examples:

class


23
24
25
26
27
28
29
30
# File 'lib/spinach/hookable.rb', line 23

def hook(hook)
  define_method hook do |&block|
    add_hook(hook, &block)
  end
  define_method "run_#{hook}" do |*args, &block|
    run_hook(hook, *args, &block)
  end
end