Permalink
Browse files

clean up more warnings, remove unnecessary methods, fix eval line num…

…bers. [#4193 state:resolved]

Signed-off-by: wycats <wycats@gmail.com>
  • Loading branch information...
1 parent c61ed70 commit 8c3e46c093023f9430c9772e81d58c9ee24de229 @tenderlove tenderlove committed with wycats Mar 16, 2010
@@ -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
@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)
@@ -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]
@@ -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
@@ -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)
@@ -1513,6 +1515,8 @@ def initialize(attributes = nil)
@readonly = false
@destroyed = false
@marked_for_destruction = false
+ @previously_changed = {}
+ @changed_attributes = {}
ensure_proper_type
@@ -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

0 comments on commit 8c3e46c

Please sign in to comment.