[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:47 UTC 2011
The following commit has been merged in the experimental branch:
commit 0fed94fbbad45388c1f9d2451d946681d80643f8
Author: Daniel Pittman <daniel at puppetlabs.com>
Date: Mon Apr 18 17:29:21 2011 -0700
(#7013) Wire up rendering hooks on the CLI.
We now find, and call, the appropriate rendering hooks on actions during the
rendering phase. This allows the user to intercept and replace the result
object that passes through the rest of the rendering system on the fly.
Example usage:
action :foo do
when_rendering :pson do |result|
{ :whatever => result[a],
:foobar => result[b],
}
end
end
Reviewed-By: Max Martin <max at puppetlabs.com>
diff --git a/lib/puppet/application/face_base.rb b/lib/puppet/application/face_base.rb
index 6b13e16..9da48af 100644
--- a/lib/puppet/application/face_base.rb
+++ b/lib/puppet/application/face_base.rb
@@ -35,9 +35,14 @@ class Puppet::Application::FaceBase < Puppet::Application
@exit_code || 0
end
- # Override this if you need custom rendering.
def render(result)
format = render_as || action.render_as || :for_humans
+
+ # Invoke the rendering hook supplied by the user, if appropriate.
+ if hook = action.when_rendering(format) then
+ result = hook.call(result)
+ end
+
if format == :for_humans then
render_for_humans(result)
else
diff --git a/lib/puppet/interface/action.rb b/lib/puppet/interface/action.rb
index d9ba4eb..b438950 100644
--- a/lib/puppet/interface/action.rb
+++ b/lib/puppet/interface/action.rb
@@ -39,7 +39,8 @@ 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].bind(@face)
+ return unless @when_rendering.has_key? type
+ return @when_rendering[type].bind(@face)
end
def set_rendering_method_for(type, proc)
unless proc.is_a? Proc
diff --git a/spec/unit/application/face_base_spec.rb b/spec/unit/application/face_base_spec.rb
index 6dfde43..5403608 100755
--- a/spec/unit/application/face_base_spec.rb
+++ b/spec/unit/application/face_base_spec.rb
@@ -264,5 +264,11 @@ text {"a"=>"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"c"=>"cccccccccccccccccccccccccccccccccccccccc"}
EOT
end
+
+ it "should invoke the action rendering hook while rendering" do
+ app.action.set_rendering_method_for(:for_humans, proc { |value| "bi-winning!" })
+ app.action.render_as = :for_humans
+ app.render("bi-polar?").should == "bi-winning!"
+ end
end
end
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list