Skip to content

Commit

Permalink
Merge pull request #35595 from shioyama/generated_attribute_methods_n…
Browse files Browse the repository at this point in the history
…amespaced_constant

Give GeneratedAttributeMethods module a name
  • Loading branch information
rafaelfranca committed Mar 20, 2019
2 parents b504a5d + 8ca3c28 commit 3dee96e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions activerecord/lib/active_record/attribute_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module AttributeMethods

RESTRICTED_CLASS_METHODS = %w(private public protected allocate new name parent superclass)

class GeneratedAttributeMethods < Module #:nodoc:
class GeneratedAttributeMethodsBuilder < Module #:nodoc:
include Mutex_m
end

Expand All @@ -35,7 +35,8 @@ def inherited(child_class) #:nodoc:
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

Expand Down Expand Up @@ -88,7 +89,7 @@ def instance_method_already_implemented?(method_name)
# 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
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/cases/attribute_methods_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ def some_method_that_is_not_on_super

test "generated attribute methods ancestors have correct class" do
mod = Topic.send(:generated_attribute_methods)
assert_match %r(GeneratedAttributeMethods), mod.inspect
assert_match %r(Topic::GeneratedAttributeMethods), mod.inspect
end

private
Expand Down

0 comments on commit 3dee96e

Please sign in to comment.