Skip to content

Commit

Permalink
Make sure to reset defined methods after calling attribute_method_suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Jul 30, 2009
1 parent d599ea2 commit 1ae7eb5
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions activerecord/lib/active_record/attribute_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ module ClassMethods
# person.name = 'Hubert'
# person.name_changed? # => true
def attribute_method_suffix(*suffixes)
attribute_method_suffixes.concat suffixes
attribute_method_suffixes.concat(suffixes)
rebuild_attribute_method_regexp
undefine_attribute_methods
end

# Returns MatchData if method_name is an attribute method.
Expand Down Expand Up @@ -101,12 +102,12 @@ def attribute_method_suffixes

# Evaluate the definition for an attribute related method
def evaluate_attribute_method(method_definition, method_name)
generated_methods << method_name
generated_methods << method_name.to_s

begin
class_eval(method_definition, __FILE__, __LINE__)
rescue SyntaxError => err
generated_methods.delete(method_name)
generated_methods.delete(method_name.to_s)
if logger
logger.warn "Exception occurred during reader method compilation."
logger.warn "Maybe #{method_name} is not a valid Ruby identifier?"
Expand Down Expand Up @@ -137,17 +138,14 @@ def method_missing(method_id, *args, &block)
end
end

guard_private_attribute_method!(method_name, args)
if md = self.class.match_attribute_method?(method_name)
attribute_name, method_type = md.pre_match, md.to_s
if attribute_name == 'id' || @attributes.include?(attribute_name)
__send__("attribute#{method_type}", attribute_name, *args, &block)
else
super
guard_private_attribute_method!(method_name, args)
return __send__("attribute#{method_type}", attribute_name, *args, &block)
end
else
super
end
super
end

# A Person object with a name attribute can ask <tt>person.respond_to?(:name)</tt>,
Expand Down

0 comments on commit 1ae7eb5

Please sign in to comment.