summaryrefslogtreecommitdiffstats
path: root/lib/puppet/resource
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2009-10-26 23:09:07 -0700
committerJames Turnbull <james@lovedthanlost.net>2009-11-14 09:08:53 +1100
commitca56aa7e5849a5489e8d38e29b25ea934caafcd7 (patch)
treed144a73d0fcae991281f688284c09283510f965d /lib/puppet/resource
parentadc0a4ed939a717e8735485d493bde28ceab5ac0 (diff)
downloadpuppet-ca56aa7e5849a5489e8d38e29b25ea934caafcd7.tar.gz
puppet-ca56aa7e5849a5489e8d38e29b25ea934caafcd7.tar.xz
puppet-ca56aa7e5849a5489e8d38e29b25ea934caafcd7.zip
Least kludgy patch for #2675
This makes parameters responsible for the canonicalization of their values and provides a default (passthrough) implementation. It changes munge to pre- canonicalize the value and resource references to builtin types to canonicalize titles (which map to resorce namevars) with the corresponding parameter's classes's canonicalization. It adds a canonicalization routine to file paths that normalizes the behaviour (trailing slashes are ignored) and DRYs up the related code. Signed-off-by: Markus Roberts <Markus@reality.com>
Diffstat (limited to 'lib/puppet/resource')
-rw-r--r--lib/puppet/resource/catalog.rb2
-rw-r--r--lib/puppet/resource/reference.rb34
2 files changed, 10 insertions, 26 deletions
diff --git a/lib/puppet/resource/catalog.rb b/lib/puppet/resource/catalog.rb
index 09c099418..f21c820a0 100644
--- a/lib/puppet/resource/catalog.rb
+++ b/lib/puppet/resource/catalog.rb
@@ -78,7 +78,7 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
@resource_table[ref] = resource
# If the name and title differ, set up an alias
- #self.alias(resource, resource.name) if resource.respond_to?(:name) and resource.respond_to?(:title) and resource.name != resource.title
+
if resource.respond_to?(:name) and resource.respond_to?(:title) and resource.name != resource.title
self.alias(resource, resource.name) if resource.isomorphic?
end
diff --git a/lib/puppet/resource/reference.rb b/lib/puppet/resource/reference.rb
index 37522ffe9..dce4449de 100644
--- a/lib/puppet/resource/reference.rb
+++ b/lib/puppet/resource/reference.rb
@@ -20,24 +20,12 @@ class Puppet::Resource::Reference
end
def initialize(argtype, argtitle = nil)
- if argtitle.nil?
- if argtype.is_a?(Puppet::Type)
- self.title = argtype.title
- self.type = argtype.class.name
- else
- self.title = argtype
- if self.title == argtype
- raise ArgumentError, "No title provided and title '%s' is not a valid resource reference" % argtype.inspect
- end
- end
- else
- # This will set @type if it looks like a resource reference.
- self.title = argtitle
-
- # Don't override whatever was done by setting the title.
- self.type ||= argtype
- end
-
+ self.type,self.title =
+ if (argtitle || argtype) =~ /^([^\[\]]+)\[(.+)\]$/m then [ $1, $2 ]
+ elsif argtitle then [ argtype, argtitle ]
+ elsif argtype.is_a?(Puppet::Type) then [ argtype.class.name, argtype.title ]
+ else raise ArgumentError, "No title provided and #{argtype.inspect} is not a valid resource reference"
+ end
@builtin_type = nil
end
@@ -47,15 +35,11 @@ class Puppet::Resource::Reference
return nil
end
- # If the title has square brackets, treat it like a reference and
- # set things appropriately; else, just set it.
def title=(value)
- if value =~ /^([^\[\]]+)\[(.+)\]$/m
- self.type = $1
- @title = $2
- else
- @title = value
+ if @type and klass = Puppet::Type.type(@type.to_s.downcase)
+ value = klass.canonicalize_ref(value)
end
+ @title = value
end
# Canonize the type so we know it's always consistent.