Skip to content

Commit d4472d8

Browse files
authored
Merge pull request #1467 from ccutrer/self-mixins
Fix resolving mixins that mix themselves in
2 parents 2d6d89f + 37f0cad commit d4472d8

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)
@@ -44,7 +48,7 @@ def process_mixin(mixin)
4448
end
4549

4650
def recipient(mixin)
47-
if statement[0].type == :const_path_ref
51+
if statement[0].type == :const_path_ref || statement[0].type == :top_const_ref
4852
Proxy.new(namespace, statement[0].source)
4953
elsif statement[0].type == :var_ref && statement[0][0] != s(:kw, "self")
5054
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
@@ -70,6 +70,10 @@ class D1; class E1; module F1; end end end
7070
expect(P('A1::B1::C1').instance_mixins).to eq [P('D1::E1::F1')]
7171
end
7272

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
76+
7377
it "ensures the recipient is loaded from another file" do
7478
# 002 includes a module into a module defined in 003
7579
parse_file [:mixin_handler_002, :mixin_handler_003], __FILE__

0 commit comments

Comments
 (0)