diff options
-rw-r--r-- | activemodel/lib/active_model/attribute_methods.rb | 5 | ||||
-rw-r--r-- | activerecord/lib/active_record/attribute_methods.rb | 13 | ||||
-rw-r--r-- | activerecord/lib/active_record/core.rb | 8 |
3 files changed, 17 insertions, 9 deletions
diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb index 1ba5b0e3d4..f336c759d2 100644 --- a/activemodel/lib/active_model/attribute_methods.rb +++ b/activemodel/lib/active_model/attribute_methods.rb @@ -1,4 +1,5 @@ require 'thread_safe' +require 'mutex_m' module ActiveModel # Raised when an attribute is not defined. @@ -333,7 +334,9 @@ module ActiveModel end def generated_attribute_methods #:nodoc: - @generated_attribute_methods ||= Module.new.tap { |mod| include mod } + @generated_attribute_methods ||= Module.new { + extend Mutex_m + }.tap { |mod| include mod } end protected diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb index 609c6e8cab..7c422ecbe0 100644 --- a/activerecord/lib/active_record/attribute_methods.rb +++ b/activerecord/lib/active_record/attribute_methods.rb @@ -1,4 +1,5 @@ require 'active_support/core_ext/enumerable' +require 'mutex_m' module ActiveRecord # = Active Record Attribute Methods @@ -18,12 +19,22 @@ module ActiveRecord end module ClassMethods + def inherited(child_class) #:nodoc: + child_class.initialize_generated_modules + super + end + + def initialize_generated_modules # :nodoc: + @generated_attribute_methods = Module.new { extend Mutex_m } + include @generated_attribute_methods + end + # Generates all the attribute related methods for columns in the database # accessors, mutators and query methods. def define_attribute_methods # :nodoc: # Use a mutex; we don't want two thread simultaneously trying to define # attribute methods. - @attribute_methods_mutex.synchronize do + generated_attribute_methods.synchronize do return if attribute_methods_generated? superclass.define_attribute_methods unless self == base_class super(column_names) diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index f306243552..7da70cea18 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -88,14 +88,8 @@ module ActiveRecord end module ClassMethods - def inherited(child_class) #:nodoc: - child_class.initialize_generated_modules - super - end - def initialize_generated_modules - @attribute_methods_mutex = Mutex.new - + super # force attribute methods to be higher in inheritance hierarchy than other generated methods generated_attribute_methods.const_set(:AttrNames, Module.new { def self.const_missing(name) |