aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/core.rb26
-rw-r--r--activerecord/lib/active_record/persistence.rb2
2 files changed, 8 insertions, 20 deletions
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb
index b53681ee20..0718688863 100644
--- a/activerecord/lib/active_record/core.rb
+++ b/activerecord/lib/active_record/core.rb
@@ -344,34 +344,22 @@ module ActiveRecord
# post = Post.allocate
# post.init_with(coder)
# post.title # => 'hello world'
- def init_with(coder)
+ def init_with(coder, &block)
coder = LegacyYamlAdapter.convert(self.class, coder)
- @attributes = self.class.yaml_encoder.decode(coder)
-
- init_internals
-
- @new_record = coder["new_record"]
-
- self.class.define_attribute_methods
-
- yield self if block_given?
-
- _run_find_callbacks
- _run_initialize_callbacks
-
- self
+ attributes = self.class.yaml_encoder.decode(coder)
+ init_with_attributes(attributes, coder["new_record"], &block)
end
##
- # Initializer used for instantiating objects that have been read from the
- # database. +attributes+ should be an attributes object, and unlike the
+ # Initialize an empty model object from +attributes+.
+ # +attributes+ should be an attributes object, and unlike the
# `initialize` method, no assignment calls are made per attribute.
#
# :nodoc:
- def init_from_db(attributes)
+ def init_with_attributes(attributes, new_record = false)
init_internals
- @new_record = false
+ @new_record = new_record
@attributes = attributes
self.class.define_attribute_methods
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index 8404119631..45ceb1e3ad 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -209,7 +209,7 @@ module ActiveRecord
# new instance of the class. Accepts only keys as strings.
def instantiate_instance_of(klass, attributes, column_types = {}, &block)
attributes = klass.attributes_builder.build_from_database(attributes, column_types)
- klass.allocate.init_from_db(attributes, &block)
+ klass.allocate.init_with_attributes(attributes, &block)
end
# Called by +instantiate+ to decide which class to use for a new