summaryrefslogtreecommitdiffstats
path: root/lib/puppet/resource.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@reductivelabs.com>2010-01-30 23:36:32 -0600
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commit9c867e6d79dcc56cd34683c9a339dc729ad2d291 (patch)
tree27ee2a51648d11891a5168db1e63e064244eeef5 /lib/puppet/resource.rb
parent274d1c5e78250640b8d2c40201ca2586c0088f32 (diff)
downloadpuppet-9c867e6d79dcc56cd34683c9a339dc729ad2d291.tar.gz
puppet-9c867e6d79dcc56cd34683c9a339dc729ad2d291.tar.xz
puppet-9c867e6d79dcc56cd34683c9a339dc729ad2d291.zip
Fixing most of the broken tests in test/
This involves a bit of refactoring in the rest of the code to make it all work, but most of the changes are fixing or removing old tests. Signed-off-by: Luke Kanies <luke@reductivelabs.com>
Diffstat (limited to 'lib/puppet/resource.rb')
-rw-r--r--lib/puppet/resource.rb52
1 files changed, 39 insertions, 13 deletions
diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb
index ec1fd2eae..630e8a823 100644
--- a/lib/puppet/resource.rb
+++ b/lib/puppet/resource.rb
@@ -13,7 +13,8 @@ class Puppet::Resource
extend Puppet::Util::Pson
include Enumerable
attr_accessor :file, :line, :catalog, :exported, :virtual, :validate_parameters
- attr_reader :type, :title, :namespaces
+ attr_reader :title, :namespaces
+ attr_writer :relative_type
require 'puppet/indirector'
extend Puppet::Indirector
@@ -145,8 +146,6 @@ class Puppet::Resource
# Create our resource.
def initialize(type, title = nil, attributes = {})
- self.type, self.title = extract_type_and_title(type, title)
-
@parameters = {}
@namespaces = [""]
@@ -159,6 +158,13 @@ class Puppet::Resource
send(attr.to_s + "=", value)
end
+ # We do namespaces first, and use tmp variables, so our title
+ # canonicalization works (i.e., namespaces are set and resource
+ # types can be looked up)
+ tmp_type, tmp_title = extract_type_and_title(type, title)
+ self.type = tmp_type
+ self.title = tmp_title
+
tag(self.type)
tag(self.title) if valid_tag?(self.title)
end
@@ -174,14 +180,19 @@ class Puppet::Resource
end
def title=(value)
- if @type and klass = Puppet::Type.type(@type.to_s.downcase)
+ if klass = resource_type and klass.respond_to?(:canonicalize_ref)
value = klass.canonicalize_ref(value)
end
@title = value
end
+ # Canonize the type so we know it's always consistent.
+ def relative_type
+ munge_type_name(@relative_type)
+ end
+
def resource_type
- case type.to_s.downcase
+ case relative_type.to_s.downcase
when "class"; find_hostclass
when "node"; find_node
else
@@ -290,13 +301,18 @@ class Puppet::Resource
self
end
- # Canonize the type so we know it's always consistent.
- def type=(value)
- if value.nil? or value.to_s.downcase == "component"
- @type = "Class"
+ def type
+ munge_type_name(if r = resource_type
+ resource_type.name
else
- @type = value.to_s.split("::").collect { |s| s.capitalize }.join("::")
- end
+ relative_type
+ end)
+ end
+
+ # Only allow people to set the relative type,
+ # so we force it to be looked up each time.
+ def type=(value)
+ @relative_type = value
end
def valid_parameter?(name)
@@ -319,11 +335,11 @@ class Puppet::Resource
end
def find_builtin_resource_type
- Puppet::Type.type(type.to_s.downcase.to_sym)
+ Puppet::Type.type(relative_type.to_s.downcase.to_sym)
end
def find_defined_resource_type
- known_resource_types.find_definition(namespaces, type.to_s.downcase)
+ known_resource_types.find_definition(namespaces, relative_type.to_s.downcase)
end
# Produce a canonical method name.
@@ -369,4 +385,14 @@ class Puppet::Resource
else raise ArgumentError, "No title provided and #{argtype.inspect} is not a valid resource reference"
end
end
+
+ def munge_type_name(value)
+ return :main if value == ""
+
+ if value.nil? or value.to_s.downcase == "component"
+ "Class"
+ else
+ value.to_s.split("::").collect { |s| s.capitalize }.join("::")
+ end
+ end
end