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

class Puppet::Parser::AST
    # A reference to an object.  Only valid as an rvalue.
    class ResourceRef < AST::Branch
        attr_accessor :title, :type

        def each
            [@type,@title].flatten.each { |param|
                #Puppet.debug("yielding param %s" % param)
                yield param
            }
        end

        # Evaluate our object, but just return a simple array of the type
        # and name.
        def evaluate(hash)
            scope = hash[:scope]

            # We want a lower-case type.
            objtype = @type.downcase

            title = @title.safeevaluate(:scope => scope)

            return Puppet::Parser::Resource::Reference.new(
                :type => objtype, :title => title
            )
        end

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

        def to_s
            return "%s[%s]" % [@type,@title]
        end
    end
end

# $Id$