Module: Lennarb::Plugins::Hooks::ClassMethods
- Defined in:
- lib/lennarb/plugins/hooks.rb
Instance Method Summary collapse
- #after(paths = '*', &block) ⇒ Object
- #before(paths = '*', &block) ⇒ Object
- #inherited(subclass) ⇒ Object
Instance Method Details
#after(paths = '*', &block) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/lennarb/plugins/hooks.rb', line 24 def after(paths = '*', &block) paths = Array(paths) @_after_hooks ||= {} paths.each do |path| @_after_hooks[path] ||= [] @_after_hooks[path] << block end end |
#before(paths = '*', &block) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/lennarb/plugins/hooks.rb', line 14 def before(paths = '*', &block) paths = Array(paths) @_before_hooks ||= {} paths.each do |path| @_before_hooks[path] ||= [] @_before_hooks[path] << block end end |
#inherited(subclass) ⇒ Object
34 35 36 37 38 |
# File 'lib/lennarb/plugins/hooks.rb', line 34 def inherited(subclass) super subclass.instance_variable_set(:@_before_hooks, @_before_hooks&.dup || {}) subclass.instance_variable_set(:@_after_hooks, @_after_hooks&.dup || {}) end |