summaryrefslogtreecommitdiffstats
path: root/lib/puppet/parser/resource
diff options
context:
space:
mode:
authorLuke Kanies <luke@reductivelabs.com>2010-01-29 20:57:21 -0600
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commit7089446697ad550c22012bc2b5572030727d67e1 (patch)
tree40d160f11839fe6e20311186ded4e621d23e1242 /lib/puppet/parser/resource
parent4871c909cd28c82b64d0b62d8a27e62737d8733d (diff)
downloadpuppet-7089446697ad550c22012bc2b5572030727d67e1.tar.gz
puppet-7089446697ad550c22012bc2b5572030727d67e1.tar.xz
puppet-7089446697ad550c22012bc2b5572030727d67e1.zip
Removing Resource::Reference classes
This commit is hopefully less messy than it first appears, but it's certainly cross-cutting. The reason for all of this is that we previously only looked up builtin resource types from outside the parser, but now that the defined resource types are available globally via environments, we can push that lookup code to Resource. Once we do that, however, we have to have environment and namespace information in every resource. Here I remove the Resource::Reference classes (except the AST class), and use Resource instances instead. I did this because the shared code between the two classes got incredibly complicated, such that they should have had a hierarchical relationship disallowed by their constants. This complexity convinced me just to get rid of References entirely. I also make Puppet::Parser::Resource a subclass of Puppet::Resource. There are still broken tests in test/, but this was a big enough commit I wanted to get it in. Signed-off-by: Luke Kanies <luke@reductivelabs.com>
Diffstat (limited to 'lib/puppet/parser/resource')
-rw-r--r--lib/puppet/parser/resource/reference.rb103
1 files changed, 0 insertions, 103 deletions
diff --git a/lib/puppet/parser/resource/reference.rb b/lib/puppet/parser/resource/reference.rb
deleted file mode 100644
index ac1c79aef..000000000
--- a/lib/puppet/parser/resource/reference.rb
+++ /dev/null
@@ -1,103 +0,0 @@
-# A reference to a resource. Mostly just the type and title.
-require 'puppet/resource/reference'
-require 'puppet/file_collection/lookup'
-require 'puppet/parser/yaml_trimmer'
-
-require 'puppet/resource/type_collection_helper'
-
-# A reference to a resource. Mostly just the type and title.
-class Puppet::Parser::Resource::Reference < Puppet::Resource::Reference
- include Puppet::Parser::YamlTrimmer
- include Puppet::FileCollection::Lookup
- include Puppet::Util::MethodHelper
- include Puppet::Util::Errors
- include Puppet::Resource::TypeCollectionHelper
-
- attr_accessor :builtin, :file, :line, :scope
-
- # Are we a builtin type?
- def builtin?
- unless defined? @builtin
- if builtintype()
- @builtin = true
- else
- @builtin = false
- end
- end
-
- @builtin
- end
-
- def builtintype
- if t = Puppet::Type.type(self.type.downcase) and t.name != :component
- t
- else
- nil
- end
- end
-
- # Return the defined type for our obj. This can return classes,
- # definitions or nodes.
- def definedtype
- unless defined? @definedtype
- case self.type
- when "Class" # look for host classes
- name = self.title == :main ? "" : self.title
- unless tmp = known_resource_types.find_hostclass("", name)
- fail Puppet::ParseError, "Could not find '#{title}' class"
- end
- when "Node" # look for node definitions
- unless tmp = known_resource_types.node(self.title)
- fail Puppet::ParseError, "Could not find node '%s'" % self.title
- end
- else # normal definitions
- # The resource type is capitalized, so we have to downcase. Really,
- # we should have a better interface for finding these, but eh.
- tmp = known_resource_types.definition(self.type.downcase)
- end
-
- if tmp
- @definedtype = tmp
- else
- fail Puppet::ParseError, "Could not find resource type '%s'" % self.type
- end
- end
-
- @definedtype
- end
-
- def environment
- scope.environment
- end
-
- def initialize(hash)
- set_options(hash)
- requiredopts(:type, :title)
- end
-
- def skip_for_yaml
- %w{@typeclass @definedtype}
- end
-
- def to_ref
- # We have to return different cases to provide backward compatibility
- # from 0.24.x to 0.23.x.
- if builtin?
- return [type.to_s.downcase, title.to_s]
- else
- return [type.to_s, title.to_s]
- end
- end
-
- def typeclass
- unless defined? @typeclass
- if tmp = builtintype || definedtype
- @typeclass = tmp
- else
- fail Puppet::ParseError, "Could not find type %s" % self.type
- end
- end
-
- @typeclass
- end
-end