source: other-projects/hathitrust/vagrant-solr-cluster/trunk/modules/stdlib/lib/puppet/parser/functions/concat.rb@ 30960

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: 866 bytes
Line 
1#
2# concat.rb
3#
4
5module Puppet::Parser::Functions
6 newfunction(:concat, :type => :rvalue, :doc => <<-EOS
7Appends the contents of multiple arrays into array 1.
8
9*Example:*
10
11 concat(['1','2','3'],['4','5','6'],['7','8','9'])
12
13Would result in:
14
15 ['1','2','3','4','5','6','7','8','9']
16 EOS
17 ) do |arguments|
18
19 # Check that more than 2 arguments have been given ...
20 raise(Puppet::ParseError, "concat(): Wrong number of arguments " +
21 "given (#{arguments.size} for < 2)") if arguments.size < 2
22
23 a = arguments[0]
24
25 # Check that the first parameter is an array
26 unless a.is_a?(Array)
27 raise(Puppet::ParseError, 'concat(): Requires array to work with')
28 end
29
30 result = a
31 arguments.shift
32
33 arguments.each do |x|
34 result = result + (x.is_a?(Array) ? x : [x])
35 end
36
37 return result
38 end
39end
40
41# vim: set ts=2 sw=2 et :
Note: See TracBrowser for help on using the repository browser.