summaryrefslogtreecommitdiff
path: root/templates/troclarc.yaml.erb
blob: 5584fd821c78053ee12dd3b07714e6d30e69fbbe (plain)
1
2
3
4
5
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
38
39
40
41
42
43
44
<%
  # stupid but effective sorting of yaml
  # forgive me for that, but puppet monkeypatches yaml heavily and breaks it constantly
  # for our use case it should be sufficient, otherwise we need to
  # extent it to address the new problems
  def sort_pseudo_yaml(obj, indent='')
    arr = obj.sort {|a,b| (a[0].is_a?(Symbol) ? a[0].to_s : a[0]) <=> (b[0].is_a?(Symbol) ? b[0].to_s : b[0]) }
    out = []
    arr.each do |e|
      if e[1].is_a?(Hash)
        out << "#{indent}#{e[0]}:"
        out << sort_pseudo_yaml(e[1],indent+'  ')
      elsif e[1].is_a?(Array)
        out << (["#{indent}#{e[0]}:"]+e[1].collect{|e| "- #{e}" }).join("\n#{indent}")
      else
        out << "#{indent}#{e[0].is_a?(Symbol) ? ":#{e[0].to_s}" : e[0]}: #{e[1].is_a?(Symbol) ? ":#{e[1].to_s}" : e[1]}"
      end
    end
    out.join("\n")
  end
  def sym_keys(h)
    h.keys.inject({}) do |r,k|
      r[k.to_sym] = h[k]
      r
    end
  end
  # transform special options so they are understood by the other libraries
  so = @store_options.dup
  so['adapter'] = so['adapter'].to_sym if so['adapter']
  so['adapter_options'] = sym_keys(so['adapter_options']) if so['adapter_options']
  eo = @encryption_options ? sym_keys(@encryption_options) : {}
  options_hash = {
    'store'              => @store.nil? ? @store : @store.to_sym,
    'store_options'      => so,
    'encryption'         => @encryption.nil? ? @encryption : @encryption.to_sym,
    'encryption_options' => eo,
    'options'            => @options,
    'profiles'           => @merged_profiles,
  }.delete_if{|k,v| v.nil? || (v.is_a?(Symbol) ? v.to_s : v).empty? }
  output = sort_pseudo_yaml(options_hash)
-%>---
<% unless output.empty? -%>
<%= output %>
<% end -%>