-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from jordiprats/master
bool2number i bool2yn
- Loading branch information
Showing
3 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#shamesly stolen from: https://github.com/puppetlabs/puppetlabs-apache/blob/master/lib/puppet/parser/functions/bool2httpd.rb | ||
# with minor changes | ||
# | ||
# | ||
#Copyright (C) 2012 Puppet Labs Inc | ||
# | ||
#Puppet Labs can be contacted at: [email protected] | ||
# | ||
#Licensed under the Apache License, Version 2.0 (the "License"); | ||
# | ||
# | ||
Puppet::Parser::Functions::newfunction(:bool2number, :type => :rvalue, :doc => <<-EOS | ||
Transform a supposed boolean to 1 or 0. Other values through. | ||
EOS | ||
) do |args| | ||
raise(Puppet::ParseError, "bool2number() 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 =~ /off/i or arg == :undef | ||
return '0' | ||
elsif arg == true or arg =~ /true/i or arg =~ /on/i | ||
return '1' | ||
end | ||
|
||
return arg.to_s | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#shamesly stolen from: https://github.com/puppetlabs/puppetlabs-apache/blob/master/lib/puppet/parser/functions/bool2httpd.rb | ||
# with minor changes | ||
# | ||
# | ||
#Copyright (C) 2012 Puppet Labs Inc | ||
# | ||
#Puppet Labs can be contacted at: [email protected] | ||
# | ||
#Licensed under the Apache License, Version 2.0 (the "License"); | ||
# | ||
# | ||
Puppet::Parser::Functions::newfunction(:bool2yn, :type => :rvalue, :doc => <<-EOS | ||
Transform a supposed boolean to yes or no. Pass all other values through. | ||
Given a nil value (undef), bool2yesno will return 'N' | ||
EOS | ||
) do |args| | ||
raise(Puppet::ParseError, "bool2yn() wrong number of arguments. #{args.size} vs 1)") if args.size != 1 | ||
|
||
arg = args[0] | ||
|
||
if arg.nil? or arg == false or arg =~ /false/i or arg =~ /no/i or arg == :undef | ||
return 'N' | ||
elsif arg == true or arg =~ /true/i or arg =~ /yes/i | ||
return 'Y' | ||
end | ||
|
||
return arg.to_s | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters