summaryrefslogtreecommitdiff
path: root/lib/puppet/parser/functions/validate_hash.rb
diff options
context:
space:
mode:
authorMicah <micah@leap.se>2016-05-24 10:19:33 -0400
committerMicah <micah@leap.se>2016-05-24 10:19:33 -0400
commit1da5dc55ee48fcd437f5b5df00a5b2f3991ec9f1 (patch)
tree1794e812d83facd93b3007c42632c63ddf1eb2fc /lib/puppet/parser/functions/validate_hash.rb
Squashed 'puppet/modules/stdlib/' content from commit 7112363
git-subtree-dir: puppet/modules/stdlib git-subtree-split: 71123634744b9fe2ec7d6a3e38e9789fd84801e3
Diffstat (limited to 'lib/puppet/parser/functions/validate_hash.rb')
-rw-r--r--lib/puppet/parser/functions/validate_hash.rb33
1 files changed, 33 insertions, 0 deletions
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