Module: ActiveModelCachers::Hook::Depdenencies

Defined in:
lib/active_model_cachers/hook/dependencies.rb

Instance Method Summary collapse

Instance Method Details

#load_hooksObject


15
16
17
# File 'lib/active_model_cachers/hook/dependencies.rb', line 15

def load_hooks
  @load_hooks ||= Hash.new{|h, k| h[k] = [] }
end

#new_constants_inObject


19
20
21
22
# File 'lib/active_model_cachers/hook/dependencies.rb', line 19

def new_constants_in(*)
  new_constants = super.each{|s| load_hooks[s].each{|hook| s.constantize.instance_exec(&hook) } }
  return new_constants
end

#onload(const_name, &block) ⇒ Object


6
7
8
9
10
11
12
13
# File 'lib/active_model_cachers/hook/dependencies.rb', line 6

def onload(const_name, &block)
  const = const_name if not const_name.is_a?(String)
  if const or Module.const_defined?(const_name)
    (const || const_name.constantize).instance_exec(&block)
  else
    load_hooks[const_name].push(block)
  end
end