aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods.rb
diff options
context:
space:
mode:
authorChris Salzberg <chris@dejimata.com>2019-03-13 10:17:00 +0900
committerChris Salzberg <chris@dejimata.com>2019-03-13 10:34:15 +0900
commit8ca3c286a768038f6b391fd3bfbdfcc299876a1f (patch)
treeae93f15965fad583bcd749d13a5e70ffd79876d9 /activerecord/lib/active_record/attribute_methods.rb
parent963ec3bae5ac12ab3e0614bdd0d0ca9fba06ac46 (diff)
downloadrails-8ca3c286a768038f6b391fd3bfbdfcc299876a1f.tar.gz
rails-8ca3c286a768038f6b391fd3bfbdfcc299876a1f.tar.bz2
rails-8ca3c286a768038f6b391fd3bfbdfcc299876a1f.zip
Give GeneratedAttributeMethods module a name
Currently GeneratedAttributeMethods is a module builder class, an instance of which is included in every AR class. OTOH, GeneratedAssociatedMethods is assigned to a constant under the model namespace. This is inconsistent and looks strange in the list of ancestors. There is no particular reason *not* to assign a constant for this (very important) module under the model namespace, so that's what this commit does. Previous to this change, ancestors for an AR class looked like this: ``` => [User (call 'User.connection' to establish a connection), User::GeneratedAssociationMethods, #<ActiveRecord::AttributeMethods::GeneratedAttributeMethods:0x000055ace0f05b08>, ApplicationRecord(abstract), ApplicationRecord::GeneratedAssociationMethods, #<ActiveRecord::AttributeMethods::GeneratedAttributeMethods:0x000055ace093c460>, ActiveRecord::Base, ... ``` With this change, they look like this: ``` => [User (call 'User.connection' to establish a connection), User::GeneratedAssociationMethods, User::GeneratedAttributeMethods, ApplicationRecord(abstract), ApplicationRecord::GeneratedAssociationMethods, ApplicationRecord::GeneratedAttributeMethods, ActiveRecord::Base, ... ``` The previously named `GeneratedAttributeMethods` module builder class is renamed `GeneratedAttributeMethodsBuilder` to emphasize that this is not a module but a class.
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods.rb')
-rw-r--r--activerecord/lib/active_record/attribute_methods.rb7
1 files changed, 4 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb
index fd8c1da842..af7e46e649 100644
--- a/activerecord/lib/active_record/attribute_methods.rb
+++ b/activerecord/lib/active_record/attribute_methods.rb
@@ -24,7 +24,7 @@ module ActiveRecord
RESTRICTED_CLASS_METHODS = %w(private public protected allocate new name parent superclass)
- class GeneratedAttributeMethods < Module #:nodoc:
+ class GeneratedAttributeMethodsBuilder < Module #:nodoc:
include Mutex_m
end
@@ -35,7 +35,8 @@ module ActiveRecord
end
def initialize_generated_modules # :nodoc:
- @generated_attribute_methods = GeneratedAttributeMethods.new
+ @generated_attribute_methods = const_set(:GeneratedAttributeMethods, GeneratedAttributeMethodsBuilder.new)
+ private_constant :GeneratedAttributeMethods
@attribute_methods_generated = false
include @generated_attribute_methods
@@ -88,7 +89,7 @@ module ActiveRecord
# 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)
+ ! superclass.instance_method(method_name).owner.is_a?(GeneratedAttributeMethodsBuilder)
defined || super
end
end