Update stdlib and concat to 6.1.0 both
[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
6     @summary
7       Validate that all passed values are hash data structures. Abort catalog
8       compilation if any value fails this check.
9
10     @return
11       validate hash
12
13     @example **Usage**
14
15       The following values will pass:
16
17           $my_hash = { 'one' => 'two' }
18           validate_hash($my_hash)
19
20       The following values will fail, causing compilation to abort:
21
22           validate_hash(true)
23           validate_hash('some_string')
24           $undefined = undef
25           validate_hash($undefined)
26     DOC
27              ) do |args|
28
29     function_deprecation([:validate_hash, 'This method is deprecated, please use the stdlib validate_legacy function,
30                           with Stdlib::Compat::Hash. There is further documentation for validate_legacy function in the README.'])
31
32     if args.empty?
33       raise Puppet::ParseError, "validate_hash(): wrong number of arguments (#{args.length}; must be > 0)"
34     end
35
36     args.each do |arg|
37       unless arg.is_a?(Hash)
38         raise Puppet::ParseError, "#{arg.inspect} is not a Hash.  It looks to be a #{arg.class}"
39       end
40     end
41   end
42 end