From 1da5dc55ee48fcd437f5b5df00a5b2f3991ec9f1 Mon Sep 17 00:00:00 2001 From: Micah Date: Tue, 24 May 2016 10:19:33 -0400 Subject: Squashed 'puppet/modules/stdlib/' content from commit 7112363 git-subtree-dir: puppet/modules/stdlib git-subtree-split: 71123634744b9fe2ec7d6a3e38e9789fd84801e3 --- lib/puppet/parser/functions/validate_array.rb | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 lib/puppet/parser/functions/validate_array.rb (limited to 'lib/puppet/parser/functions/validate_array.rb') diff --git a/lib/puppet/parser/functions/validate_array.rb b/lib/puppet/parser/functions/validate_array.rb new file mode 100644 index 00000000..34b51182 --- /dev/null +++ b/lib/puppet/parser/functions/validate_array.rb @@ -0,0 +1,33 @@ +module Puppet::Parser::Functions + + newfunction(:validate_array, :doc => <<-'ENDHEREDOC') do |args| + Validate that all passed values are array data structures. Abort catalog + compilation if any value fails this check. + + The following values will pass: + + $my_array = [ 'one', 'two' ] + validate_array($my_array) + + The following values will fail, causing compilation to abort: + + validate_array(true) + validate_array('some_string') + $undefined = undef + validate_array($undefined) + + ENDHEREDOC + + unless args.length > 0 then + raise Puppet::ParseError, ("validate_array(): wrong number of arguments (#{args.length}; must be > 0)") + end + + args.each do |arg| + unless arg.is_a?(Array) + raise Puppet::ParseError, ("#{arg.inspect} is not an Array. It looks to be a #{arg.class}") + end + end + + end + +end -- cgit v1.2.3