puppetlabs-stdlib/prefix.rb
Krzysztof Wilczynski b26d5b2f3b Now prefix will convert everything into string which is the same
as join would do.  Also function is now more robust in error detection.

Signed-off-by: Krzysztof Wilczynski <krzysztof.wilczynski@linux.com>
2011-04-30 02:40:04 +01:00

38 lines
873 B
Ruby

#
# prefix.rb
#
module Puppet::Parser::Functions
newfunction(:prefix, :type => :rvalue, :doc => <<-EOS
EOS
) do |arguments|
# Technically we support two arguments but only first is mandatory ...
raise(Puppet::ParseError, "prefix(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1
array = arguments[0]
unless array.is_a?(Array)
raise(Puppet::ParseError, 'prefix(): Requires array to work with')
end
prefix = arguments[1] if arguments[1]
if prefix
unless prefix.is_a?(String)
raise(Puppet::ParseError, 'prefix(): Requires string to work with')
end
end
# Turn everything into string same as join would do ...
result = array.collect do |i|
i = i.to_s
prefix ? prefix + i : i
end
return result
end
end
# vim: set ts=2 sw=2 et :