Module: BootyCall::Callbacker::ClassMethods
- Defined in:
- lib/booty_call/callbacker.rb
Instance Method Summary collapse
- #callback_cache ⇒ Object
- #pristine_cache ⇒ Object
- #run_callbacks_for(target, position, method_id, *results, &block) ⇒ Object
Instance Method Details
#callback_cache ⇒ Object
71 72 73 |
# File 'lib/booty_call/callbacker.rb', line 71 def callback_cache @callback_cache || superclass.callback_cache end |
#pristine_cache ⇒ Object
67 68 69 |
# File 'lib/booty_call/callbacker.rb', line 67 def pristine_cache @pristine_cache || superclass.pristine_cache end |
#run_callbacks_for(target, position, method_id, *results, &block) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/booty_call/callbacker.rb', line 75 def run_callbacks_for(target, position, method_id, *results, &block) callbacks = callback_cache[position][method_id.to_sym] handle = proc do |fn| if fn.is_a?(Proc) block ? proc { instance_exec(block, &fn) } : fn else target.method(fn).arity.abs == results.length ? proc { send(fn, *results, &block) } : proc { send(fn, &block) } end end cancel = proc do block ? target.instance_eval(&block) : true end callbacks.empty? ? cancel[block] : callbacks.map { |fn| target.instance_exec(*results, &handle[fn]) }.all? end |