diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-01-19 18:32:58 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-01-19 18:32:58 -0800 |
commit | eb1b7294083bf28367a2bf057c216c9bd1f0f106 (patch) | |
tree | 63c472717ecfce968203dcd2c77afe91cfae2dd1 /activerecord | |
parent | 17064acb3e8a99b306924a5a01f64e1d734fe8ac (diff) | |
download | rails-eb1b7294083bf28367a2bf057c216c9bd1f0f106.tar.gz rails-eb1b7294083bf28367a2bf057c216c9bd1f0f106.tar.bz2 rails-eb1b7294083bf28367a2bf057c216c9bd1f0f106.zip |
push ivar initialization down to a common method
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/core.rb | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index 22574c4ce7..c0722e5eeb 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -152,16 +152,8 @@ module ActiveRecord # User.new({ :first_name => 'Jamie', :is_admin => true }, :without_protection => true) def initialize(attributes = nil, options = {}) @attributes = self.class.initialize_attributes(self.class.column_defaults.dup) - @association_cache = {} - @aggregation_cache = {} - @attributes_cache = {} - @new_record = true - @readonly = false - @destroyed = false - @marked_for_destruction = false - @previously_changed = {} - @changed_attributes = {} - @relation = nil + + init_internals ensure_proper_type @@ -185,13 +177,11 @@ module ActiveRecord # post.title # => 'hello world' def init_with(coder) @attributes = self.class.initialize_attributes(coder['attributes']) - @relation = nil - @attributes_cache, @previously_changed, @changed_attributes = {}, {}, {} - @association_cache = {} - @aggregation_cache = {} - @readonly = @destroyed = @marked_for_destruction = false + init_internals + @new_record = false + run_callbacks :find run_callbacks :initialize @@ -219,7 +209,8 @@ module ActiveRecord @aggregation_cache = {} @association_cache = {} - @attributes_cache = {} + @attributes_cache = {} + @new_record = true ensure_proper_type @@ -330,5 +321,18 @@ module ActiveRecord def to_ary # :nodoc: nil end + + def init_internals + @relation = nil + @aggregation_cache = {} + @association_cache = {} + @attributes_cache = {} + @previously_changed = {} + @changed_attributes = {} + @readonly = false + @destroyed = false + @marked_for_destruction = false + @new_record = true + end end end |