comparison modules/stdlib/lib/puppet/parser/functions/unique.rb @ 272:c42fb28cff86

Update to a newer Python module This also pulls in an EPEL module (which we don't use) and a newer stdlib version.
author IBBoard <dev@ibboard.co.uk>
date Fri, 03 Jan 2020 19:56:04 +0000
parents addb0ea390a1
children d9352a684e62
comparison
equal deleted inserted replaced
271:c62728474654 272:c42fb28cff86
1 # 1 #
2 # unique.rb 2 # unique.rb
3 # 3 #
4 module Puppet::Parser::Functions
5 newfunction(:unique, :type => :rvalue, :doc => <<-DOC
6 This function will remove duplicates from strings and arrays.
4 7
5 module Puppet::Parser::Functions 8 *Examples:*
6 newfunction(:unique, :type => :rvalue, :doc => <<-EOS
7 This function will remove duplicates from strings and arrays.
8 9
9 *Examples:* 10 unique("aabbcc")
10 11
11 unique("aabbcc") 12 Will return:
12 13
13 Will return: 14 abc
14 15
15 abc 16 You can also use this with arrays:
16 17
17 You can also use this with arrays: 18 unique(["a","a","b","b","c","c"])
18 19
19 unique(["a","a","b","b","c","c"]) 20 This returns:
20 21
21 This returns: 22 ["a","b","c"]
23 DOC
24 ) do |arguments|
22 25
23 ["a","b","c"] 26 if Puppet::Util::Package.versioncmp(Puppet.version, '5.0.0') >= 0
24 EOS 27 function_deprecation([:unique, 'This method is deprecated, please use the core puppet unique function. There is further documentation for the function in the release notes of Puppet 5.0.'])
25 ) do |arguments| 28 end
26 29
27 raise(Puppet::ParseError, "unique(): Wrong number of arguments " + 30 raise(Puppet::ParseError, "unique(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty?
28 "given (#{arguments.size} for 1)") if arguments.size < 1
29 31
30 value = arguments[0] 32 value = arguments[0]
31 33
32 unless value.is_a?(Array) || value.is_a?(String) 34 unless value.is_a?(Array) || value.is_a?(String)
33 raise(Puppet::ParseError, 'unique(): Requires either ' + 35 raise(Puppet::ParseError, 'unique(): Requires either array or string to work with')
34 'array or string to work with')
35 end 36 end
36 37
37 result = value.clone 38 result = value.clone
38 39
39 string = value.is_a?(String) ? true : false 40 string = value.is_a?(String) ? true : false