diff options
Diffstat (limited to 'activerecord/lib/active_record/callbacks.rb')
-rwxr-xr-x | activerecord/lib/active_record/callbacks.rb | 41 |
1 files changed, 6 insertions, 35 deletions
diff --git a/activerecord/lib/active_record/callbacks.rb b/activerecord/lib/active_record/callbacks.rb index 9a9bf28323..67a4117d20 100755 --- a/activerecord/lib/active_record/callbacks.rb +++ b/activerecord/lib/active_record/callbacks.rb @@ -183,14 +183,8 @@ module ActiveRecord base.send :alias_method_chain, method, :callbacks end - CALLBACKS.each do |method| - base.class_eval <<-"end_eval" - def self.#{method}(*callbacks, &block) - callbacks << block if block_given? - write_inheritable_array(#{method.to_sym.inspect}, callbacks) - end - end_eval - end + base.send :include, ActiveSupport::Callbacks + base.define_callbacks *CALLBACKS end # Is called when the object was instantiated by one of the finders, like <tt>Base.find</tt>. @@ -301,38 +295,15 @@ module ActiveRecord def callback(method) notify(method) - callbacks_for(method).each do |callback| - result = case callback - when Symbol - self.send(callback) - when String - eval(callback, binding) - when Proc, Method - callback.call(self) - else - if callback.respond_to?(method) - callback.send(method, self) - else - raise ActiveRecordError, "Callbacks must be a symbol denoting the method to call, a string to be evaluated, a block to be invoked, or an object responding to the callback method." - end - end - return false if result == false - end + result = run_callbacks(method) { |result, object| result == false } - result = send(method) if respond_to_without_attributes?(method) + if result != false && respond_to_without_attributes?(method) + result = send(method) + end return result end - def callbacks_for(method) - self.class.read_inheritable_attribute(method.to_sym) or [] - end - - def invoke_and_notify(method) - notify(method) - send(method) if respond_to_without_attributes?(method) - end - def notify(method) #:nodoc: self.class.changed self.class.notify_observers(method, self) |