Skip to content
Open
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
13 changes: 12 additions & 1 deletion gapic-generator/lib/gapic/presenters/enum_value_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,18 @@ def initialize value

# @return [String] The enum value name without keyword collision.
def name
Gapic::RubyInfo.keywords.include?(@value.name) ? "#{@value.parent.name}::#{@value.name}" : @value.name
keyword_collision? ? "#{@value.parent.name}::#{@value.name}" : @value.name
end

# @return [Boolean] Whether the enum name collides with a Ruby keyword.
def keyword_collision?
Gapic::RubyInfo.keywords.include? @value.name
end

# @return [String] The doc stub string for the enum value. Prevents YARD warnings in cases of keyword
# collision.
def doc_line
keyword_collision? ? "const_set :#{@value.name}, #{@value.number}" : "#{@value.name} = #{@value.number}"
end

def doc_description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ module <%= enum.name %>
<%- if value.doc_description -%>
<%= indent value.doc_description, " # " %>
<%- end -%>
<%= value.name %> = <%= value.number %>
<%= value.doc_line %>
<%- end -%>
end
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,13 @@ def test_enum_value_name_no_keyword_collision
def test_enum_value_name_with_keyword_collision
evp = typical_garbage_enum_value 4
assert_equal "GarbageEnum::END", evp.name
assert evp.keyword_collision?
assert_equal "const_set :END, 4", evp.doc_line
end

def test_enum_value_doc_line_no_keyword_collision
evp = typical_garbage_enum_value 3
refute evp.keyword_collision?
assert_equal "DUMPSTER = 3", evp.doc_line
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ module GarbageEnum
DUMPSTER = 3

# The end of garbage.
GarbageEnum::END = 4
const_set :END, 4
end
end
end
Expand Down
Loading