[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, experimental, updated. debian/2.6.8-1-844-g7ec39d5
Daniel Pittman
daniel at puppetlabs.com
Tue May 10 08:16:44 UTC 2011
The following commit has been merged in the experimental branch:
commit 5258e06a39e11c2cc1951af9235605a29a155c36
Author: Daniel Pittman <daniel at puppetlabs.com>
Date: Mon Apr 18 14:41:01 2011 -0700
(#7013) Return bound methods for when_rendering hooks.
We can return a method bound to the current face instance when we access the
'when_rendering' hook, which allows us to directly call them. Make that
change, and add appropriate testing.
Reviewed-By: Max Martin <max at puppetlabs.com>
diff --git a/lib/puppet/interface/action.rb b/lib/puppet/interface/action.rb
index bdd42b1..53c40bc 100644
--- a/lib/puppet/interface/action.rb
+++ b/lib/puppet/interface/action.rb
@@ -40,7 +40,7 @@ class Puppet::Interface::Action
unless type.is_a? Symbol
raise ArgumentError, "The rendering format must be a symbol, not #{type.class.name}"
end
- @when_rendering[type]
+ @when_rendering[type].bind(@face)
end
def set_rendering_method_for(type, proc)
unless proc.is_a? Proc
diff --git a/spec/unit/interface/action_builder_spec.rb b/spec/unit/interface/action_builder_spec.rb
index 38a23a6..c122d3e 100755
--- a/spec/unit/interface/action_builder_spec.rb
+++ b/spec/unit/interface/action_builder_spec.rb
@@ -121,7 +121,7 @@ describe Puppet::Interface::ActionBuilder do
action = Puppet::Interface::ActionBuilder.build(face, :foo) do
when_rendering :json do |a| true end
end
- action.when_rendering(:json).should be_an_instance_of UnboundMethod
+ action.when_rendering(:json).should be_an_instance_of Method
end
it "should fail if you try to set the same rendering twice" do
@@ -138,8 +138,15 @@ describe Puppet::Interface::ActionBuilder do
when_rendering :json do |a| true end
when_rendering :yaml do |a| true end
end
- action.when_rendering(:json).should be_an_instance_of UnboundMethod
- action.when_rendering(:yaml).should be_an_instance_of UnboundMethod
+ action.when_rendering(:json).should be_an_instance_of Method
+ action.when_rendering(:yaml).should be_an_instance_of Method
+ end
+
+ it "should be bound to the face when called" do
+ action = Puppet::Interface::ActionBuilder.build(face, :foo) do
+ when_rendering :json do |a| self end
+ end
+ action.when_rendering(:json).call(true).should == face
end
end
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list