]> git.donarmstrong.com Git - dsa-puppet.git/blobdiff - 3rdparty/modules/apache/lib/puppet/parser/functions/bool2httpd.rb
try again, with puppetforge modules, correctly included now
[dsa-puppet.git] / 3rdparty / modules / apache / lib / puppet / parser / functions / bool2httpd.rb
diff --git a/3rdparty/modules/apache/lib/puppet/parser/functions/bool2httpd.rb b/3rdparty/modules/apache/lib/puppet/parser/functions/bool2httpd.rb
new file mode 100644 (file)
index 0000000..5fb79f6
--- /dev/null
@@ -0,0 +1,30 @@
+Puppet::Parser::Functions::newfunction(:bool2httpd, :type => :rvalue, :doc => <<-EOS
+Transform a supposed boolean to On or Off. Pass all other values through.
+Given a nil value (undef), bool2httpd will return 'Off'
+
+Example:
+
+    $trace_enable     = false
+    $server_signature = 'mail'
+
+    bool2httpd($trace_enable)
+    # => 'Off'
+    bool2httpd($server_signature)
+    # => 'mail'
+    bool2httpd(undef)
+    # => 'Off'
+
+EOS
+) do |args|
+  raise(Puppet::ParseError, "bool2httpd() wrong number of arguments. Given: #{args.size} for 1)") if args.size != 1
+
+  arg = args[0]
+
+  if arg.nil? or arg == false or arg =~ /false/i or arg == :undef
+    return 'Off'
+  elsif arg == true or arg =~ /true/i
+    return 'On'
+  end
+
+  return arg.to_s
+end