aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/callbacks.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-08-31 01:56:39 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-08-31 01:56:39 +0000
commit55efae2387b0542e6f943f8a3d50290c7b06ae80 (patch)
tree0d5a738622a4b7f2ac13e4a875f7f150443d821c /activerecord/lib/active_record/callbacks.rb
parent35ade47a30fbd10c3dddfad959a324f94569bf74 (diff)
downloadrails-55efae2387b0542e6f943f8a3d50290c7b06ae80.tar.gz
rails-55efae2387b0542e6f943f8a3d50290c7b06ae80.tar.bz2
rails-55efae2387b0542e6f943f8a3d50290c7b06ae80.zip
Performance: absorb instantiate and initialize_with_callbacks into the Base methods.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7380 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/callbacks.rb')
-rwxr-xr-xactiverecord/lib/active_record/callbacks.rb36
1 files changed, 3 insertions, 33 deletions
diff --git a/activerecord/lib/active_record/callbacks.rb b/activerecord/lib/active_record/callbacks.rb
index 83c54680b5..631eb911fc 100755
--- a/activerecord/lib/active_record/callbacks.rb
+++ b/activerecord/lib/active_record/callbacks.rb
@@ -177,16 +177,10 @@ module ActiveRecord
)
def self.included(base) #:nodoc:
- base.extend(ClassMethods)
- base.class_eval do
- class << self
- include Observable
- alias_method_chain :instantiate, :callbacks
- end
+ base.extend Observable
- [:initialize, :create_or_update, :valid?, :create, :update, :destroy].each do |method|
- alias_method_chain method, :callbacks
- end
+ [:create_or_update, :valid?, :create, :update, :destroy].each do |method|
+ base.send :alias_method_chain, method, :callbacks
end
CALLBACKS.each do |method|
@@ -199,36 +193,12 @@ module ActiveRecord
end
end
- module ClassMethods #:nodoc:
- def instantiate_with_callbacks(record)
- object = instantiate_without_callbacks(record)
-
- if object.respond_to_without_attributes?(:after_find)
- object.send(:callback, :after_find)
- end
-
- if object.respond_to_without_attributes?(:after_initialize)
- object.send(:callback, :after_initialize)
- end
-
- object
- end
- end
-
# Is called when the object was instantiated by one of the finders, like <tt>Base.find</tt>.
#def after_find() end
# Is called after the object has been instantiated by a call to <tt>Base.new</tt>.
#def after_initialize() end
- def initialize_with_callbacks(attributes = nil) #:nodoc:
- initialize_without_callbacks(attributes)
- result = yield self if block_given?
- callback(:after_initialize) if respond_to_without_attributes?(:after_initialize)
- result
- end
- private :initialize_with_callbacks
-
# Is called _before_ <tt>Base.save</tt> (regardless of whether it's a +create+ or +update+ save).
def before_save() end