]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/apache/lib/puppet/parser/functions/bool2httpd.rb
add Openstack modules to 3rdparty
[dsa-puppet.git] / 3rdparty / modules / apache / lib / puppet / parser / functions / bool2httpd.rb
1 Puppet::Parser::Functions::newfunction(:bool2httpd, :type => :rvalue, :doc => <<-EOS
2 Transform a supposed boolean to On or Off. Pass all other values through.
3 Given a nil value (undef), bool2httpd will return 'Off'
4
5 Example:
6
7     $trace_enable     = false
8     $server_signature = 'mail'
9
10     bool2httpd($trace_enable)
11     # => 'Off'
12     bool2httpd($server_signature)
13     # => 'mail'
14     bool2httpd(undef)
15     # => 'Off'
16
17 EOS
18 ) do |args|
19   raise(Puppet::ParseError, "bool2httpd() wrong number of arguments. Given: #{args.size} for 1)") if args.size != 1
20
21   arg = args[0]
22
23   if arg.nil? or arg == false or arg =~ /false/i or arg == :undef
24     return 'Off'
25   elsif arg == true or arg =~ /true/i
26     return 'On'
27   end
28
29   return arg.to_s
30 end