]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
Change boolean detecion from string to make entire function more robust.
authorKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>
Sat, 30 Apr 2011 01:57:48 +0000 (02:57 +0100)
committerKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>
Sat, 30 Apr 2011 01:57:48 +0000 (02:57 +0100)
Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
bool2num.rb

index 65c829555c1b0e1984aa5846f263e89e6fd7fd64..b2989d03d10ac9806ed94e7d424e168584716d6a 100644 (file)
@@ -20,26 +20,24 @@ module Puppet::Parser::Functions
     end
 
     if value.is_a?(String)
-
       # We consider all the yes, no, y, n and so on too ...
-      result = case value
+      value = case value
         #
         # This is how undef looks like in Puppet ...
         # We yield 0 (or false if you wish) in this case.
         #
-        when /^$/, '' then 0 # Empty string will be false ...
-        when /^(1|t|y|true|yes)$/  then 1
-        when /^(0|f|n|false|no)$/  then 0
-        when /^(undef|undefined)$/ then 0 # This is not likely to happen ...
+        when /^$/, '' then false # Empty string will be false ...
+        when /^(1|t|y|true|yes)$/  then true
+        when /^(0|f|n|false|no)$/  then false
+        when /^(undef|undefined)$/ then false # This is not likely to happen ...
         else
           raise(Puppet::ParseError, 'bool2num(): Unknown type of boolean given')
       end
-
-    else
-      # We have real boolean values as well ...
-      result = value ? 1 : 0
     end
 
+    # We have real boolean values as well ...
+    result = value ? 1 : 0
+
     return result
   end
 end