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:
parent
726746649e
commit
0ff8b00a64
14 changed files with 29 additions and 27 deletions
5
chomp.rb
5
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
|
||||
|
|
3
chop.rb
3
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
|
||||
|
|
4
count.rb
4
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]
|
||||
|
|
2
fact.rb
2
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
|
||||
|
||||
|
|
4
join.rb
4
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]
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
4
keys.rb
4
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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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 ...
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 ...
|
||||
|
|
Loading…
Reference in a new issue