Skip to content

Commit a950183

Browse files
committed
Fix resolving mixins that mix themselves in
1 parent e167846 commit a950183

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

lib/yard/handlers/ruby/mixin_handler.rb

+9-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,15 @@ def process_mixin(mixin)
2626
raise YARD::Parser::UndocumentableError unless mixin.ref?
2727
raise YARD::Parser::UndocumentableError if mixin.first.type == :ident
2828

29-
case obj = Proxy.new(namespace, mixin.source)
30-
when ConstantObject # If a constant is included, use its value as the real object
31-
obj = Proxy.new(namespace, obj.value, :module)
29+
if mixin.type == :var_ref && mixin[0] == s(:kw, "self")
30+
obj = namespace
3231
else
33-
obj = Proxy.new(namespace, mixin.source, :module)
32+
case obj = Proxy.new(namespace, mixin.source)
33+
when ConstantObject # If a constant is included, use its value as the real object
34+
obj = Proxy.new(namespace, obj.value, :module)
35+
else
36+
obj = Proxy.new(namespace, mixin.source, :module)
37+
end
3438
end
3539

3640
rec = recipient(mixin)
@@ -41,7 +45,7 @@ def process_mixin(mixin)
4145
end
4246

4347
def recipient(mixin)
44-
if statement[0].type == :const_path_ref
48+
if statement[0].type == :const_path_ref || statement[0].type == :top_const_ref
4549
Proxy.new(namespace, statement[0].source)
4650
elsif statement[0].type == :var_ref && statement[0][0] != s(:kw, "self")
4751
statement[0][0].type == :const ?

spec/handlers/examples/mixin_handler_001.rb.txt

+13
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,16 @@ end
3838

3939
module FromConstant; end
4040
FromConstant.include A
41+
42+
module Foo
43+
end
44+
45+
module MixMySelfIn
46+
Foo.include(self)
47+
end
48+
49+
module Nested
50+
module Foo
51+
::Foo.include(self)
52+
end
53+
end

spec/handlers/mixin_handler_spec.rb

+4
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,8 @@ class D1; class E1; class F1; end end end
6969
expect(YARD::Registry.root.instance_mixins).not_to eq [P('D1::E1::F1')]
7070
expect(P('A1::B1::C1').instance_mixins).to eq [P('D1::E1::F1')]
7171
end
72+
73+
it "resolves modules that mix themselves in" do
74+
expect(Registry.at('Foo').mixins).to match_array [P('MixMySelfIn'), P('Nested::Foo')]
75+
end
7276
end

0 commit comments

Comments
 (0)