From 8c3e46c093023f9430c9772e81d58c9ee24de229 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 16 Mar 2010 11:26:19 -0700 Subject: clean up more warnings, remove unnecessary methods, fix eval line numbers. [#4193 state:resolved] Signed-off-by: wycats --- activemodel/lib/active_model/dirty.rb | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'activemodel/lib/active_model/dirty.rb') diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb index 5f02929a9d..cb70cf74ee 100644 --- a/activemodel/lib/active_model/dirty.rb +++ b/activemodel/lib/active_model/dirty.rb @@ -116,19 +116,12 @@ module ActiveModel # person.save # person.previous_changes # => {'name' => ['bob, 'robert']} def previous_changes - previously_changed_attributes + @previously_changed end private # Map of change attr => original value. - def changed_attributes - @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 *_changed? for +method_missing+. def attribute_changed?(attr) -- cgit v1.2.3 From df735cf5b712312a161d703f2606b145ea2d3b85 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 16 Mar 2010 15:08:38 -0700 Subject: fisting uninitialized ivar warnings. [#4198 state:resolved] Signed-off-by: wycats --- activemodel/lib/active_model/dirty.rb | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'activemodel/lib/active_model/dirty.rb') diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb index cb70cf74ee..d3a6bad6bb 100644 --- a/activemodel/lib/active_model/dirty.rb +++ b/activemodel/lib/active_model/dirty.rb @@ -91,7 +91,7 @@ module ActiveModel # person.name = 'bob' # person.changed? # => true def changed? - !changed_attributes.empty? + !@changed_attributes.empty? end # List of attributes with unsaved changes. @@ -99,7 +99,7 @@ module ActiveModel # person.name = 'bob' # person.changed # => ['name'] def changed - changed_attributes.keys + @changed_attributes.keys end # Map of changed attrs => [original value, new value]. @@ -120,22 +120,19 @@ module ActiveModel end private - # Map of change attr => original value. - attr_reader :changed_attributes - # Handle *_changed? for +method_missing+. def attribute_changed?(attr) - changed_attributes.include?(attr) + @changed_attributes.include?(attr) end # Handle *_change for +method_missing+. def attribute_change(attr) - [changed_attributes[attr], __send__(attr)] if attribute_changed?(attr) + [@changed_attributes[attr], __send__(attr)] if attribute_changed?(attr) end # Handle *_was for +method_missing+. def attribute_was(attr) - attribute_changed?(attr) ? changed_attributes[attr] : __send__(attr) + attribute_changed?(attr) ? @changed_attributes[attr] : __send__(attr) end # Handle *_will_change! for +method_missing+. @@ -146,12 +143,12 @@ module ActiveModel rescue TypeError, NoMethodError end - changed_attributes[attr] = value + @changed_attributes[attr] = value end # Handle reset_*! for +method_missing+. def reset_attribute!(attr) - __send__("#{attr}=", changed_attributes[attr]) if attribute_changed?(attr) + __send__("#{attr}=", @changed_attributes[attr]) if attribute_changed?(attr) end end end -- cgit v1.2.3