summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/ast/resourcedefaults.rb
blob: df16b1b596000f166735a4719cc632936ca1e36a (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
require 'puppet/parser/ast/branch'

class Puppet::Parser::AST
    # A statement syntactically similar to an ResourceDef, but uses a
    # capitalized object type and cannot have a name.  
    class ResourceDefaults < AST::Branch
        attr_accessor :type, :params

        def each
            [@type,@params].each { |child| yield child }
        end

        # As opposed to ResourceDef, this stores each default for the given
        # object type.
        def evaluate(hash)
            scope = hash[:scope]
            type = @type.downcase
            params = @params.safeevaluate(:scope => scope)

            parsewrap do
                scope.setdefaults(type, params)
            end
        end

        def tree(indent = 0)
            return [
                @type.tree(indent + 1),
                ((@@indline * 4 * indent) + self.typewrap(self.pin)),
                @params.tree(indent + 1)
            ].join("\n")
        end

        def to_s
            return "%s { %s }" % [@type,@params]
        end
    end

end

# $Id$