]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
Small re-factor. Changed if not to unless for code clarity.
authorKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>
Fri, 29 Apr 2011 22:30:32 +0000 (23:30 +0100)
committerKrzysztof Wilczynski <krzysztof.wilczynski@linux.com>
Fri, 29 Apr 2011 22:30:32 +0000 (23:30 +0100)
Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
14 files changed:
chomp.rb
chop.rb
count.rb
fact.rb
join.rb
join_with_prefix.rb
keys.rb
lstrip.rb
prefix.rb
reverse.rb
rstrip.rb
str2bool.rb
values.rb
values_at.rb

index bec3adf1c8a6ff0d6c29ca25e8d1b7d5dfda3b70..aba9e8decc63a964b039540af7986504bb2f195e 100644 (file)
--- 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 2f6b2d2e8390af260f8a18f80177c8743ee536cd..32ce040008fea1ec23815212511edbe6837d2918 100644 (file)
--- 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
index 9ea403327f36ae51a0de598009f30c3955e3c75a..e4bf22e436e9049e0f2325690a2621352fea3f7b 100644 (file)
--- 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 0f4114e729b48111fb0abcdaf1dd1d5e723a8b8f..00aa572bb5843c024c80787bbfa666b5254a8b86 100644 (file)
--- 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 39615fd1989caa5a5b0184e8f820993306b2d5c4..4d20731f5e4790c32f0fa6440ce399747ec20c4c 100644 (file)
--- 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]
index c0a2e4efebef4d71b49140712cfdede57067fa7f..8bf96d915204e79cef61ded5fce79edd29f1f8b3 100644 (file)
@@ -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 7d50889733ad7d4c22f62b039fbc6e6e09eb5b58..3a92a47c7aeb796119967bfdb0ac23a939b912c8 100644 (file)
--- 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 hash to work with')
+    unless hash.is_a?(Hash)
+      raise(Puppet::ParseError, 'keys(): Requires hash to work with')
     end
 
     result = hash.keys
index 7f205a877762ab57953d787378b5f1c8ddb6fbf3..241b68355251427aef334e9162f83944f5061006 100644 (file)
--- 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
 
index bf3690dd789c3cedafe753c4aa4e8684641de496..572ff4e0538615c4d1f1b29a4db4d89fb9f548ab 100644 (file)
--- 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]
index 86dee28c9e61d1f8d49a12fd065b1911bf468aff..79e9b9358ee7fa2c0d8770b2d53a5eed52117b8e 100644 (file)
@@ -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
 
index b198488d4637a61e8c3af723eaf9e974d68061a9..56849d30a4b282506d7211de4a10690e74fbbcfe 100644 (file)
--- 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
 
index 02b5aaef4a0773bd26d3abe41869b68d900fd085..5a52f250f871d1f821cf7bed7e85a05caf8f8ce6 100644 (file)
@@ -12,11 +12,12 @@ module Puppet::Parser::Functions
 
     string = arguments[0]
 
-    if not string.is_a?(String)
-      raise(Puppet::ParseError, 'str2bool(): Requires either ' +
+    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 ...
index 8e5818458e212eef9ce348913575848e7a24faca..c1c4a774dbdbe7a2cdbbee4fd3d9fd0a0daeab9c 100644 (file)
--- 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 hash to work with')
+    unless hash.is_a?(Hash)
+      raise(Puppet::ParseError, 'values(): Requires hash to work with')
     end
 
     result = hash.values
index cd7205d29c11a40ef23cfa33b6bf17a560fd9a31..331af6a138cec8b8ccda290c30cfe9c41df222ef 100644 (file)
@@ -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 ...