]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/horizon/lib/puppet/parser/functions/os_any2array.rb
a3877a0bd3c20aacc31c41a5903fa049d817539c
[dsa-puppet.git] / 3rdparty / modules / horizon / lib / puppet / parser / functions / os_any2array.rb
1 #
2 # os_any2array.rb
3 #
4 # TODO: Remove this function when puppetlabs-stdlib 4.0.0 is in wider use
5
6 module Puppet::Parser::Functions
7   newfunction(:os_any2array, :type => :rvalue, :doc => <<-EOS
8 This converts any object to an array containing that object. Empty argument
9 lists are converted to an empty array. Arrays are left untouched. Hashes are
10 converted to arrays of alternating keys and values.
11     EOS
12   ) do |arguments|
13
14     if arguments.empty?
15         return []
16     end
17
18     if arguments.length == 1
19         if arguments[0].kind_of?(Array)
20             return arguments[0]
21         elsif arguments[0].kind_of?(Hash)
22             result = []
23             arguments[0].each do |key, value|
24                 result << key << value
25             end
26             return result
27         end
28     end
29
30     return arguments
31   end
32 end
33
34 # vim: set ts=2 sw=2 et :