From fae30756e48184dfc8238dcfe80b843f981b6070 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 11 Dec 2008 12:31:01 -0600 Subject: Simplifying the initialization interface for References You previously had to call new(nil, "Foo[bar]") if you just had the resource reference as a string. Now you can call new("Foo[bar]"), but the old behaviour works, too. Signed-off-by: Luke Kanies --- lib/puppet/resource/reference.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'lib/puppet') diff --git a/lib/puppet/resource/reference.rb b/lib/puppet/resource/reference.rb index d254254aa..d17b3e558 100644 --- a/lib/puppet/resource/reference.rb +++ b/lib/puppet/resource/reference.rb @@ -21,12 +21,17 @@ class Puppet::Resource::Reference builtin_type ? true : false end - def initialize(type, title) - # This will set @type if it looks like a resource reference. - self.title = title + def initialize(argtype, argtitle = nil) + if argtitle.nil? + self.title = argtype + raise ArgumentError, "No title provided and title '%s' is not a valid resource reference" % argtype if self.title == argtype + 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 = type if self.type.nil? + # Don't override whatever was done by setting the title. + self.type ||= argtype + end @builtin_type = nil end -- cgit