lib/method_callbacks.rb in method_callbacks-1.0.0 vs lib/method_callbacks.rb in method_callbacks-1.1.0

- old
+ new

@@ -1,11 +1,9 @@ require "method_callbacks/finder" require "method_callbacks/version" module MethodCallbacks - ALIAS_PREFIX = "__method_callback_alias_to_original" - def self.included(base) base.extend(ClassMethods) end module ClassMethods @@ -41,27 +39,29 @@ @_finder ||= {} @_finder[method_name] ||= MethodCallbacks::Finder.new(method_name) end def find_or_new(method_name) - finder(method_name).find_or_new + method = finder(method_name).find_or_new + redefine_method(method) + method end def method_added(method_name) redefine_method(find(method_name)) super end def redefine_method(method) - return if !method || method.locked? + return if !method || method.locked? || !method_defined?(method.name) || method_defined?(method.alias) - method.lock! && alias_method("#{ALIAS_PREFIX}_#{method.name}", method.name) + method.lock! && alias_method(method.alias, method.name) define_method(method.name) do method.execute(:before, self) return_value = method.execute(:around, self) do - send("#{ALIAS_PREFIX}_#{method.name}") + send(method.alias) end method.execute(:after, self) return_value end