aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2014-08-17 12:53:15 -0700
committerDavid Heinemeier Hansson <david@loudthinking.com>2014-08-17 12:53:15 -0700
commit8f15565de879bd40c8390884d1d31e52de240323 (patch)
treec6c30c4a07a5d11f46d50853613b909ee0e8c6ae /activerecord/lib/active_record/attribute_methods.rb
parent9f6e82ee4783e491c20f5244a613fdeb4024beb5 (diff)
parente158ee50e64e2ae2460cd26be53039922f588300 (diff)
downloadrails-8f15565de879bd40c8390884d1d31e52de240323.tar.gz
rails-8f15565de879bd40c8390884d1d31e52de240323.tar.bz2
rails-8f15565de879bd40c8390884d1d31e52de240323.zip
Merge branch 'master' of github.com:rails/rails
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods.rb')
-rw-r--r--activerecord/lib/active_record/attribute_methods.rb13
1 files changed, 8 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb
index 09e2faee86..1ff28ceccc 100644
--- a/activerecord/lib/active_record/attribute_methods.rb
+++ b/activerecord/lib/active_record/attribute_methods.rb
@@ -57,6 +57,8 @@ module ActiveRecord
end
end
+ class GeneratedAttributeMethods < Module; end # :nodoc:
+
module ClassMethods
def inherited(child_class) #:nodoc:
child_class.initialize_generated_modules
@@ -64,7 +66,7 @@ module ActiveRecord
end
def initialize_generated_modules # :nodoc:
- @generated_attribute_methods = Module.new { extend Mutex_m }
+ @generated_attribute_methods = GeneratedAttributeMethods.new { extend Mutex_m }
@attribute_methods_generated = false
include @generated_attribute_methods
end
@@ -113,10 +115,11 @@ module ActiveRecord
if superclass == Base
super
else
- # If B < A and A defines its own attribute method, then we don't want to overwrite that.
- defined = method_defined_within?(method_name, superclass, superclass.generated_attribute_methods)
- base_defined = Base.method_defined?(method_name) || Base.private_method_defined?(method_name)
- defined && !base_defined || super
+ # If ThisClass < ... < SomeSuperClass < ... < Base and SomeSuperClass
+ # defines its own attribute method, then we don't want to overwrite that.
+ defined = method_defined_within?(method_name, superclass, Base) &&
+ ! superclass.instance_method(method_name).owner.is_a?(GeneratedAttributeMethods)
+ defined || super
end
end