aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-07-02 15:06:04 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-07-02 15:06:04 -0700
commitb670d799e4f7c1ddc235fbeec1ca1806a8b5d6ff (patch)
treeab2386246f16c957c2217c32261a8bd689fcad9a /activerecord
parent4236d8f05631ab75b74850546d0253d41d4d48df (diff)
downloadrails-b670d799e4f7c1ddc235fbeec1ca1806a8b5d6ff.tar.gz
rails-b670d799e4f7c1ddc235fbeec1ca1806a8b5d6ff.tar.bz2
rails-b670d799e4f7c1ddc235fbeec1ca1806a8b5d6ff.zip
define attribute methods in a thread safe manner
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/attribute_methods.rb9
1 files changed, 4 insertions, 5 deletions
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.