diff options
author | Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> | 2011-04-30 02:57:48 +0100 |
---|---|---|
committer | Krzysztof Wilczynski <krzysztof.wilczynski@linux.com> | 2011-04-30 02:57:48 +0100 |
commit | f74ab047cd397f16f57e8a3516d5ef7cafcc24d7 (patch) | |
tree | bbdbcd9fc287b6f00456cb48481ac2da4281c833 /bool2num.rb | |
parent | 4da6d8222eeca060ad91c9a49f965ec1150a37c2 (diff) |
Change boolean detecion from string to make entire function more robust.
Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
Diffstat (limited to 'bool2num.rb')
-rw-r--r-- | bool2num.rb | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/bool2num.rb b/bool2num.rb index 65c8295..b2989d0 100644 --- a/bool2num.rb +++ b/bool2num.rb @@ -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 |