]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/lib/puppet/parser/functions/join.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / join.rb
1 #
2 # join.rb
3 #
4
5 module Puppet::Parser::Functions
6   newfunction(:join, :type => :rvalue, :doc => <<-EOS
7 This function joins an array into a string using a separator.
8
9 *Examples:*
10
11     join(['a','b','c'], ",")
12
13 Would result in: "a,b,c"
14     EOS
15   ) do |arguments|
16
17     # Technically we support two arguments but only first is mandatory ...
18     raise(Puppet::ParseError, "join(): Wrong number of arguments " +
19       "given (#{arguments.size} for 1)") if arguments.size < 1
20
21     array = arguments[0]
22
23     unless array.is_a?(Array)
24       raise(Puppet::ParseError, 'join(): Requires array to work with')
25     end
26
27     suffix = arguments[1] if arguments[1]
28
29     if suffix
30       unless suffix.is_a?(String)
31         raise(Puppet::ParseError, 'join(): Requires string to work with')
32       end
33     end
34
35     result = suffix ? array.join(suffix) : array.join
36
37     return result
38   end
39 end
40
41 # vim: set ts=2 sw=2 et :