Last change
on this file since 30960 was 30960, checked in by davidb, 7 years ago |
Switch to using Puppet to provision machine. Strongly based on files developed for spark-hdfs cluster
|
File size:
825 bytes
|
Line | |
---|
1 | #
|
---|
2 | # difference.rb
|
---|
3 | #
|
---|
4 |
|
---|
5 | module Puppet::Parser::Functions
|
---|
6 | newfunction(:difference, :type => :rvalue, :doc => <<-EOS
|
---|
7 | This function returns the difference between two arrays.
|
---|
8 | The returned array is a copy of the original array, removing any items that
|
---|
9 | also appear in the second array.
|
---|
10 |
|
---|
11 | *Examples:*
|
---|
12 |
|
---|
13 | difference(["a","b","c"],["b","c","d"])
|
---|
14 |
|
---|
15 | Would return: ["a"]
|
---|
16 | EOS
|
---|
17 | ) do |arguments|
|
---|
18 |
|
---|
19 | # Two arguments are required
|
---|
20 | raise(Puppet::ParseError, "difference(): Wrong number of arguments " +
|
---|
21 | "given (#{arguments.size} for 2)") if arguments.size != 2
|
---|
22 |
|
---|
23 | first = arguments[0]
|
---|
24 | second = arguments[1]
|
---|
25 |
|
---|
26 | unless first.is_a?(Array) && second.is_a?(Array)
|
---|
27 | raise(Puppet::ParseError, 'difference(): Requires 2 arrays')
|
---|
28 | end
|
---|
29 |
|
---|
30 | result = first - second
|
---|
31 |
|
---|
32 | return result
|
---|
33 | end
|
---|
34 | end
|
---|
35 |
|
---|
36 | # vim: set ts=2 sw=2 et :
|
---|
Note:
See
TracBrowser
for help on using the repository browser.