2011-04-26 01:14:24 +02:00
|
|
|
#
|
|
|
|
# reverse.rb
|
|
|
|
#
|
|
|
|
|
|
|
|
module Puppet::Parser::Functions
|
|
|
|
newfunction(:reverse, :type => :rvalue, :doc => <<-EOS
|
2011-07-29 23:18:56 +02:00
|
|
|
Reverses the order of a string or array.
|
2011-04-26 01:14:24 +02:00
|
|
|
EOS
|
|
|
|
) do |arguments|
|
|
|
|
|
|
|
|
raise(Puppet::ParseError, "reverse(): Wrong number of arguments " +
|
|
|
|
"given (#{arguments.size} for 1)") if arguments.size < 1
|
|
|
|
|
2011-04-29 18:30:04 +02:00
|
|
|
value = arguments[0]
|
|
|
|
klass = value.class
|
2011-04-26 01:14:24 +02:00
|
|
|
|
2011-04-30 00:30:32 +02:00
|
|
|
unless [Array, String].include?(klass)
|
|
|
|
raise(Puppet::ParseError, 'reverse(): Requires either ' +
|
2011-04-29 18:30:04 +02:00
|
|
|
'array or string to work with')
|
2011-04-26 01:14:24 +02:00
|
|
|
end
|
|
|
|
|
2011-04-29 18:30:04 +02:00
|
|
|
result = value.reverse
|
2011-04-26 01:14:24 +02:00
|
|
|
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# vim: set ts=2 sw=2 et :
|