From a9d0c6d301c05a4200222f25e2ad702ee991752e Mon Sep 17 00:00:00 2001 From: Jordi Prats Date: Fri, 10 Jun 2016 16:14:26 +0200 Subject: [PATCH] =?UTF-8?q?afegida=20funci=C3=B3bool2boolstr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/puppet/parser/functions/bool2boolstr.rb | 28 +++++++++++++++++++++ lib/puppet/parser/functions/bool2yn.rb | 2 +- metadata.json | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 lib/puppet/parser/functions/bool2boolstr.rb diff --git a/lib/puppet/parser/functions/bool2boolstr.rb b/lib/puppet/parser/functions/bool2boolstr.rb new file mode 100644 index 0000000..70e88ed --- /dev/null +++ b/lib/puppet/parser/functions/bool2boolstr.rb @@ -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: info@puppetlabs.com +# +#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 diff --git a/lib/puppet/parser/functions/bool2yn.rb b/lib/puppet/parser/functions/bool2yn.rb index 3b44ed0..db405b1 100644 --- a/lib/puppet/parser/functions/bool2yn.rb +++ b/lib/puppet/parser/functions/bool2yn.rb @@ -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 diff --git a/metadata.json b/metadata.json index f03d009..6280131 100644 --- a/metadata.json +++ b/metadata.json @@ -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",