Puppet Function: bool2ensure

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

Overview

bool2ensure()Any

This converts any input similar to a boolean to the stringpresent or absent

Returns:

  • (Any)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/puppet/parser/functions/bool2ensure.rb', line 7

newfunction(:bool2ensure, :type => :rvalue, :doc => <<-EOS
This converts any input similar to a boolean to the stringpresent or absent
  EOS
) do |arguments|

  raise(Puppet::ParseError, "bool2ensure(): Wrong number of arguments " +
    "given (#{arguments.size} for 1)") if arguments.size < 1

  string = arguments[0]

  result = case string
    when false then "absent"
    when true then "present"
    when /^$/, '' then "present" 
    when /^(1|t|y|true|yes)$/  then "present"
    when /^(0|f|n|false|no)$/  then "absent"
    when /^(undef|undefined)$/ then "present"
    else
      raise(Puppet::ParseError, 'bool2ensure(): Unknown type of boolean given')
  end

  return result
end