Suggest different variables to use if we want to tunnel both v4 and v6
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / join.rb
1 #
2 # join.rb
3 #
4 module Puppet::Parser::Functions
5   newfunction(:join, :type => :rvalue, :doc => <<-DOC
6     This function joins an array into a string using a separator.
7
8     *Examples:*
9
10         join(['a','b','c'], ",")
11
12     Would result in: "a,b,c"
13
14     Note: from Puppet 5.4.0, the compatible function with the same name in Puppet core
15     will be used instead of this function.
16     DOC
17              ) do |arguments|
18
19     # Technically we support two arguments but only first is mandatory ...
20     raise(Puppet::ParseError, "join(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
21
22     array = arguments[0]
23
24     unless array.is_a?(Array)
25       raise(Puppet::ParseError, 'join(): Requires array to work with')
26     end
27
28     suffix = arguments[1] if arguments[1]
29
30     if suffix
31       unless suffix.is_a?(String)
32         raise(Puppet::ParseError, 'join(): Requires string to work with')
33       end
34     end
35
36     result = suffix ? array.join(suffix) : array.join
37
38     return result
39   end
40 end
41
42 # vim: set ts=2 sw=2 et :