5 module Puppet::Parser::Functions
6 newfunction(:prefix, :type => :rvalue, :doc => <<-EOS
7 This function applies a prefix to all elements in an array.
11 prefix(['a','b','c'], 'p')
13 Will return: ['pa','pb','pc']
17 # Technically we support two arguments but only first is mandatory ...
18 raise(Puppet::ParseError, "prefix(): Wrong number of arguments " +
19 "given (#{arguments.size} for 1)") if arguments.size < 1
23 unless array.is_a?(Array)
24 raise(Puppet::ParseError, 'prefix(): Requires array to work with')
27 prefix = arguments[1] if arguments[1]
30 unless prefix.is_a?(String)
31 raise(Puppet::ParseError, 'prefix(): Requires string to work with')
35 # Turn everything into string same as join would do ...
36 result = array.collect do |i|
38 prefix ? prefix + i : i
45 # vim: set ts=2 sw=2 et :