diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2019-04-23 22:26:17 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2019-04-24 05:14:25 +0900 |
commit | 2c0729d8cb13100ea576337ebb7703320203c548 (patch) | |
tree | a6a2d210a96f1891705262673378a977e33bfaaa /activerecord/lib/active_record/core.rb | |
parent | 48e606f25af80cf1b774c659ed444322fa11106c (diff) | |
download | rails-2c0729d8cb13100ea576337ebb7703320203c548.tar.gz rails-2c0729d8cb13100ea576337ebb7703320203c548.tar.bz2 rails-2c0729d8cb13100ea576337ebb7703320203c548.zip |
Re-organize `init_internals`
* Avoid duplicated `@new_record` assignment
* Extract `define_attribute_methods` into `init_internals`
Diffstat (limited to 'activerecord/lib/active_record/core.rb')
-rw-r--r-- | activerecord/lib/active_record/core.rb | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index 351865dfbc..28bd7f8cdc 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -316,7 +316,7 @@ module ActiveRecord # # Instantiates a single new object # User.new(first_name: 'Jamie') def initialize(attributes = nil) - self.class.define_attribute_methods + @new_record = true @attributes = self.class._default_attributes.deep_dup init_internals @@ -353,12 +353,10 @@ module ActiveRecord # +attributes+ should be an attributes object, and unlike the # `initialize` method, no assignment calls are made per attribute. def init_with_attributes(attributes, new_record = false) # :nodoc: - init_internals - @new_record = new_record @attributes = attributes - self.class.define_attribute_methods + init_internals yield self if block_given? @@ -574,9 +572,10 @@ module ActiveRecord @destroyed = false @marked_for_destruction = false @destroyed_by_association = nil - @new_record = true @_start_transaction_state = nil @transaction_state = nil + + self.class.define_attribute_methods end def initialize_internals_callback |