Skip to content

Commit

Permalink
clean up more warnings, remove unnecessary methods, fix eval line num…
Browse files Browse the repository at this point in the history
…bers. [#4193 state:resolved]

Signed-off-by: wycats <wycats@gmail.com>
  • Loading branch information
tenderlove authored and wycats committed Mar 16, 2010
1 parent c61ed70 commit 8c3e46c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
11 changes: 2 additions & 9 deletions activemodel/lib/active_model/dirty.rb
Expand Up @@ -116,19 +116,12 @@ def changes
# person.save
# person.previous_changes # => {'name' => ['bob, 'robert']}
def previous_changes
previously_changed_attributes
@previously_changed
end

private
# Map of change <tt>attr => original value</tt>.
def changed_attributes

This comment has been minimized.

Copy link
@spohlenz

spohlenz Mar 20, 2010

Contributor

I'm all for removing unnecessary methods but this introduces additional complexity to the including code, requiring the ivars to be set manually (AR requires it in not one but two places!).

What advantages does this change have?

@changed_attributes ||= {}
end

# Map of fields that were changed when the model was saved
def previously_changed_attributes
@previously_changed || {}
end
attr_reader :changed_attributes

# Handle <tt>*_changed?</tt> for +method_missing+.
def attribute_changed?(attr)
Expand Down
Expand Up @@ -5,6 +5,10 @@ module Associations
# If the association has a <tt>:through</tt> option further specialization
# is provided by its child HasManyThroughAssociation.
class HasManyAssociation < AssociationCollection #:nodoc:
def initialize(owner, reflection)
@finder_sql = nil
super
end
protected
def owner_quoted_id
if @reflection.options[:primary_key]
Expand Down
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/attribute_methods/dirty.rb
Expand Up @@ -34,7 +34,7 @@ def save_with_dirty!(*args) #:nodoc:
# <tt>reload</tt> the record and clears changed attributes.
def reload_with_dirty(*args) #:nodoc:
reload_without_dirty(*args).tap do
previously_changed_attributes.clear
@previously_changed.clear
changed_attributes.clear
end
end
Expand Down
4 changes: 4 additions & 0 deletions activerecord/lib/active_record/base.rb
Expand Up @@ -1045,6 +1045,8 @@ def instantiate(record)
object.instance_variable_set(:@readonly, false)
object.instance_variable_set(:@destroyed, false)
object.instance_variable_set(:@marked_for_destruction, false)
object.instance_variable_set(:@previously_changed, {})
object.instance_variable_set(:@changed_attributes, {})

object.send(:_run_find_callbacks)
object.send(:_run_initialize_callbacks)
Expand Down Expand Up @@ -1513,6 +1515,8 @@ def initialize(attributes = nil)
@readonly = false
@destroyed = false
@marked_for_destruction = false
@previously_changed = {}
@changed_attributes = {}

ensure_proper_type

Expand Down
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/nested_attributes.rb
Expand Up @@ -243,11 +243,11 @@ def accepts_nested_attributes_for(*attr_names)
# def pirate_attributes=(attributes)
# assign_nested_attributes_for_one_to_one_association(:pirate, attributes)
# end
class_eval %{
class_eval <<-eoruby, __FILE__, __LINE__ + 1
def #{association_name}_attributes=(attributes)
assign_nested_attributes_for_#{type}_association(:#{association_name}, attributes)
end
}, __FILE__, __LINE__
eoruby
else
raise ArgumentError, "No association found for name `#{association_name}'. Has it been defined yet?"
end
Expand Down

0 comments on commit 8c3e46c

Please sign in to comment.