]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/lib/puppet/parser/functions/validate_bool.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / validate_bool.rb
1 module Puppet::Parser::Functions
2
3   newfunction(:validate_bool, :doc => <<-'ENDHEREDOC') do |args|
4     Validate that all passed values are either true or false. Abort catalog
5     compilation if any value fails this check.
6
7     The following values will pass:
8
9         $iamtrue = true
10         validate_bool(true)
11         validate_bool(true, true, false, $iamtrue)
12
13     The following values will fail, causing compilation to abort:
14
15         $some_array = [ true ]
16         validate_bool("false")
17         validate_bool("true")
18         validate_bool($some_array)
19
20     ENDHEREDOC
21
22     unless args.length > 0 then
23       raise Puppet::ParseError, ("validate_bool(): wrong number of arguments (#{args.length}; must be > 0)")
24     end
25
26     args.each do |arg|
27       unless function_is_bool([arg])
28         raise Puppet::ParseError, ("#{arg.inspect} is not a boolean.  It looks to be a #{arg.class}")
29       end
30     end
31
32   end
33
34 end