Module: Rucola::InitializeHooks

Defined in:
lib/rucola/rucola_support/initialize_hooks.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

:nodoc



24
25
26
# File 'lib/rucola/rucola_support/initialize_hooks.rb', line 24

def self.included(base) # :nodoc
  base.extend(ClassMethods)
end

Instance Method Details

#initializeObject

Calls all the hooks that have been added to the queue.

It will also call the method after_init, but only if you have defined it. Create this method to do work that you would normally do in initialize or init.



15
16
17
18
19
20
21
22
# File 'lib/rucola/rucola_support/initialize_hooks.rb', line 15

def initialize
  # get the hooks, if they exist let them all do their after initialization work.
  hooks = self.class.instance_variable_get(:@_rucola_initialize_hooks)
  hooks.each { |hook| self.instance_eval(&hook) } unless hooks.nil?
  
  # also call after_init for custom initialization code.
  send :after_init if respond_to? :after_init # TODO: test
end