Module: BootyCall::Callbacker::ClassMethods

Defined in:
lib/booty_call/callbacker.rb

Instance Method Summary collapse

Instance Method Details

#callback_cacheObject



68
69
70
# File 'lib/booty_call/callbacker.rb', line 68

def callback_cache
  @callback_cache || superclass.callback_cache
end

#pristine_cacheObject



64
65
66
# File 'lib/booty_call/callbacker.rb', line 64

def pristine_cache
  @pristine_cache || superclass.pristine_cache
end

#run_callbacks_for(target, position, method_id, *results) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/booty_call/callbacker.rb', line 72

def run_callbacks_for(target, position, method_id, *results)
  callbacks = callback_cache[position][method_id.to_sym]
  
  handler = proc do |fn|
    fn.is_a?(Proc) ? fn : begin
      target.method(fn).arity.abs == results.length ?
        proc { send(fn, *results) } :
        proc { send(fn) }
    end
  end
  
  callbacks.empty? ? true : callbacks.map { |fn|
    target.instance_exec(*results, &handler.call(fn))
  }.all?
end