Skip to content

Commit

Permalink
Merge pull request #1468 from ccutrer/ensure-mixins-loaded
Browse files Browse the repository at this point in the history
use ensure_loaded! with mixin objects
  • Loading branch information
lsegal authored Apr 8, 2023
2 parents 3081468 + 705962c commit 2d6d89f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
5 changes: 4 additions & 1 deletion lib/yard/handlers/ruby/mixin_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ def process_mixin(mixin)
end

rec = recipient(mixin)
return if rec.nil? || rec.mixins(scope).include?(obj)
return if rec.nil?

ensure_loaded!(rec)
return if rec.mixins(scope).include?(obj)

shift = statement.method_name(true) == :include ? :unshift : :push
rec.mixins(scope).send(shift, obj)
Expand Down
3 changes: 3 additions & 0 deletions spec/handlers/examples/mixin_handler_002.rb.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module B1; end

A1.include(B1)
1 change: 1 addition & 0 deletions spec/handlers/examples/mixin_handler_003.rb.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module A1; end
9 changes: 8 additions & 1 deletion spec/handlers/mixin_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,18 @@
it "can mixin a const by complex path" do
YARD.parse_string <<-eof
class A1; class B1; class C1; end end end
class D1; class E1; class F1; end end end
class D1; class E1; module F1; end end end
A1::B1::C1.include D1::E1::F1
eof

expect(YARD::Registry.root.instance_mixins).not_to eq [P('D1::E1::F1')]
expect(P('A1::B1::C1').instance_mixins).to eq [P('D1::E1::F1')]
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__

expect(P('A1').instance_mixins).to eq [P('B1')]
end
end
6 changes: 3 additions & 3 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ def self.parser_type; @parser_type == :ruby ? :ruby18 : @parser_type end

NAMED_OPTIONAL_ARGUMENTS = RUBY_VERSION >= '2.1.0'

def parse_file(file, thisfile = __FILE__, log_level = log.level, ext = '.rb.txt')
def parse_file(files, thisfile = __FILE__, log_level = log.level, ext = '.rb.txt')
Registry.clear
path = File.join(File.dirname(thisfile), 'examples', file.to_s + ext)
YARD::Parser::SourceParser.parse(path, [], log_level)
paths = Array(files).map { |file| File.join(File.dirname(thisfile), 'examples', file.to_s + ext) }
YARD::Parser::SourceParser.parse(paths, [], log_level)
end

def described_in_docs(klass, meth, file = nil)
Expand Down

0 comments on commit 2d6d89f

Please sign in to comment.