Module: Log

Defined in:
lib/puppet/parser/functions/log.rb

Class Method Summary collapse

Class Method Details

.build(hash, indent, buffer) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/puppet/parser/functions/log.rb', line 17

def self.build(hash, indent, buffer)
    indent = indent + '    '
    if hash.keys.length != 1
        return 'Error'
    end

    key = hash.keys[0]

    value = hash[key]

    if value.is_a? String
        build_reference(key, value, indent, buffer)
    elsif value.is_a? Array
        buffer << "#{indent}#{key} {\n"
        build_array(value, indent, buffer)
        buffer << "#{indent}};\n" 
    elsif value.is_a? Hash
        buffer <<  "#{indent}Build error\n"
    end
end

.build_array(array, indent, buffer) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/puppet/parser/functions/log.rb', line 9

def self.build_array(array, indent, buffer)
    array.each do |item|
        if item.is_a? Hash
            build(item, indent, buffer)
        end
    end
end

.build_reference(key, value, indent, buffer) ⇒ Object



5
6
7
# File 'lib/puppet/parser/functions/log.rb', line 5

def self.build_reference(key, value, indent, buffer)
    buffer << "#{indent}#{key}(#{value});\n"
end

.generate_log(options) ⇒ Object



38
39
40
41
42
43
44
45
# File 'lib/puppet/parser/functions/log.rb', line 38

def self.generate_log(options)
    buffer = StringIO.new
    indent = ''
    buffer << "log {\n"
    build_array(options, indent, buffer)
    buffer << "};\n"
    return buffer.string
end