Changeset 7380
- Timestamp:
- 08/31/07 01:56:39 (1 year ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/base.rb (modified) (2 diffs)
- trunk/activerecord/lib/active_record/callbacks.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r7355 r7380 1 1 *SVN* 2 3 * Performance: absorb instantiate and initialize_with_callbacks into the Base methods. [Jeremy Kemper] 2 4 3 5 * Fixed that eager loading queries and with_scope should respect the :group option [DHH] trunk/activerecord/lib/active_record/base.rb
r7355 r7380 1096 1096 object.instance_variable_set("@attributes", record) 1097 1097 object.instance_variable_set("@attributes_cache", Hash.new) 1098 1099 if object.respond_to_without_attributes?(:after_find) 1100 object.send(:callback, :after_find) 1101 end 1102 1103 if object.respond_to_without_attributes?(:after_initialize) 1104 object.send(:callback, :after_initialize) 1105 end 1106 1098 1107 object 1099 1108 end … … 1650 1659 self.attributes = attributes unless attributes.nil? 1651 1660 self.class.send(:scope, :create).each { |att,value| self.send("#{att}=", value) } if self.class.send(:scoped?, :create) 1652 yield self if block_given? 1661 result = yield self if block_given? 1662 callback(:after_initialize) if respond_to_without_attributes?(:after_initialize) 1663 result 1653 1664 end 1654 1665 trunk/activerecord/lib/active_record/callbacks.rb
r7368 r7380 178 178 179 179 def self.included(base) #:nodoc: 180 base.extend(ClassMethods) 181 base.class_eval do 182 class << self 183 include Observable 184 alias_method_chain :instantiate, :callbacks 185 end 186 187 [:initialize, :create_or_update, :valid?, :create, :update, :destroy].each do |method| 188 alias_method_chain method, :callbacks 189 end 180 base.extend Observable 181 182 [:create_or_update, :valid?, :create, :update, :destroy].each do |method| 183 base.send :alias_method_chain, method, :callbacks 190 184 end 191 185 … … 200 194 end 201 195 202 module ClassMethods #:nodoc:203 def instantiate_with_callbacks(record)204 object = instantiate_without_callbacks(record)205 206 if object.respond_to_without_attributes?(:after_find)207 object.send(:callback, :after_find)208 end209 210 if object.respond_to_without_attributes?(:after_initialize)211 object.send(:callback, :after_initialize)212 end213 214 object215 end216 end217 218 196 # Is called when the object was instantiated by one of the finders, like <tt>Base.find</tt>. 219 197 #def after_find() end … … 221 199 # Is called after the object has been instantiated by a call to <tt>Base.new</tt>. 222 200 #def after_initialize() end 223 224 def initialize_with_callbacks(attributes = nil) #:nodoc:225 initialize_without_callbacks(attributes)226 result = yield self if block_given?227 callback(:after_initialize) if respond_to_without_attributes?(:after_initialize)228 result229 end230 private :initialize_with_callbacks231 201 232 202 # Is called _before_ <tt>Base.save</tt> (regardless of whether it's a +create+ or +update+ save).