Module: Hookable
- Included in:
- Specwrk::CLI::Clientable, Specwrk::CLI::Servable, Specwrk::CLI::Workable
- Defined in:
- lib/specwrk/hookable.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #included(base) ⇒ Object
- #included_hooks ⇒ Object
- #on_included(&block) ⇒ Object
- #on_setup(&block) ⇒ Object
- #setup_hooks ⇒ Object
Class Method Details
.extended(base) ⇒ Object
2 3 4 5 |
# File 'lib/specwrk/hookable.rb', line 2 def self.extended(base) base.instance_variable_set(:@included_hooks, []) base.instance_variable_set(:@setup_hooks, []) # unless base.instance_variable_defined?(:@setup_hooks) end |
Instance Method Details
#included(base) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/specwrk/hookable.rb', line 15 def included(base) super if defined?(super) base.extend ClassMethods host_hooks = base.instance_variable_defined?(:@setup_hooks) ? base.instance_variable_get(:@setup_hooks) : [] merged = host_hooks + setup_hooks base.instance_variable_set(:@setup_hooks, merged) included_hooks.each { |blk| blk.call(base) } end |
#included_hooks ⇒ Object
29 30 31 |
# File 'lib/specwrk/hookable.rb', line 29 def included_hooks @included_hooks end |
#on_included(&block) ⇒ Object
7 8 9 |
# File 'lib/specwrk/hookable.rb', line 7 def on_included(&block) included_hooks << block end |
#on_setup(&block) ⇒ Object
11 12 13 |
# File 'lib/specwrk/hookable.rb', line 11 def on_setup(&block) setup_hooks << block end |
#setup_hooks ⇒ Object
33 34 35 |
# File 'lib/specwrk/hookable.rb', line 33 def setup_hooks @setup_hooks end |