summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-10-28 19:40:32 -0500
committerLuke Kanies <luke@madstop.com>2008-11-04 16:20:45 -0600
commit77d73e0230e466182c13a600a6c5cf8de67654e7 (patch)
tree9cf9cac701960daef302791a7174ebccebcfff55
parent05e1325891b2ab22088dcd34dd54e4afcbf59ddb (diff)
downloadpuppet-77d73e0230e466182c13a600a6c5cf8de67654e7.tar.gz
puppet-77d73e0230e466182c13a600a6c5cf8de67654e7.tar.xz
puppet-77d73e0230e466182c13a600a6c5cf8de67654e7.zip
Changing the meaning of the unused Puppet::Type#parameter method to return an instance
rather than a value. This parallels and largely obviates the 'property' method. Signed-off-by: Luke Kanies <luke@madstop.com>
-rw-r--r--lib/puppet/type.rb10
-rwxr-xr-xspec/unit/type.rb17
2 files changed, 20 insertions, 7 deletions
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 85f72f79a..da274df88 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -601,10 +601,7 @@ class Type
# return the value of a parameter
def parameter(name)
- unless name.is_a? Symbol
- name = name.intern
- end
- return @parameters[name].value
+ @parameters[name.to_sym]
end
# Is the named property defined?
@@ -615,8 +612,9 @@ class Type
return @parameters.include?(name)
end
- # return an actual type by name; to return the value, use 'inst[name]'
- # FIXME this method should go away
+ # Return an actual property instance by name; to return the value, use 'resource[param]'
+ # LAK:NOTE(20081028) Since the 'parameter' method is now a superset of this method,
+ # this one should probably go away at some point.
def property(name)
if obj = @parameters[symbolize(name)] and obj.is_a?(Puppet::Property)
return obj
diff --git a/spec/unit/type.rb b/spec/unit/type.rb
index 4c0cb5077..b07f781ed 100755
--- a/spec/unit/type.rb
+++ b/spec/unit/type.rb
@@ -3,7 +3,22 @@
require File.dirname(__FILE__) + '/../spec_helper'
describe Puppet::Type do
- describe "when retrieving current properties" do
+ it "should be able to retrieve a property by name" do
+ resource = Puppet::Type.type(:mount).create(:name => "foo", :fstype => "bar", :pass => 1, :ensure => :present)
+ resource.property(:fstype).must be_instance_of(Puppet::Type.type(:mount).attrclass(:fstype))
+ end
+
+ it "should be able to retrieve a parameter by name" do
+ resource = Puppet::Type.type(:mount).create(:name => "foo", :fstype => "bar", :pass => 1, :ensure => :present)
+ resource.parameter(:name).must be_instance_of(Puppet::Type.type(:mount).attrclass(:name))
+ end
+
+ it "should be able to retrieve a property by name using the :parameter method" do
+ resource = Puppet::Type.type(:mount).create(:name => "foo", :fstype => "bar", :pass => 1, :ensure => :present)
+ resource.parameter(:fstype).must be_instance_of(Puppet::Type.type(:mount).attrclass(:fstype))
+ end
+
+ describe "when retrieving current property values" do
# Use 'mount' as an example, because it doesn't override 'retrieve'
before do
@resource = Puppet::Type.type(:mount).create(:name => "foo", :fstype => "bar", :pass => 1, :ensure => :present)