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