From b670d799e4f7c1ddc235fbeec1ca1806a8b5d6ff Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 2 Jul 2013 15:06:04 -0700 Subject: define attribute methods in a thread safe manner --- activerecord/lib/active_record/attribute_methods.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'activerecord') diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index 00237d7caf..be6d50e542 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -37,11 +37,12 @@ module ActiveRecord # 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: @@ -132,9 +133,7 @@ module ActiveRecord # 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 @@ -177,7 +176,7 @@ module ActiveRecord # 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. -- cgit v1.2.3