From 9a1a0b4af633b9e3d726d4d8900fe2e87ba7675d Mon Sep 17 00:00:00 2001 From: Eric Putnam Date: Fri, 20 Apr 2018 15:04:52 +0100 Subject: [PATCH] (PDOC-240) add handling for :array node type in rsapi_handler The 'features' key in the resource api expects an array of feature names. Currently, if you run strings on a resource api type that specifies features, it falls over because it doesn't know what to do with an AST node of type :array. Further, the method that throws the error is looking for an undefined variable called 'parameters'. This removes the odd conditional that calls 'parameters' and adds a method that returns an array of the array contents that may be passed to features. Features are not currently sent to the renderer, but now Strings will be able to handle any array it comes across in an rsapi type. --- .../yard/handlers/ruby/rsapi_handler.rb | 12 +++++++++++- .../yard/handlers/ruby/rsapi_handler_spec.rb | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb b/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb index 19b6e60..294235c 100644 --- a/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb +++ b/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb @@ -44,7 +44,7 @@ class PuppetStrings::Yard::Handlers::Ruby::RsapiHandler < PuppetStrings::Yard::H private def raise_parse_error(msg, location = statement) - raise YARD::Parser::UndocumentableError, "#{msg} at #{location.file}:#{location.line}." if parameters.empty? + raise YARD::Parser::UndocumentableError, "#{msg} at #{location.file}:#{location.line}." end # check that the params of the register_type call are key/value pairs. @@ -67,6 +67,8 @@ class PuppetStrings::Yard::Handlers::Ruby::RsapiHandler < PuppetStrings::Yard::H node.source.to_i when :hash hash_from_node(node) + when :array + array_from_node(node) when :var_ref var_ref_from_node(node) when :symbol, :symbol_literal, :label, :dyna_symbol, :string_literal @@ -76,6 +78,14 @@ class PuppetStrings::Yard::Handlers::Ruby::RsapiHandler < PuppetStrings::Yard::H end end + def array_from_node(node) + return nil unless node + + arr = node.children.collect do |assoc| + value_from_node(assoc.children[0]) + end + end + def hash_from_node(node) return nil unless node diff --git a/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb b/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb index 983558b..568c628 100644 --- a/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb +++ b/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb @@ -70,6 +70,7 @@ SOURCE Puppet::ResourceApi.register_type( name: 'database', docs: 'An example database server resource type.', + features: ['remote-resource'], attributes: { ensure: { type: 'Enum[present, absent, up, down]',