From 5257ca4bed42c0ffdc5ab550a20aeb793c8d8ea9 Mon Sep 17 00:00:00 2001 From: Hailee Kenney Date: Thu, 12 Feb 2015 13:27:35 -0800 Subject: [PATCH] (PDOC-27) Don't require options for 3x functions Prior to this commit, the 3x function handler assumed that at least two arguments (the name and one or more additional arguments) were passed into newfunction when creating a 3x function. However that is not actually required, the only argument needed is the name. Update the 3x function handler so that it will not throw and exception if only one argument is given. --- .../yard/handlers/puppet_3x_function_handler.rb | 13 +++++++++---- .../strings/yard/puppet_3x_function_handler_spec.rb | 9 +++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_3x_function_handler.rb b/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_3x_function_handler.rb index 116c71b..1e1cea2 100644 --- a/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_3x_function_handler.rb +++ b/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_3x_function_handler.rb @@ -66,10 +66,15 @@ class PuppetX::PuppetLabs::Strings::YARD::Handlers::Puppet3xFunctionHandler < YA name = process_element(name) - opts = opts.map do |tuple| - # Jump down into the S-Expression that represents a hashrocket, `=>`, - # and the values on either side of it. - tuple.jump(:assoc).map{|e| process_element(e)} + # Don't try to process options if we don't have any + if !opts.nil? + opts = opts.map do |tuple| + # Jump down into the S-Expression that represents a hashrocket, `=>`, + # and the values on either side of it. + tuple.jump(:assoc).map{|e| process_element(e)} + end + else + opts = [[]] end [name, Hash[opts]] diff --git a/spec/unit/puppet_x/puppetlabs/strings/yard/puppet_3x_function_handler_spec.rb b/spec/unit/puppet_x/puppetlabs/strings/yard/puppet_3x_function_handler_spec.rb index 3fa453c..0b58605 100644 --- a/spec/unit/puppet_x/puppetlabs/strings/yard/puppet_3x_function_handler_spec.rb +++ b/spec/unit/puppet_x/puppetlabs/strings/yard/puppet_3x_function_handler_spec.rb @@ -51,4 +51,13 @@ describe PuppetX::PuppetLabs::Strings::YARD::Handlers::Puppet3xFunctionHandler d expect(the_method).to document_a(:type => :method, :docstring => "") expect(the_namespace).to document_a(:type => :puppetnamespace) end + + it "should process documentation if only one option is passed to newfunction" do + parse <<-RUBY + newfunction(:the_functiion) do |args| + end + RUBY + + expect(the_namespace).to document_a(:type => :puppetnamespace) + end end