Skip to content

Commit

Permalink
Merge pull request #4 from jordiprats/master
Browse files Browse the repository at this point in the history
afegida funció bool2boolstr
  • Loading branch information
jordiprats authored Jun 13, 2016
2 parents 343fe40 + a9d0c6d commit 03d8073
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
28 changes: 28 additions & 0 deletions lib/puppet/parser/functions/bool2boolstr.rb
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(:bool2boolstr, :type => :rvalue, :doc => <<-EOS
Transform a supposed boolean to "true" or "false". Pass all other values through.
Given a nil value (undef), bool2boolstr will return "false"
EOS
) do |args|
raise(Puppet::ParseError, "bool2boolstr() 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 'false'
elsif arg == true or arg =~ /true/i or arg =~ /yes/i
return 'true'
end

return arg.to_s
end
2 changes: 1 addition & 1 deletion lib/puppet/parser/functions/bool2yn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
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'
Given a nil value (undef), bool2yn will return 'N'
EOS
) do |args|
raise(Puppet::ParseError, "bool2yn() wrong number of arguments. #{args.size} vs 1)") if args.size != 1
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eyp-eyplib",
"version": "0.1.5",
"version": "0.1.6",
"author": "eyp",
"summary": "Utility functions for puppet modules",
"license": "Apache-2.0",
Expand Down

0 comments on commit 03d8073

Please sign in to comment.