Skip to content

Commit

Permalink
afegit bool2number
Browse files Browse the repository at this point in the history
  • Loading branch information
jordiprats committed Jun 6, 2016
1 parent 483c803 commit f2fb0e2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions lib/puppet/parser/functions/bool2number.rb
Original file line number Diff line number Diff line change
@@ -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: [email protected]
#
#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
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.3",
"version": "0.1.4",
"author": "eyp",
"summary": "Utility functions for puppet modules",
"license": "Apache-2.0",
Expand Down

0 comments on commit f2fb0e2

Please sign in to comment.