summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/ast/resource_reference.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2007-09-06 18:53:00 -0500
committerLuke Kanies <luke@madstop.com>2007-09-06 18:53:00 -0500
commitb7f42441b91c921cd31f3d8c7875ce98bdedf786 (patch)
tree07ef5bf2d42027914704d0305a353741d191cc90 /lib/puppet/parser/ast/resource_reference.rb
parent653c1514b613f27cb22d24b4bdd7b6c118047566 (diff)
downloadpuppet-b7f42441b91c921cd31f3d8c7875ce98bdedf786.tar.gz
puppet-b7f42441b91c921cd31f3d8c7875ce98bdedf786.tar.xz
puppet-b7f42441b91c921cd31f3d8c7875ce98bdedf786.zip
Renaming some ast resource classes and files so they make a lot more sense.
Diffstat (limited to 'lib/puppet/parser/ast/resource_reference.rb')
-rw-r--r--lib/puppet/parser/ast/resource_reference.rb66
1 files changed, 66 insertions, 0 deletions
diff --git a/lib/puppet/parser/ast/resource_reference.rb b/lib/puppet/parser/ast/resource_reference.rb
new file mode 100644
index 000000000..b8edff8f1
--- /dev/null
+++ b/lib/puppet/parser/ast/resource_reference.rb
@@ -0,0 +1,66 @@
+require 'puppet/parser/ast/branch'
+
+class Puppet::Parser::AST
+ # A reference to an object. Only valid as an rvalue.
+ class ResourceReference < AST::Branch
+ attr_accessor :title, :type
+ # Is the type a builtin type?
+ def builtintype?(type)
+ if typeklass = Puppet::Type.type(type)
+ return typeklass
+ else
+ return false
+ end
+ end
+
+ 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]
+
+ title = @title.safeevaluate(:scope => scope)
+ if @type == "class"
+ objtype = @type
+ title = qualified_class(scope, title)
+ else
+ objtype = qualified_type(scope)
+ end
+
+ return Puppet::Parser::Resource::Reference.new(
+ :type => objtype, :title => title
+ )
+ end
+
+ # Look up a fully qualified class name.
+ def qualified_class(scope, title)
+ # 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
+ end
+
+ # Look up a fully-qualified type. This method is
+ # also used in AST::Resource.
+ def qualified_type(scope, title = nil)
+ # We want a lower-case type. For some reason.
+ objtype = @type.downcase
+ unless builtintype?(objtype)
+ if dtype = scope.finddefine(objtype)
+ objtype = dtype.classname
+ else
+ raise Puppet::ParseError, "Could not find resource type %s" % objtype
+ end
+ end
+ return objtype
+ end
+ end
+end