Permalink
Browse files

define attribute methods in a thread safe manner

  • Loading branch information...
1 parent 9867339 commit 30efdd6e9066684dc952966ed71e23a9c7640e7e @tenderlove tenderlove committed with rafaelfranca Jul 2, 2013
Showing with 4 additions and 5 deletions.
  1. +4 −5 activerecord/lib/active_record/attribute_methods.rb
@@ -48,11 +48,12 @@ def define_attribute_methods # :nodoc:
# Use a mutex; we don't want two thread simultaneously trying to define
# attribute methods.
generated_attribute_methods.synchronize do
- return if attribute_methods_generated?
+ return false if attribute_methods_generated?
superclass.define_attribute_methods unless self == base_class
super(column_names)
@attribute_methods_generated = true
end
+ true
end
def attribute_methods_generated? # :nodoc:
@@ -143,9 +144,7 @@ def attribute_names
# If we haven't generated any methods yet, generate them, then
# see if we've created the method we're looking for.
def method_missing(method, *args, &block) # :nodoc:
- unless self.class.attribute_methods_generated?
- self.class.define_attribute_methods
-
+ if self.class.define_attribute_methods
if respond_to_without_attributes?(method)
send(method, *args, &block)
else
@@ -188,7 +187,7 @@ def attribute_missing(match, *args, &block) # :nodoc:
# person.respond_to(:nothing) # => false
def respond_to?(name, include_private = false)
name = name.to_s
- self.class.define_attribute_methods unless self.class.attribute_methods_generated?
+ self.class.define_attribute_methods
result = super
# If the result is false the answer is false.

0 comments on commit 30efdd6

Please sign in to comment.