From 84f31a807462121909f1a1017218e5b915f3ca23 Mon Sep 17 00:00:00 2001 From: Charlie Sharpsteen Date: Mon, 2 Jun 2014 19:04:19 -0700 Subject: [PATCH] Handle cases where the parser returns nil The Future Parser will return nil if a manifest file contains no statements (I.E. it is empty or full of comments). Handle these cases and ensure the `enumerate` method of the YARD parser always returns an Array. --- lib/puppetx/yardoc/pops/yard_transformer.rb | 5 +++++ lib/puppetx/yardoc/yard/parser.rb | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/puppetx/yardoc/pops/yard_transformer.rb b/lib/puppetx/yardoc/pops/yard_transformer.rb index a5f596e..6560b07 100644 --- a/lib/puppetx/yardoc/pops/yard_transformer.rb +++ b/lib/puppetx/yardoc/pops/yard_transformer.rb @@ -45,5 +45,10 @@ module Puppetx::Yardoc::Pops def transform_Positioned(o) YARDStatement.new(o) end + + # nil in... nil out! + def transform_NilClass(o) + nil + end end end diff --git a/lib/puppetx/yardoc/yard/parser.rb b/lib/puppetx/yardoc/yard/parser.rb index aa64fb0..2d815b3 100644 --- a/lib/puppetx/yardoc/yard/parser.rb +++ b/lib/puppetx/yardoc/yard/parser.rb @@ -22,7 +22,10 @@ module Puppetx::Yardoc::YARD end def enumerator - @transformer.transform(@parse_result) + statements = @transformer.transform(@parse_result) + + # Ensure an array is returned and prune any nil values. + Array(statements).compact end end