2011-04-26 01:09:26 +02:00
|
|
|
#
|
|
|
|
# empty.rb
|
|
|
|
#
|
|
|
|
|
|
|
|
module Puppet::Parser::Functions
|
|
|
|
newfunction(:empty, :type => :rvalue, :doc => <<-EOS
|
2011-07-30 00:09:30 +02:00
|
|
|
Returns true if the variable is empty.
|
2011-04-26 01:09:26 +02:00
|
|
|
EOS
|
|
|
|
) do |arguments|
|
|
|
|
|
|
|
|
raise(Puppet::ParseError, "empty(): Wrong number of arguments " +
|
|
|
|
"given (#{arguments.size} for 1)") if arguments.size < 1
|
|
|
|
|
2011-04-29 19:27:52 +02:00
|
|
|
value = arguments[0]
|
2011-04-26 01:09:26 +02:00
|
|
|
|
2015-09-22 18:05:37 +02:00
|
|
|
unless value.is_a?(Array) || value.is_a?(Hash) || value.is_a?(String) || value.is_a?(Numeric)
|
2011-04-30 01:58:37 +02:00
|
|
|
raise(Puppet::ParseError, 'empty(): Requires either ' +
|
2015-09-22 18:05:37 +02:00
|
|
|
'array, hash, string or integer to work with')
|
2011-04-26 01:09:26 +02:00
|
|
|
end
|
|
|
|
|
2015-09-22 18:05:37 +02:00
|
|
|
if value.is_a?(Numeric)
|
|
|
|
return false
|
|
|
|
else
|
|
|
|
result = value.empty?
|
2011-04-26 01:09:26 +02:00
|
|
|
|
2015-09-22 18:05:37 +02:00
|
|
|
return result
|
|
|
|
end
|
2011-04-26 01:09:26 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# vim: set ts=2 sw=2 et :
|