forked from example42/puppi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbool2ensure.rb
32 lines (27 loc) · 885 Bytes
/
bool2ensure.rb
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
28
29
30
31
32
#
# bool2ensure.rb
#
# This define return present/absent accroding to the boolean value passed
#
module Puppet::Parser::Functions
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
end
# vim: set ts=2 sw=2 et :