diff options
| author | Luke Kanies <luke@madstop.com> | 2009-08-03 16:07:30 -0700 |
|---|---|---|
| committer | Luke Kanies <luke@madstop.com> | 2009-08-03 16:07:30 -0700 |
| commit | 1410bed5a40fe945f68b805474b7c022403c3d47 (patch) | |
| tree | 8064cd32c3cf91e3546e1c841145bf3dea43457f | |
| parent | 3ab3a5c7ab9f01b78e0e6d27fce6377de0cfaeec (diff) | |
Adding metadata delegation from param to resource
This is for file, line, version, and tags, with the
parameter name added to the tags.
This is mostly so logs generated by the parameters
work better.
Signed-off-by: Luke Kanies <luke@madstop.com>
| -rw-r--r-- | lib/puppet/parameter.rb | 19 | ||||
| -rw-r--r-- | lib/puppet/property.rb | 13 | ||||
| -rwxr-xr-x | spec/unit/parameter.rb | 16 | ||||
| -rwxr-xr-x | spec/unit/property.rb | 5 |
4 files changed, 34 insertions, 19 deletions
diff --git a/lib/puppet/parameter.rb b/lib/puppet/parameter.rb index c594ed5f4..f4086671d 100644 --- a/lib/puppet/parameter.rb +++ b/lib/puppet/parameter.rb @@ -359,6 +359,12 @@ class Puppet::Parameter # LAK 2007-05-09: Keep the @parent around for backward compatibility. attr_accessor :parent + [:line, :file, :version].each do |param| + define_method(param) do + resource.send(param) + end + end + def devfail(msg) self.fail(Puppet::DevError, msg) end @@ -513,6 +519,19 @@ class Puppet::Parameter @resource.provider end + # The properties need to return tags so that logs correctly collect them. + def tags + unless defined? @tags + @tags = [] + # This might not be true in testing + if @resource.respond_to? :tags + @tags = @resource.tags + end + @tags << self.name.to_s + end + @tags + end + def to_s s = "Parameter(%s)" % self.name end diff --git a/lib/puppet/property.rb b/lib/puppet/property.rb index 487028ed2..1ed323f16 100644 --- a/lib/puppet/property.rb +++ b/lib/puppet/property.rb @@ -370,19 +370,6 @@ class Puppet::Property < Puppet::Parameter end end - # The properties need to return tags so that logs correctly collect them. - def tags - unless defined? @tags - @tags = [] - # This might not be true in testing - if @resource.respond_to? :tags - @tags = @resource.tags - end - @tags << self.name.to_s - end - @tags - end - def to_s return "%s(%s)" % [@resource.name,self.name] end diff --git a/spec/unit/parameter.rb b/spec/unit/parameter.rb index 42d3103bd..0548346b3 100755 --- a/spec/unit/parameter.rb +++ b/spec/unit/parameter.rb @@ -6,7 +6,9 @@ require 'puppet/parameter' describe Puppet::Parameter do before do - @class = Class.new(Puppet::Parameter) + @class = Class.new(Puppet::Parameter) do + @name = :foo + end @class.initvars @resource = mock 'resource' @resource.stub_everything @@ -30,6 +32,18 @@ describe Puppet::Parameter do @parameter.expirer.should equal(catalog) end + [:line, :file, :version].each do |data| + it "should return its resource's #{data} as its #{data}" do + @resource.expects(data).returns "foo" + @parameter.send(data).should == "foo" + end + end + + it "should return the resource's tags plus its name as its tags" do + @resource.expects(:tags).returns %w{one two} + @parameter.tags.should == %w{one two foo} + end + describe "when returning the value" do it "should return nil if no value is set" do @parameter.value.should be_nil diff --git a/spec/unit/property.rb b/spec/unit/property.rb index f09549ddc..07ab9c319 100755 --- a/spec/unit/property.rb +++ b/spec/unit/property.rb @@ -30,11 +30,6 @@ describe Puppet::Property do @class.value_option(:foo, :event).should == :whatever end - it "should return the resource's tags plus its name as its tags" do - @resource.expects(:tags).returns %w{one two} - @property.tags.should == %w{one two foo} - end - it "should be able to specify required features" do @class.should respond_to(:required_features=) end |
