Update stdlib and concat to 6.1.0 both
[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     @summary
7       **Deprecated:** This function joins an array into a string using a separator.
8
9     @example Example Usage:
10       join(['a','b','c'], ",") # Results in: "a,b,c"
11
12     @return [String]
13       The String containing each of the array values
14
15     > **Note:** **Deprecated** from Puppet 5.4.0 this function has been replaced
16     with a built-in [`join`](https://puppet.com/docs/puppet/latest/function.html#join) function.
17     DOC
18              ) do |arguments|
19
20     # Technically we support two arguments but only first is mandatory ...
21     raise(Puppet::ParseError, "join(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
22
23     array = arguments[0]
24
25     unless array.is_a?(Array)
26       raise(Puppet::ParseError, 'join(): Requires array to work with')
27     end
28
29     suffix = arguments[1] if arguments[1]
30
31     if suffix
32       unless suffix.is_a?(String)
33         raise(Puppet::ParseError, 'join(): Requires string to work with')
34       end
35     end
36
37     result = suffix ? array.join(suffix) : array.join
38
39     return result
40   end
41 end
42
43 # vim: set ts=2 sw=2 et :