Permalink
Browse files

Call undefine_attribute_methods only when defining new attributes

  • Loading branch information...
1 parent 1ae68ea commit 42d0b1c8ddab9c3ffa8951bf085f5c758673e94b @oscardelben oscardelben committed Apr 2, 2012
Showing with 1 addition and 3 deletions.
  1. +1 −3 activemodel/lib/active_model/attribute_methods.rb
View
4 activemodel/lib/active_model/attribute_methods.rb
@@ -102,7 +102,6 @@ module ClassMethods
# person.name # => nil
def attribute_method_prefix(*prefixes)
self.attribute_method_matchers += prefixes.map { |prefix| AttributeMethodMatcher.new :prefix => prefix }
- undefine_attribute_methods
end
# Declares a method available for all attributes with the given suffix.
@@ -139,7 +138,6 @@ def attribute_method_prefix(*prefixes)
# person.name_short? # => true
def attribute_method_suffix(*suffixes)
self.attribute_method_matchers += suffixes.map { |suffix| AttributeMethodMatcher.new :suffix => suffix }
- undefine_attribute_methods
end
# Declares a method available for all attributes with the given prefix
@@ -177,7 +175,6 @@ def attribute_method_suffix(*suffixes)
# person.name # => 'Gemma'
def attribute_method_affix(*affixes)
self.attribute_method_matchers += affixes.map { |affix| AttributeMethodMatcher.new :prefix => affix[:prefix], :suffix => affix[:suffix] }
- undefine_attribute_methods
end
@@ -225,6 +222,7 @@ def alias_attribute(new_name, old_name)
# end
# end
def define_attribute_methods(*attr_names)
+ undefine_attribute_methods
attr_names.flatten.each { |attr_name| define_attribute_method(attr_name) }
end

6 comments on commit 42d0b1c

@carlosantoniodasilva
Ruby on Rails member

Hey, apparently this broke the build, could you take a look please?

@oscardelben

Yes, at the time I did this commit everything was green. Looking now.

@oscardelben

Hi, not sure if this was the case when I first made the patch, but there seems to be incompatibilities with activerecord attribute methods which I couldn't figure out yet. I think there's something weird going on here, but I don't want to break existing functionality, so feel free to revert the commit. Sorry.

@carlosantoniodasilva
Ruby on Rails member

@oscardelben no problem, I'll try to check it later and revert if necessary. Thanks!

@drogus
Ruby on Rails member

@carlosantoniodasilva I've reverted that merge. When I last checked it, it was fine, so apparently something has changed.

@carlosantoniodasilva
Ruby on Rails member

@drogus ok great, thanks.

Please sign in to comment.