Puppet Function: clj_vec

Defined in:
lib/puppet/parser/functions/clj_vec.rb
Function type:
Ruby 3.x API

Overview

clj_vec()Any

This converts an array into a string containing a serialized clojure vector.

Example:

The following puppet structure:

[‘service’,‘“users/users”’],

Will yield the string:

(service “users/users”)

Arguments: $array

Returns:

  • (Any)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/puppet/parser/functions/clj_vec.rb', line 6

newfunction(:clj_vec, :type => :rvalue, :doc => <<-EOS
This converts an array into a string containing a serialized clojure vector.

Example:

The following puppet structure:

['service','"users/users"'],

Will yield the string:

(service "users/users")

Arguments: $array
  EOS
) do |arguments|

  if arguments.empty?
    return []
  end

  if arguments.length == 1
    if ! arguments[0].kind_of?(Array)
      raise(Puppet::Error, "clj_vec(): argument must be an array")
    end
  else
    raise(Puppet::Error, "clj_vec(): only one argument accepted")
  end
  
  result = '(' + arguments[0].join(" ") + ')'
  return result
end