Skip to content

Commit 53507c6

Browse files
committed
Make the TypeExtrasHandler more robust
Ruby 2.7's AST has added an entry for `:period` between the function call and the const reference. This change makes it so the method1_name parsing can deal with that. Ruby 2.5: ``` [1] pry(#<PuppetStrings::Yard::Handlers::Ruby::TypeExtrasHandler>)> statement[0].children => [s(:const_path_ref, s(:var_ref, s(:const, "Puppet", line: 1..1, source: 2..7), line: 1..1, source: 2..7), s(:const, "Type", line: 1..1, source: 10..13), line: 1..1, source: 2..13), s(:ident, "type", line: 1..1, source: 15..18), s(:arg_paren, s(s(:symbol_literal, s(:symbol, s(:ident, "file", line: 1..1, source: 21..24), line: 1..1, source: 20..24), line: 1..1, source: 20..24), false), line: 1..1, source: 19..25)] [2] pry(#<PuppetStrings::Yard::Handlers::Ruby::TypeExtrasHandler>)> ``` Ruby 2.7: ``` [4] pry(#<PuppetStrings::Yard::Handlers::Ruby::TypeExtrasHandler>)> statement[0].children => [s(:const_path_ref, s(:var_ref, s(:const, "Puppet", line: 1..1, source: 2..7), line: 1..1, source: 2..7), s(:const, "Type", line: 1..1, source: 10..13), line: 1..1, source: 2..13), s(:period, ".", line: 1..1, source: 14..14), s(:ident, "type", line: 1..1, source: 15..18), s(:arg_paren, s(s(:symbol_literal, s(:symbol, s(:ident, "file", line: 1..1, source: 21..24), line: 1..1, source: 20..24), line: 1..1, source: 20..24), false), line: 1..1, source: 19..25)] [5] pry(#<PuppetStrings::Yard::Handlers::Ruby::TypeExtrasHandler>)> ```
1 parent 8cd8c07 commit 53507c6

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class PuppetStrings::Yard::Handlers::Ruby::TypeExtrasHandler < PuppetStrings::Ya
3232

3333
return unless (statement.count > 1) && (statement[0].children.count > 2)
3434
module_name = statement[0].children[0].source
35-
method1_name = statement[0].children[1].source
35+
method1_name = statement[0].children.drop(1).find{ |c| c.type == :ident }.source
3636
return unless (module_name == 'Puppet::Type' || module_name == 'Type') && method1_name == 'type'
3737

3838
typename = get_name(statement[0], 'Puppet::Type.type')

0 commit comments

Comments
 (0)