Sha256: 86318824161547b63473521940df2d2e75f276840e4f27b4d50d38798627fe52

Contents?: true

Size: 1.73 KB

Versions: 2

Compression:

Stored size: 1.73 KB

Contents

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)

            if scope.builtintype?(objtype)
                # nothing
            elsif dtype = scope.finddefine(objtype)
                objtype = dtype.classname
            elsif objtype == "class"
                # Look up the full path to the class
                if classobj = scope.findclass(title)
                    title = classobj.classname
                else
                    raise Puppet::ParseError, "Could not find class %s" % title
                end
            else
                raise Puppet::ParseError, "Could not find resource type %s" % objtype
            end

            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: resourceref.rb 2715 2007-07-19 19:23:56Z luke $

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
puppet-0.23.1 lib/puppet/parser/ast/resourceref.rb
puppet-0.23.2 lib/puppet/parser/ast/resourceref.rb