Adding support for strings and hashes to the function empty.

Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
This commit is contained in:
Krzysztof Wilczynski 2011-04-29 18:27:52 +01:00
parent 456a351ac2
commit af1ba5ce8a

View file

@ -12,13 +12,15 @@ module Puppet::Parser::Functions
raise(Puppet::ParseError, "empty(): Wrong number of arguments " + raise(Puppet::ParseError, "empty(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1 "given (#{arguments.size} for 1)") if arguments.size < 1
array = arguments[0] value = arguments[0]
klass = value.class
if not array.is_a?(Array) if not [Array, Hash, String].include?(klass)
raise(Puppet::ParseError, 'empty(): Requires an array to work with') raise(Puppet::ParseError, 'empty(): Requires either an ' +
'array, hash or string to work with')
end end
result = array.empty? result = value.empty?
return result return result
end end