0460cf35b8d81d194539ba8cb48b820d15987027
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / validate_hash.rb
1 #
2 # validate_hash.rb
3 #
4 module Puppet::Parser::Functions
5   newfunction(:validate_hash, :doc => <<-'DOC') do |args|
6     Validate that all passed values are hash data structures. Abort catalog
7     compilation if any value fails this check.
8
9     The following values will pass:
10
11         $my_hash = { 'one' => 'two' }
12         validate_hash($my_hash)
13
14     The following values will fail, causing compilation to abort:
15
16         validate_hash(true)
17         validate_hash('some_string')
18         $undefined = undef
19         validate_hash($undefined)
20
21     DOC
22
23     function_deprecation([:validate_hash, 'This method is deprecated, please use the stdlib validate_legacy function,
24                           with Stdlib::Compat::Hash. There is further documentation for validate_legacy function in the README.'])
25
26     if args.empty?
27       raise Puppet::ParseError, "validate_hash(): wrong number of arguments (#{args.length}; must be > 0)"
28     end
29
30     args.each do |arg|
31       unless arg.is_a?(Hash)
32         raise Puppet::ParseError, "#{arg.inspect} is not a Hash.  It looks to be a #{arg.class}"
33       end
34     end
35   end
36 end