Skip to content

Commit

Permalink
yesno2bool
Browse files Browse the repository at this point in the history
  • Loading branch information
jordiprats committed Feb 22, 2018
1 parent cee6ec6 commit da60515
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## 0.1.12

* added **yesno2bool** function

## 0.1.11

* added **git clone** type to clone repos
Expand Down
26 changes: 26 additions & 0 deletions lib/puppet/parser/functions/yesno2bool.rb
Original file line number Diff line number Diff line change
@@ -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: [email protected]
#
#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
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.11",
"version": "0.1.12",
"author": "eyp",
"summary": "Utility functions for puppet modules",
"license": "Apache-2.0",
Expand Down

0 comments on commit da60515

Please sign in to comment.