summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/ast
diff options
context:
space:
mode:
authorJesse Wolfe <jes5199@gmail.com>2010-07-28 14:54:23 -0700
committerJesse Wolfe <jes5199@gmail.com>2010-07-30 14:28:31 -0700
commit6dbd4771265173a9d4c3e7756c35c9ca371ca394 (patch)
tree835faf9ed49da69b9d2059ed1ebba8cde485d21d /lib/puppet/parser/ast
parent871e6fd58223cad241bcc14f165b3ab1e6e257e6 (diff)
[#4397]+[#4344] Move type-name resolution out of Puppet::Resource into the AST resources.
Move type-name resolution out of Puppet::Resource into the AST resources. Move find_resource_type out of Puppet::Resource into Scope Thus, never pass unqualified type names to Puppet::Resource objects. Thus, Puppet::Resource objects don't need the namespace property, and Puppet::Resource objects never consult the harddrive to look for .pp files that might contain their type definitions, Thus, performance is improved. Also removes the temporary fix for #4257 that caused #4397 (The code was too eager to look for a class in the topscope) Paired-With: Paul Berry <paul@puppetlabs.com> Signed-off-by: Jesse Wolfe <jes5199@gmail.com>
Diffstat (limited to 'lib/puppet/parser/ast')
-rw-r--r--lib/puppet/parser/ast/resource.rb6
-rw-r--r--lib/puppet/parser/ast/resource_reference.rb25
2 files changed, 26 insertions, 5 deletions
diff --git a/lib/puppet/parser/ast/resource.rb b/lib/puppet/parser/ast/resource.rb
index 1b063c984..9149b06c3 100644
--- a/lib/puppet/parser/ast/resource.rb
+++ b/lib/puppet/parser/ast/resource.rb
@@ -33,11 +33,11 @@ class Resource < AST::ResourceReference
# This is where our implicit iteration takes place; if someone
# passed an array as the name, then we act just like the called us
# many times.
+ resource_type = scope.find_resource_type(type)
resource_titles.flatten.collect { |resource_title|
exceptwrap :type => Puppet::ParseError do
-
- resource = Puppet::Parser::Resource.new(
- type, resource_title,
+ resource = Puppet::Parser::Resource.new(
+ resource_type.name, resource_title,
:parameters => paramobjects,
:file => self.file,
:line => self.line,
diff --git a/lib/puppet/parser/ast/resource_reference.rb b/lib/puppet/parser/ast/resource_reference.rb
index 5d8334335..5b1b0aa3a 100644
--- a/lib/puppet/parser/ast/resource_reference.rb
+++ b/lib/puppet/parser/ast/resource_reference.rb
@@ -7,8 +7,29 @@ class Puppet::Parser::AST::ResourceReference < Puppet::Parser::AST::Branch
# Evaluate our object, but just return a simple array of the type
# and name.
def evaluate(scope)
- titles = Array(title.safeevaluate(scope)).collect { |t| Puppet::Resource.new(type, t, :namespaces => scope.namespaces) }
- return(titles.length == 1 ? titles.pop : titles)
+ a_type = type
+ titles = Array(title.safeevaluate(scope))
+
+ case type.downcase
+ when "class"
+ # resolve the titles
+ titles = titles.collect do |a_title|
+ hostclass = scope.find_hostclass(a_title)
+ hostclass ? hostclass.name : a_title
+ end
+ when "node"
+ # no-op
+ else
+ # resolve the type
+ resource_type = scope.find_resource_type(type)
+ a_type = resource_type.name if resource_type
+ end
+
+ resources = titles.collect{ |a_title|
+ Puppet::Resource.new(a_type, a_title)
+ }
+
+ return(resources.length == 1 ? resources.pop : resources)
end
def to_s