Small re-factor. Changed if not to unless for code clarity.

Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
This commit is contained in:
Krzysztof Wilczynski 2011-04-29 23:30:32 +01:00
parent 726746649e
commit 0ff8b00a64
14 changed files with 29 additions and 27 deletions

View file

@ -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

View file

@ -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

View file

@ -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]

View file

@ -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

View file

@ -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]

View 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

View file

@ -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

View file

@ -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

View file

@ -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]

View 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

View file

@ -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

View file

@ -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 ...

View file

@ -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

View 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 ...