Module: Ducktape::Hookable::ClassMethods
- Defined in:
- lib/ducktape/hookable.rb
Instance Method Summary collapse
-
#def_hook(event) ⇒ Object
Creates a wrapper method for #add_hook that doesn’t require the event to be passed.
-
#def_hooks(*events) ⇒ Object
Calls
def_hook
for each event passed. -
#make_handlers(*args) ⇒ Object
Overrides (decorates) existing methods to make then handleable.
-
#make_hooks(*args) ⇒ Object
Overrides (decorates) existing methods to make then hookable.
Instance Method Details
#def_hook(event) ⇒ Object
Creates a wrapper method for #add_hook that doesn’t require the event to be passed. For example, calling:
def_hook :on_init
will create a on_init
method, that can be used as:
on_init { |*_| puts 'I initialized' }
It’s the same as calling:
add_hook(:on_init) { |*_| puts 'I initialized' }
43 44 45 46 47 |
# File 'lib/ducktape/hookable.rb', line 43 def def_hook(event) define_method event, ->(method_name = nil, &block) do add_hook event, method_name, &block end end |
#def_hooks(*events) ⇒ Object
Calls def_hook
for each event passed.
50 51 52 |
# File 'lib/ducktape/hookable.rb', line 50 def def_hooks(*events) events.each { |event| def_hook(event) } end |
#make_handlers(*args) ⇒ Object
Overrides (decorates) existing methods to make then handleable. This is similar to hookable, but stops calling the hooks when a hook returns false
or nil
.
62 63 64 |
# File 'lib/ducktape/hookable.rb', line 62 def make_handlers(*args) make :handler, *args end |
#make_hooks(*args) ⇒ Object
Overrides (decorates) existing methods to make then hookable.
55 56 57 |
# File 'lib/ducktape/hookable.rb', line 55 def make_hooks(*args) make :hook, *args end |