diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ca5740..051f372 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## 0.1.12 + +* added **yesno2bool** function + ## 0.1.11 * added **git clone** type to clone repos diff --git a/lib/puppet/parser/functions/yesno2bool.rb b/lib/puppet/parser/functions/yesno2bool.rb new file mode 100644 index 0000000..cfd9f9d --- /dev/null +++ b/lib/puppet/parser/functions/yesno2bool.rb @@ -0,0 +1,26 @@ +#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(:yesno2bool, :type => :rvalue, :doc => <<-EOS +Transform a supposed string ('yes', 'true' or 'no', 'false') to a bool (true or false). +Unexpected values will return true and nil value (undef) will return false +EOS +) do |args| + raise(Puppet::ParseError, "bool2yesno() 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 + else + return true + end +end diff --git a/metadata.json b/metadata.json index adb23f0..9d71edd 100644 --- a/metadata.json +++ b/metadata.json @@ -1,6 +1,6 @@ { "name": "eyp-eyplib", - "version": "0.1.11", + "version": "0.1.12", "author": "eyp", "summary": "Utility functions for puppet modules", "license": "Apache-2.0",