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