[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:19:24 UTC 2011
The following commit has been merged in the experimental branch:
commit 18b3584e16515cfc45aeaa8d0913de8e8bcb3e95
Author: Daniel Pittman <daniel at puppetlabs.com>
Date: Mon May 2 16:27:28 2011 -0700
(#7329) Consistent naming for rendering formats and hooks.
We refer to rendering formats pretty consistently as `json`, `yaml`, `s`, and
so forth; unqualified names.
On the other hand, we refer to the rendering hooks *mostly* as `to_*`, except
the `:for_humans` and `:json` formats. Which is kind of confusing because of
the internal inconsistency, and because it doesn't match the public name.
Fix the code to resolve both, so the `to_*` format still works, but we mostly
expect to use the `*` version, to match public expectation.
diff --git a/lib/puppet/interface/action.rb b/lib/puppet/interface/action.rb
index d4cf23f..622371a 100644
--- a/lib/puppet/interface/action.rb
+++ b/lib/puppet/interface/action.rb
@@ -76,8 +76,15 @@ class Puppet::Interface::Action
unless type.is_a? Symbol
raise ArgumentError, "The rendering format must be a symbol, not #{type.class.name}"
end
- return unless @when_rendering.has_key? type
- return @when_rendering[type].bind(@face)
+ # Do we have a rendering hook for this name?
+ return @when_rendering[type].bind(@face) if @when_rendering.has_key? type
+
+ # How about by another name?
+ alt = type.to_s.sub(/^to_/, '').to_sym
+ return @when_rendering[alt].bind(@face) if @when_rendering.has_key? alt
+
+ # Guess not, nothing to run.
+ return nil
end
def set_rendering_method_for(type, proc)
unless proc.is_a? Proc
diff --git a/spec/lib/puppet/face/basetest.rb b/spec/lib/puppet/face/basetest.rb
index 41a4ef3..9398f5b 100755
--- a/spec/lib/puppet/face/basetest.rb
+++ b/spec/lib/puppet/face/basetest.rb
@@ -32,4 +32,10 @@ Puppet::Face.define(:basetest, '0.0.1') do
summary "just raises an exception"
when_invoked do |options| raise ArgumentError, "your failure" end
end
+
+ action :with_s_rendering_hook do
+ summary "has a rendering hook for 's'"
+ when_invoked do |options| "this is not the hook you are looking for" end
+ when_rendering :s do |value| "you invoked the 's' rendering hook" end
+ end
end
diff --git a/spec/unit/application/face_base_spec.rb b/spec/unit/application/face_base_spec.rb
index d8c9701..133e6b2 100755
--- a/spec/unit/application/face_base_spec.rb
+++ b/spec/unit/application/face_base_spec.rb
@@ -319,5 +319,13 @@ EOT
expect { app.run }.to exit_with 0
}.to have_printed(/--- 3/)
end
+
+ it "should invoke when_rendering hook 's' when asked to render-as 's'" do
+ app.command_line.stubs(:args).returns %w{with_s_rendering_hook --render-as s}
+ app.action = app.face.get_action(:with_s_rendering_hook)
+ expect {
+ expect { app.run }.to exit_with 0
+ }.to have_printed(/you invoked the 's' rendering hook/)
+ end
end
end
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list