summaryrefslogtreecommitdiffstats
path: root/lib/puppet/resource/reference.rb
diff options
context:
space:
mode:
authorLuke Kanies <luke@reductivelabs.com>2009-12-21 16:23:44 -0800
committerLuke Kanies <luke@reductivelabs.com>2009-12-21 16:23:44 -0800
commit740fd6b301af89ab3aad89bca183ad1fcdc24ac4 (patch)
treef34617a229509c373d28d67abb453e7ae2136c39 /lib/puppet/resource/reference.rb
parent8971d8beae2c409f9052f27c3f80ad3bdfff4de2 (diff)
parent4a06379f8770c164e42bcc410d874076c6e95f24 (diff)
downloadpuppet-740fd6b301af89ab3aad89bca183ad1fcdc24ac4.tar.gz
puppet-740fd6b301af89ab3aad89bca183ad1fcdc24ac4.tar.xz
puppet-740fd6b301af89ab3aad89bca183ad1fcdc24ac4.zip
Merge branch '0.25.x'
Conflicts: lib/puppet/agent.rb lib/puppet/application/puppetd.rb lib/puppet/parser/ast/leaf.rb lib/puppet/util/rdoc/parser.rb
Diffstat (limited to 'lib/puppet/resource/reference.rb')
-rw-r--r--lib/puppet/resource/reference.rb34
1 files changed, 9 insertions, 25 deletions
diff --git a/lib/puppet/resource/reference.rb b/lib/puppet/resource/reference.rb
index c205f1038..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 =~ /^([^\[\]]+)\[(.+)\]$/
- 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.