summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>2011-04-30 02:48:25 +0100
committerKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>2011-04-30 02:48:25 +0100
commit3c4c1c7c2010d8df0e5e43306cc7b407705d4053 (patch)
tree24d236922543625df836846afd364a2ac81acdfd
parent9ec50e7968bbd53c0e9d3b626ae46ce2eeba7cf1 (diff)
downloadpuppet-stdlib-3c4c1c7c2010d8df0e5e43306cc7b407705d4053.tar.gz
puppet-stdlib-3c4c1c7c2010d8df0e5e43306cc7b407705d4053.tar.bz2
Moved to unless from if not to improve code clarity. Added TODO
for future reference. Changed wording of few error messages. Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
-rw-r--r--num2bool.rb10
1 files changed, 6 insertions, 4 deletions
diff --git a/num2bool.rb b/num2bool.rb
index 0e6b7a5..2baef62 100644
--- a/num2bool.rb
+++ b/num2bool.rb
@@ -2,6 +2,8 @@
# num2bool.rb
#
+# TODO(Krzysztof Wilczynski): We probably need to approach numeric values differently ...
+
module Puppet::Parser::Functions
newfunction(:num2bool, :type => :rvalue, :doc => <<-EOS
EOS
@@ -13,20 +15,20 @@ module Puppet::Parser::Functions
number = arguments[0]
# Only numbers allowed ...
- if not number.match(/^\-?\d+$/)
- raise(Puppet::ParseError, 'num2bool(): Requires a number to work with')
+ unless number.match(/^\-?\d+$/)
+ raise(Puppet::ParseError, 'num2bool(): Requires integer to work with')
end
result = case number
when /^0$/
false
when /^\-?\d+$/
- # In Puppet numbers are often string-encoded ...
+ # Numbers in Puppet are often string-encoded which is troublesome ...
number = number.to_i
# We yield true for any positive number and false otherwise ...
number > 0 ? true : false
else
- raise(Puppet::ParseError, 'num2bool(): Unknown number format given')
+ raise(Puppet::ParseError, 'num2bool(): Unknown numeric format given')
end
return result