Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document block for Struct.new if present #1099

Merged
merged 1 commit into from
Jun 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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