summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/ast/asthash.rb
blob: 2860657e09d137ed63e3208698b78e716549ac20 (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
require 'puppet/parser/ast/leaf'

class Puppet::Parser::AST
    class ASTHash < Leaf
        include Enumerable

        def [](index)
        end

        # Evaluate our children.
        def evaluate(scope)
            items = {}

            @value.each_pair do |k,v|
                items.merge!({ k => v.safeevaluate(scope) })
            end

            return items
        end

        def merge(hash)
            case hash
            when ASTHash
                @value = @value.merge(hash.value)
            when Hash
                @value = @value.merge(hash)
            end
        end

        def to_s
            "{" + @value.collect { |v| v.collect { |a| a.to_s }.join(' => ') }.join(', ') + "}"
        end
    end
end