diff options
author | Luke Kanies <luke@madstop.com> | 2008-12-11 12:31:01 -0600 |
---|---|---|
committer | Luke Kanies <luke@madstop.com> | 2008-12-18 11:10:23 -0600 |
commit | fae30756e48184dfc8238dcfe80b843f981b6070 (patch) | |
tree | 9de8d66a6cd9a73b720786a25843e837048ec628 | |
parent | 14c3c54ee1976e1c76acfe62554bb1786da6427b (diff) | |
download | puppet-fae30756e48184dfc8238dcfe80b843f981b6070.tar.gz puppet-fae30756e48184dfc8238dcfe80b843f981b6070.tar.xz puppet-fae30756e48184dfc8238dcfe80b843f981b6070.zip |
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 <luke@madstop.com>
-rw-r--r-- | lib/puppet/resource/reference.rb | 15 | ||||
-rwxr-xr-x | spec/unit/resource/reference.rb | 10 |
2 files changed, 20 insertions, 5 deletions
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 diff --git a/spec/unit/resource/reference.rb b/spec/unit/resource/reference.rb index 001aa0395..fa2d87bd5 100755 --- a/spec/unit/resource/reference.rb +++ b/spec/unit/resource/reference.rb @@ -47,6 +47,16 @@ describe Puppet::Resource::Reference do ref.title.should =="baz[yay]" end + it "should interpret the type as a reference and assign appropriately if the title is nil and the type contains square brackets" do + ref = Puppet::Resource::Reference.new("foo::bar[baz]") + ref.type.should == "Foo::Bar" + ref.title.should =="baz" + end + + it "should fail if the title is nil and the type is not a valid resource reference string" do + lambda { Puppet::Resource::Reference.new("foo") }.should raise_error(ArgumentError) + end + it "should be considered builtin if an existing resource type matches the type" do Puppet::Resource::Reference.new("file", "/f").should be_builtin_type end |