Module: ConfigParser

Defined in:
modules/graphite/lib/puppet/functions/graphite/configparser_format.rb

Overview

SPDX-License-Identifier: Apache-2.0

Function: configparser_format

Serialize a hash to Python ConfigParser format. See <docs.python.org/2/library/configparser.html>

Class Method Summary collapse

Class Method Details

.format(config) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'modules/graphite/lib/puppet/functions/graphite/configparser_format.rb', line 19

def self::format(config)
  # Serialize a hash to Python ConfigParser format.
  config.sort.map { |section, items|
    ["[#{section}]"].concat items.sort.map { |k, v|
      if v.is_a?(Array)
        v = v.join(',')
      else
        v = v == :undef ? '' : v
      end

      "#{k} = #{v}"
    }.push []
  }.join("\n")
end

.rmerge(*args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'modules/graphite/lib/puppet/functions/graphite/configparser_format.rb', line 8

def self::rmerge(*args)
  # Recursively merge hashes.
  merged = args.shift.clone
  args.each do |hash|
    merged.merge!(hash) do |k, old, new|
      merged[k] = old.is_a?(Hash) && new.is_a?(Hash) ? ConfigParser.rmerge(old, new) : new
    end
  end
  merged
end