lib/method_callbacks/executor.rb in method_callbacks-1.1.1 vs lib/method_callbacks/executor.rb in method_callbacks-1.2.0
- old
+ new
@@ -6,14 +6,19 @@
@method = method
@type = type
@object = object
end
- def execute
- return execute_callbacks if !block_given?
-
- callbacks.empty? ? yield : execute_around_callbacks(&Proc.new)
+ def execute(&block)
+ case type
+ when :proxy
+ execute_proxy_callbacks(&block)
+ when :around
+ execute_around_callbacks(&block)
+ else
+ execute_callbacks
+ end
end
private
def callbacks
@@ -24,8 +29,12 @@
callbacks.reverse.reduce(Proc.new) { |block, callback_name| Proc.new { object.send(callback_name, &block) } }.call
end
def execute_callbacks
callbacks.each { |callback_name| callback_name.is_a?(Proc) ? object.instance_eval(&callback_name) : object.send(callback_name) }
+ end
+
+ def execute_proxy_callbacks(&block_on_call)
+ callbacks.reduce(object) { |result, block| block.call(result, &block_on_call) }
end
end
end