lib/method_callbacks.rb in method_callbacks-1.1.1 vs lib/method_callbacks.rb in method_callbacks-1.2.0
- old
+ new
@@ -14,10 +14,14 @@
def around_method(method_name, *callback_names)
define(method_name, :around, callback_names)
end
+ def proxy_result(method_name, &block)
+ define_with_block(method_name, :proxy, &block)
+ end
+
def before_method(method_name, *callback_names)
define(method_name, :before, callback_names)
define_with_block(method_name, :before, &Proc.new) if block_given?
end
@@ -55,14 +59,13 @@
def redefine_method(method)
return if !method || method.locked? || !method_defined?(method.name) || method_defined?(method.alias)
method.lock! && alias_method(method.alias, method.name)
- define_method(method.name) do
+ define_method(method.name) do |&block|
method.execute(:before, self)
- return_value = method.execute(:around, self) do
- send(method.alias)
- end
+ return_value = method.execute(:around, self) { send(method.alias) }
+ return_value = method.execute(:proxy, return_value, &block)
method.execute(:after, self)
return_value
end
method.unlock!