From 1faefed56e0ba75f75cc914075f9a8fb825a88a5 Mon Sep 17 00:00:00 2001 From: Jordi Prats Date: Mon, 6 Jun 2016 14:56:22 +0200 Subject: [PATCH] bool2yn --- lib/puppet/parser/functions/bool2yn.rb | 28 ++++++++++++++++++++++++++ metadata.json | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 lib/puppet/parser/functions/bool2yn.rb diff --git a/lib/puppet/parser/functions/bool2yn.rb b/lib/puppet/parser/functions/bool2yn.rb new file mode 100644 index 0000000..3b44ed0 --- /dev/null +++ b/lib/puppet/parser/functions/bool2yn.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(: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 diff --git a/metadata.json b/metadata.json index 0558ded..f03d009 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "eyp-eyplib", - "version": "0.1.4", + "version": "0.1.5", "author": "eyp", "summary": "Utility functions for puppet modules", "license": "Apache-2.0",