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') 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') 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 From b652aa81216f718f27ba257238d4c27dd54863b2 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 17 Mar 2010 13:30:17 -0700 Subject: cleaning up a bunch of method already defined warnings [#4209 state:resolved] Signed-off-by: wycats --- activemodel/lib/active_model/attribute_methods.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'activemodel/lib/active_model') diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb index 588976f1d4..7f2959fcde 100644 --- a/activemodel/lib/active_model/attribute_methods.rb +++ b/activemodel/lib/active_model/attribute_methods.rb @@ -90,13 +90,20 @@ module ActiveModel # # => 'address_id' def define_attr_method(name, value=nil, &block) sing = singleton_class - sing.send :alias_method, "original_#{name}", name + sing.class_eval <<-eorb, __FILE__, __LINE__ + 1 + if method_defined?(:original_#{name}) + undef :original_#{name} + end + alias_method :original_#{name}, :#{name} + eorb if block_given? sing.send :define_method, name, &block else # use eval instead of a block to work around a memory leak in dev # mode in fcgi - sing.class_eval "def #{name}; #{value.to_s.inspect}; end" + sing.class_eval <<-eorb, __FILE__, __LINE__ + 1 + def #{name}; #{value.to_s.inspect}; end + eorb end end @@ -257,8 +264,13 @@ module ActiveModel if respond_to?(generate_method) send(generate_method, attr_name) else + method_name = matcher.method_name(attr_name) + generated_attribute_methods.module_eval <<-STR, __FILE__, __LINE__+1 - def #{matcher.method_name(attr_name)}(*args) + if method_defined?(:#{method_name}) + undef :#{method_name} + end + def #{method_name}(*args) send(:#{matcher.method_missing_target}, '#{attr_name}', *args) end STR -- cgit v1.2.3 From 4c7c4061558bb8781da0d54159e3cebcb0a8c07a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Fri, 26 Mar 2010 01:12:24 +0100 Subject: Remove reference to unexistent methods and fix typo. --- activemodel/lib/active_model/validations.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'activemodel/lib/active_model') diff --git a/activemodel/lib/active_model/validations.rb b/activemodel/lib/active_model/validations.rb index ba8648f8c9..6013cdb23b 100644 --- a/activemodel/lib/active_model/validations.rb +++ b/activemodel/lib/active_model/validations.rb @@ -112,7 +112,6 @@ module ActiveModel # end # end # - # This usage applies to +validate_on_create+ and +validate_on_update as well+. def validate(*args, &block) options = args.last if options.is_a?(Hash) && options.key?(:on) -- cgit v1.2.3