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