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_hash.rb | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 lib/puppet/parser/functions/validate_hash.rb (limited to 'lib/puppet/parser/functions/validate_hash.rb') diff --git a/lib/puppet/parser/functions/validate_hash.rb b/lib/puppet/parser/functions/validate_hash.rb new file mode 100644 index 00000000..9bdd5432 --- /dev/null +++ b/lib/puppet/parser/functions/validate_hash.rb @@ -0,0 +1,33 @@ +module Puppet::Parser::Functions + + newfunction(:validate_hash, :doc => <<-'ENDHEREDOC') do |args| + Validate that all passed values are hash data structures. Abort catalog + compilation if any value fails this check. + + The following values will pass: + + $my_hash = { 'one' => 'two' } + validate_hash($my_hash) + + The following values will fail, causing compilation to abort: + + validate_hash(true) + validate_hash('some_string') + $undefined = undef + validate_hash($undefined) + + ENDHEREDOC + + unless args.length > 0 then + raise Puppet::ParseError, ("validate_hash(): wrong number of arguments (#{args.length}; must be > 0)") + end + + args.each do |arg| + unless arg.is_a?(Hash) + raise Puppet::ParseError, ("#{arg.inspect} is not a Hash. It looks to be a #{arg.class}") + end + end + + end + +end -- cgit v1.2.3