Skip to content

Commit

Permalink
push ivar initialization down to a common method
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Jan 20, 2012
1 parent 17064ac commit eb1b729
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions activerecord/lib/active_record/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,8 @@ def relation #:nodoc:
# 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

Expand All @@ -185,13 +177,11 @@ def initialize(attributes = nil, options = {})
# 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

Expand Down Expand Up @@ -219,7 +209,8 @@ def initialize_dup(other)

@aggregation_cache = {}
@association_cache = {}
@attributes_cache = {}
@attributes_cache = {}

@new_record = true

ensure_proper_type
Expand Down Expand Up @@ -330,5 +321,18 @@ def inspect
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

0 comments on commit eb1b729

Please sign in to comment.