summaryrefslogtreecommitdiff
path: root/lib/puppet/parser/functions/union.rb
diff options
context:
space:
mode:
authorHailee Kenney <hailee@puppetlabs.com>2013-05-15 13:56:15 -0700
committerHailee Kenney <hailee@puppetlabs.com>2013-05-15 13:56:15 -0700
commita2abfb9894e8b91eeeffea0faa5d6e55a0519667 (patch)
treee13852080cd3a6f8aaae722ab13d2ae252802898 /lib/puppet/parser/functions/union.rb
parentdad3a2948fb9ebc5c45975340bc8796c9c041d9a (diff)
parent737aa31546e71e9febea2199582510ef88a2560c (diff)
Merge pull request #155 from AlexCline/feature/master/array_comparison_functions
(#20684) Add array comparison functions, difference, intersection and union
Diffstat (limited to 'lib/puppet/parser/functions/union.rb')
-rw-r--r--lib/puppet/parser/functions/union.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/puppet/parser/functions/union.rb b/lib/puppet/parser/functions/union.rb
new file mode 100644
index 0000000..c91bb80
--- /dev/null
+++ b/lib/puppet/parser/functions/union.rb
@@ -0,0 +1,34 @@
+#
+# union.rb
+#
+
+module Puppet::Parser::Functions
+ newfunction(:union, :type => :rvalue, :doc => <<-EOS
+This function returns a union of two arrays.
+
+*Examples:*
+
+ union(["a","b","c"],["b","c","d"])
+
+Would return: ["a","b","c","d"]
+ EOS
+ ) do |arguments|
+
+ # Two arguments are required
+ raise(Puppet::ParseError, "union(): Wrong number of arguments " +
+ "given (#{arguments.size} for 2)") if arguments.size != 2
+
+ first = arguments[0]
+ second = arguments[1]
+
+ unless first.is_a?(Array) && second.is_a?(Array)
+ raise(Puppet::ParseError, 'union(): Requires 2 arrays')
+ end
+
+ result = first | second
+
+ return result
+ end
+end
+
+# vim: set ts=2 sw=2 et :