diff options
| author | Luke Kanies <luke@madstop.com> | 2007-11-28 15:20:52 -0600 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2007-11-28 15:20:52 -0600 |
| commit | 11ae473e3852adcc382a3efea2329586d2e4bcb3 (patch) | |
| tree | 7a7ff70f7d9f7bc9af0635c56690fb9fc810b9f5 /lib/puppet/parser/resource | |
| parent | 8127397e1efafc13975b79eabf7ce951c1e90114 (diff) | |
| download | puppet-11ae473e3852adcc382a3efea2329586d2e4bcb3.tar.gz puppet-11ae473e3852adcc382a3efea2329586d2e4bcb3.tar.xz puppet-11ae473e3852adcc382a3efea2329586d2e4bcb3.zip | |
Theoretically, this patch is to fix #917 (which it does), but
there were enough problems fixing it that I decided something
more drastic needed to be done.
This uses the new Puppet::ResourceReference class to canonize
what a resource reference looks like and how to retrieve resources
via their references. Specifically, it guarantees that resource types
are always capitalized, even when they include '::' in them.
While many files are modified in this commit, the majority of changes are
quite small, and most of the changes are fixing the tests to use
capitalized types.
As we look at consolidating some of our resource types, we could consolidate
the ResourceReference stuff at the same time, but at least the
Puppet::Parser::ResourceReference class subclasses the main Puppet::ResourceReference
class.
Diffstat (limited to 'lib/puppet/parser/resource')
| -rw-r--r-- | lib/puppet/parser/resource/reference.rb | 27 |
1 files changed, 9 insertions, 18 deletions
diff --git a/lib/puppet/parser/resource/reference.rb b/lib/puppet/parser/resource/reference.rb index 543ee7195..1dd816093 100644 --- a/lib/puppet/parser/resource/reference.rb +++ b/lib/puppet/parser/resource/reference.rb @@ -1,9 +1,11 @@ +require 'puppet/resource_reference' + # A reference to a resource. Mostly just the type and title. -class Puppet::Parser::Resource::Reference +class Puppet::Parser::Resource::Reference < Puppet::ResourceReference include Puppet::Util::MethodHelper include Puppet::Util::Errors - attr_accessor :type, :title, :builtin, :file, :line, :scope + attr_accessor :builtin, :file, :line, :scope # Are we a builtin type? def builtin? @@ -19,7 +21,7 @@ class Puppet::Parser::Resource::Reference end def builtintype - if t = Puppet::Type.type(self.type) and t.name != :component + if t = Puppet::Type.type(self.type.downcase) and t.name != :component t else nil @@ -30,28 +32,24 @@ class Puppet::Parser::Resource::Reference # definitions or nodes. def definedtype unless defined? @definedtype - type = self.type.to_s.downcase - name = self.title - case type - when "class": # look for host classes + case self.type + when "Class": # look for host classes if self.title == :main tmp = @scope.findclass("") else tmp = @scope.findclass(self.title) end - when "node": # look for node definitions + when "Node": # look for node definitions tmp = @scope.parser.nodes[self.title] else # normal definitions # We have to swap these variables around so the errors are right. - name = type - type = "type" tmp = @scope.finddefine(self.type) end if tmp @definedtype = tmp else - fail Puppet::ParseError, "Could not find resource %s '%s'" % [type, name] + fail Puppet::ParseError, "Could not find resource '%s'" % self end end @@ -67,13 +65,6 @@ class Puppet::Parser::Resource::Reference return [type.to_s,title.to_s] end - def to_s - unless defined? @namestring - @namestring = "%s[%s]" % [type.split("::").collect { |s| s.capitalize }.join("::"), title] - end - @namestring - end - def typeclass unless defined? @typeclass if tmp = builtintype || definedtype |
