summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>2011-04-29 23:30:32 +0100
committerKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>2011-04-29 23:30:32 +0100
commit0ff8b00a64426acf96d0659d1cbc1f67bba842f4 (patch)
tree34c846c222a34df5059e618be48a3585d9a78458
parent726746649e38615b69aa372ec978b2ffa39b89d5 (diff)
downloadpuppet-stdlib-0ff8b00a64426acf96d0659d1cbc1f67bba842f4.tar.gz
puppet-stdlib-0ff8b00a64426acf96d0659d1cbc1f67bba842f4.tar.bz2
Small re-factor. Changed if not to unless for code clarity.
Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
-rw-r--r--chomp.rb5
-rw-r--r--chop.rb3
-rw-r--r--count.rb4
-rw-r--r--fact.rb2
-rw-r--r--join.rb4
-rw-r--r--join_with_prefix.rb4
-rw-r--r--keys.rb4
-rw-r--r--lstrip.rb4
-rw-r--r--prefix.rb4
-rw-r--r--reverse.rb4
-rw-r--r--rstrip.rb4
-rw-r--r--str2bool.rb5
-rw-r--r--values.rb4
-rw-r--r--values_at.rb5
14 files changed, 29 insertions, 27 deletions
diff --git a/chomp.rb b/chomp.rb
index bec3adf..aba9e8d 100644
--- a/chomp.rb
+++ b/chomp.rb
@@ -13,12 +13,13 @@ module Puppet::Parser::Functions
value = arguments[0]
klass = value.class
- if not [Array, String].include?(klass)
- raise(Puppet::ParseError, 'chomp(): Requires either an ' +
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'chomp(): Requires either ' +
'array or string to work with')
end
if value.is_a?(Array)
+ # Numbers in Puppet are often string-encoded ...
result = value.collect { |i| i.is_a?(String) ? i.chomp : i }
else
result = value.chomp
diff --git a/chop.rb b/chop.rb
index 2f6b2d2..32ce040 100644
--- a/chop.rb
+++ b/chop.rb
@@ -13,12 +13,13 @@ module Puppet::Parser::Functions
value = arguments[0]
klass = value.class
- if not [Array, String].include?(klass)
+ unless [Array, String].include?(klass)
raise(Puppet::ParseError, 'chop(): Requires either an ' +
'array or string to work with')
end
if value.is_a?(Array)
+ # Numbers in Puppet are often string-encoded ...
result = value.collect { |i| i.is_a?(String) ? i.chop : i }
else
result = value.chop
diff --git a/count.rb b/count.rb
index 9ea4033..e4bf22e 100644
--- a/count.rb
+++ b/count.rb
@@ -16,8 +16,8 @@ module Puppet::Parser::Functions
array = arguments[0]
- if not array.is_a?(Array)
- raise(Puppet::ParseError, 'count(): Requires an array to work with')
+ unless array.is_a?(Array)
+ raise(Puppet::ParseError, 'count(): Requires array to work with')
end
item = arguments[1] if arguments[1]
diff --git a/fact.rb b/fact.rb
index 0f4114e..00aa572 100644
--- a/fact.rb
+++ b/fact.rb
@@ -12,7 +12,7 @@ module Puppet::Parser::Functions
fact = arguments[0]
- if not fact.is_a?(String)
+ unless fact.is_a?(String)
raise(Puppet::ParseError, 'fact(): Requires fact name to be a string')
end
diff --git a/join.rb b/join.rb
index 39615fd..4d20731 100644
--- a/join.rb
+++ b/join.rb
@@ -13,8 +13,8 @@ module Puppet::Parser::Functions
array = arguments[0]
- if not array.is_a?(Array)
- raise(Puppet::ParseError, 'join(): Requires an array to work with')
+ unless array.is_a?(Array)
+ raise(Puppet::ParseError, 'join(): Requires array to work with')
end
suffix = arguments[1] if arguments[1]
diff --git a/join_with_prefix.rb b/join_with_prefix.rb
index c0a2e4e..8bf96d9 100644
--- a/join_with_prefix.rb
+++ b/join_with_prefix.rb
@@ -13,8 +13,8 @@ module Puppet::Parser::Functions
array = arguments[0]
- if not array.is_a?(Array)
- raise(Puppet::ParseError, 'join_with_prefix(): Requires an ' +
+ unless array.is_a?(Array)
+ raise(Puppet::ParseError, 'join_with_prefix(): Requires ' +
'array to work with')
end
diff --git a/keys.rb b/keys.rb
index 7d50889..3a92a47 100644
--- a/keys.rb
+++ b/keys.rb
@@ -12,8 +12,8 @@ module Puppet::Parser::Functions
hash = arguments[0]
- if not hash.is_a?(Hash)
- raise(Puppet::ParseError, 'keys(): Requires a hash to work with')
+ unless hash.is_a?(Hash)
+ raise(Puppet::ParseError, 'keys(): Requires hash to work with')
end
result = hash.keys
diff --git a/lstrip.rb b/lstrip.rb
index 7f205a8..241b683 100644
--- a/lstrip.rb
+++ b/lstrip.rb
@@ -13,8 +13,8 @@ module Puppet::Parser::Functions
value = arguments[0]
klass = value.class
- if not [Array, String].include?(klass)
- raise(Puppet::ParseError, 'lstrip(): Requires either an ' +
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'lstrip(): Requires either ' +
'array or string to work with')
end
diff --git a/prefix.rb b/prefix.rb
index bf3690d..572ff4e 100644
--- a/prefix.rb
+++ b/prefix.rb
@@ -13,8 +13,8 @@ module Puppet::Parser::Functions
array = arguments[0]
- if not array.is_a?(Array)
- raise(Puppet::ParseError, 'prefix(): Requires an array to work with')
+ unless array.is_a?(Array)
+ raise(Puppet::ParseError, 'prefix(): Requires array to work with')
end
prefix = arguments[1] if arguments[1]
diff --git a/reverse.rb b/reverse.rb
index 86dee28..79e9b93 100644
--- a/reverse.rb
+++ b/reverse.rb
@@ -13,8 +13,8 @@ module Puppet::Parser::Functions
value = arguments[0]
klass = value.class
- if not [Array, String].include?(klass)
- raise(Puppet::ParseError, 'reverse(): Requires either an ' +
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'reverse(): Requires either ' +
'array or string to work with')
end
diff --git a/rstrip.rb b/rstrip.rb
index b198488..56849d3 100644
--- a/rstrip.rb
+++ b/rstrip.rb
@@ -13,8 +13,8 @@ module Puppet::Parser::Functions
value = arguments[0]
klass = value.class
- if not [Array, String].include?(klass)
- raise(Puppet::ParseError, 'rstrip(): Requires either an ' +
+ unless [Array, String].include?(klass)
+ raise(Puppet::ParseError, 'rstrip(): Requires either ' +
'array or string to work with')
end
diff --git a/str2bool.rb b/str2bool.rb
index 02b5aae..5a52f25 100644
--- a/str2bool.rb
+++ b/str2bool.rb
@@ -12,11 +12,12 @@ module Puppet::Parser::Functions
string = arguments[0]
- if not string.is_a?(String)
- raise(Puppet::ParseError, 'str2bool(): Requires either a ' +
+ unless string.is_a?(String)
+ raise(Puppet::ParseError, 'str2bool(): Requires either ' +
'string to work with')
end
+ # We consider all the yes, no, y, n and so on too ...
result = case string
#
# This is how undef looks like in Puppet ...
diff --git a/values.rb b/values.rb
index 8e58184..c1c4a77 100644
--- a/values.rb
+++ b/values.rb
@@ -12,8 +12,8 @@ module Puppet::Parser::Functions
hash = arguments[0]
- if not hash.is_a?(Hash)
- raise(Puppet::ParseError, 'values(): Requires a hash to work with')
+ unless hash.is_a?(Hash)
+ raise(Puppet::ParseError, 'values(): Requires hash to work with')
end
result = hash.values
diff --git a/values_at.rb b/values_at.rb
index cd7205d..331af6a 100644
--- a/values_at.rb
+++ b/values_at.rb
@@ -15,9 +15,8 @@ module Puppet::Parser::Functions
array = arguments.shift
- if not array.is_a?(Array)
- raise(Puppet::ParseError, 'values_at(): Requires an array ' +
- 'to work with')
+ unless array.is_a?(Array)
+ raise(Puppet::ParseError, 'values_at(): Requires array to work with')
end
indices = *arguments # Get them all ... Pokemon ...