Puppet Function: bool2httpd

Defined in:
lib/puppet/parser/functions/bool2httpd.rb
Function type:
Ruby 3.x API

Summary

Transform a supposed boolean to On or Off. Pass all other values through.

Overview

bool2httpd(Any $arg)Any

Examples:

$trace_enable     = false
$server_signature = 'mail'

bool2httpd($trace_enable) # returns 'Off'
bool2httpd($server_signature) # returns 'mail'
bool2httpd(undef) # returns 'Off'

Parameters:

  • arg (Any)

    The value to be converted into a string.

Returns:

  • (Any)

    Will return either ‘On` or `Off` if given a boolean value. Return’s a string of any other given value.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/puppet/parser/functions/bool2httpd.rb', line 1

Puppet::Parser::Functions.newfunction(:bool2httpd, type: :rvalue, doc: <<-DOC
  @summary
    Transform a supposed boolean to On or Off. Pass all other values through.

  @param arg
    The value to be converted into a string.

  @return
    Will return either `On` or `Off` if given a boolean value. Return's a string of any
    other given value.

  @example
    $trace_enable     = false
    $server_signature = 'mail'

    bool2httpd($trace_enable) # returns 'Off'
    bool2httpd($server_signature) # returns 'mail'
    bool2httpd(undef) # returns 'Off'
DOC
                                     ) do |args|
  raise(Puppet::ParseError, "bool2httpd() wrong number of arguments. Given: #{args.size} for 1)") if args.size != 1

  arg = args[0]
  return 'Off' if arg.nil? || arg == false || arg =~ %r{false}i || arg == :undef
  return 'On' if arg == true || arg =~ %r{true}i
  return arg.to_s
end