Skip to content

Commit

Permalink
Merge pull request #1467 from ccutrer/self-mixins
Browse files Browse the repository at this point in the history
Fix resolving mixins that mix themselves in
  • Loading branch information
lsegal committed Apr 8, 2023
2 parents 2d6d89f + 37f0cad commit d4472d8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/yard/handlers/ruby/mixin_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@ def process_mixin(mixin)
raise YARD::Parser::UndocumentableError unless mixin.ref?
raise YARD::Parser::UndocumentableError if mixin.first.type == :ident

case obj = Proxy.new(namespace, mixin.source)
when ConstantObject # If a constant is included, use its value as the real object
obj = Proxy.new(namespace, obj.value, :module)
if mixin.type == :var_ref && mixin[0] == s(:kw, "self")
obj = namespace
else
obj = Proxy.new(namespace, mixin.source, :module)
case obj = Proxy.new(namespace, mixin.source)
when ConstantObject # If a constant is included, use its value as the real object
obj = Proxy.new(namespace, obj.value, :module)
else
obj = Proxy.new(namespace, mixin.source, :module)
end
end

rec = recipient(mixin)
Expand All @@ -44,7 +48,7 @@ def process_mixin(mixin)
end

def recipient(mixin)
if statement[0].type == :const_path_ref
if statement[0].type == :const_path_ref || statement[0].type == :top_const_ref
Proxy.new(namespace, statement[0].source)
elsif statement[0].type == :var_ref && statement[0][0] != s(:kw, "self")
statement[0][0].type == :const ?
Expand Down
13 changes: 13 additions & 0 deletions spec/handlers/examples/mixin_handler_001.rb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,16 @@ end

module FromConstant; end
FromConstant.include A

module Foo
end

module MixMySelfIn
Foo.include(self)
end

module Nested
module Foo
::Foo.include(self)
end
end
4 changes: 4 additions & 0 deletions spec/handlers/mixin_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ class D1; class E1; module F1; end end end
expect(P('A1::B1::C1').instance_mixins).to eq [P('D1::E1::F1')]
end

it "resolves modules that mix themselves in" do
expect(Registry.at('Foo').mixins).to match_array [P('MixMySelfIn'), P('Nested::Foo')]
end

it "ensures the recipient is loaded from another file" do
# 002 includes a module into a module defined in 003
parse_file [:mixin_handler_002, :mixin_handler_003], __FILE__
Expand Down

0 comments on commit d4472d8

Please sign in to comment.