Module: Callbacks::InstanceMethods

Defined in:
lib/instancemethods.rb

Instance Method Summary collapse

Instance Method Details

#trigger_callback_actions(method, type) ⇒ Object



4
5
6
7
8
# File 'lib/instancemethods.rb', line 4

def trigger_callback_actions(method, type)
  trigger_class_callback_actions(method, type) if self.class.respond_to?(:callback_actions_for)
  trigger_metaclass_callback_actions(method, type) if self.metaclass.respond_to?(:callback_actions_for)
  #Should I return something?
end

#trigger_class_callback_actions(method, type) ⇒ Object

TODO: do something with a block or proc or something :p Instead of self.class/self.metaclass



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/instancemethods.rb', line 12

def trigger_class_callback_actions(method, type)
  self.class.callback_actions_for(method, type).each do |callback|
    
    if callback.block
      self.instance_eval(&callback.block)
    else
      callback.proc.call
    end
  end
  
  #I'm not happy with this...
  if self.respond_to?("#{type}_#{method}")
    self.send("#{type}_#{method}")
  end
end

#trigger_metaclass_callback_actions(method, type) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/instancemethods.rb', line 28

def trigger_metaclass_callback_actions(method, type)
  self.metaclass.callback_actions_for(method, type).each do |callback|
    
    if callback.block
      return self.instance_eval(&callback.block)
    else
      callback.proc.call
    end
  end
  #Should I return something?
end