Module: Easyop::Hooks::ClassMethods
- Defined in:
- lib/easyop/hooks.rb
Instance Method Summary collapse
- #_after_hooks ⇒ Object
- #_around_hooks ⇒ Object
-
#_before_hooks ⇒ Object
Hook lists, inherited from superclass (returns a dup so additions on a subclass don’t pollute the parent).
-
#after(*methods, &block) ⇒ Object
Add an after hook (method name or block).
-
#around(*methods, &block) ⇒ Object
Add an around hook (method name or block).
-
#before(*methods, &block) ⇒ Object
Add a before hook (method name or block).
Instance Method Details
#_after_hooks ⇒ Object
49 50 51 |
# File 'lib/easyop/hooks.rb', line 49 def _after_hooks @_after_hooks ||= _inherited_hooks(:_after_hooks) end |
#_around_hooks ⇒ Object
53 54 55 |
# File 'lib/easyop/hooks.rb', line 53 def _around_hooks @_around_hooks ||= _inherited_hooks(:_around_hooks) end |
#_before_hooks ⇒ Object
Hook lists, inherited from superclass (returns a dup so additions on a subclass don’t pollute the parent).
45 46 47 |
# File 'lib/easyop/hooks.rb', line 45 def _before_hooks @_before_hooks ||= _inherited_hooks(:_before_hooks) end |
#after(*methods, &block) ⇒ Object
Add an after hook (method name or block).
31 32 33 34 |
# File 'lib/easyop/hooks.rb', line 31 def after(*methods, &block) methods.each { |m| _after_hooks << m } _after_hooks << block if block_given? end |
#around(*methods, &block) ⇒ Object
Add an around hook (method name or block). The hook must yield (or call its first argument) to continue the chain.
38 39 40 41 |
# File 'lib/easyop/hooks.rb', line 38 def around(*methods, &block) methods.each { |m| _around_hooks << m } _around_hooks << block if block_given? end |
#before(*methods, &block) ⇒ Object
Add a before hook (method name or block).
25 26 27 28 |
# File 'lib/easyop/hooks.rb', line 25 def before(*methods, &block) methods.each { |m| _before_hooks << m } _before_hooks << block if block_given? end |