From f2fb0e2c85f2d8056e523ad2d2f73e74d7fdfb9a Mon Sep 17 00:00:00 2001 From: Jordi Prats Date: Mon, 6 Jun 2016 13:14:06 +0200 Subject: [PATCH] afegit bool2number --- lib/puppet/parser/functions/bool2number.rb | 27 ++++++++++++++++++++++ metadata.json | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 lib/puppet/parser/functions/bool2number.rb diff --git a/lib/puppet/parser/functions/bool2number.rb b/lib/puppet/parser/functions/bool2number.rb new file mode 100644 index 0000000..d27ee6b --- /dev/null +++ b/lib/puppet/parser/functions/bool2number.rb @@ -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: info@puppetlabs.com +# +#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 diff --git a/metadata.json b/metadata.json index 895290f..0558ded 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "eyp-eyplib", - "version": "0.1.3", + "version": "0.1.4", "author": "eyp", "summary": "Utility functions for puppet modules", "license": "Apache-2.0",