module Prong::Hooks::Executer

Public Class Methods

with_return_all(obj,name,type,&block) click to toggle source
# File lib/prong/hooks/executer.rb, line 59
def self.with_return_all(obj,name,type,&block)
  return_block = nil
  return_collection = []
  closure = Proc.new { return_block ||= block.call if block }
  callbacks = obj.class.send("_#{name}_callbacks")
  callbacks.compile([closure],type).each do |callback|
    callback[0].each { |b| next callback[1].clear unless obj.instance_exec(callback[1], &b) }
    return_collection << callback[1].map { |i| case i when Symbol then next obj.send(i) when Proc then next obj.instance_exec(&i) end }
  end
  return [return_collection.flatten].push([return_block||true].flatten)
end
without_return_all(obj,name,type,&block) click to toggle source
# File lib/prong/hooks/executer.rb, line 71
def self.without_return_all(obj,name,type,&block)
  return_block = nil
  closure = Proc.new { return_block ||= block.call if block }
  callbacks = obj.class.send("_#{name}_callbacks")
  callbacks.compile([closure],type).each do |callback|
    callback[0].each { |b| next callback[1].clear unless obj.instance_exec(callback[1], &b) }
    callback[1].each { |i| case i when Symbol then next obj.send(i) when Proc then next obj.instance_exec(&i) end }
  end
  return return_block || true
end