Skip to content

Commit

Permalink
Merge pull request #1099 from kagucho/master
Browse files Browse the repository at this point in the history
Document block for Struct.new if present
  • Loading branch information
lsegal authored Jun 24, 2017
2 parents a85a262 + 343b314 commit 1505386
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/yard/handlers/ruby/constant_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def process_structclass(statement)
if lhs.type == :const
klass = create_class(lhs[0], P(:Struct))
create_attributes(klass, extract_parameters(statement[1]))
parse_block(statement[1].block[1], :namespace => klass) unless statement[1].block.nil?
else
raise YARD::Parser::UndocumentableError, "Struct assignment to #{statement[0].source}"
end
Expand Down
8 changes: 8 additions & 0 deletions spec/handlers/constant_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
end
end

it 'documents block for Struct.new if present' do
obj = Registry.at("MyStructWithConstant")
expect(obj).to be_kind_of(CodeObjects::ClassObject)
expect(obj.constants[0].docstring).to eq 'A constant.'
expect(obj.constants[0].name).to eq :CONSTANT
expect(obj.constants[0].value).to eq "42"
end

it "turns Const = Struct.new('Name', :sym) into class Const with attr :sym" do
obj = Registry.at("NotMyClass")
expect(obj).to be_kind_of(CodeObjects::ClassObject)
Expand Down
5 changes: 5 additions & 0 deletions spec/handlers/examples/constant_handler_001.rb.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ MyClass = Struct.new(:a, :b, :c)
NotMyClass = Struct.new("NotMyClass2", :b, :c)
MyEmptyStruct = Struct.new

MyStructWithConstant = Struct.new do
# A constant.
CONSTANT = 42
end

# A crazy struct.
#
# @attr [String] bar An attr
Expand Down

4 comments on commit 1505386

@tarfand77
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tarfand77
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tarfand77
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tarfand77
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.