summaryrefslogtreecommitdiffstats
path: root/lib/puppet/interface.rb
diff options
context:
space:
mode:
authorDaniel Pittman <daniel@puppetlabs.com>2011-04-15 15:34:24 -0700
committerDaniel Pittman <daniel@puppetlabs.com>2011-04-15 15:34:24 -0700
commit0d0318f9f0eadff7f9934d3d02a7081bba05164c (patch)
treedfc6b3d976ac5acf822846c272bdb4451b10aeba /lib/puppet/interface.rb
parent3fe01a34e8397c30a00e7d47b4ac0b93198e1fcf (diff)
parentd80500f42367fa30a00dc12ef4b32b55b350b1ca (diff)
downloadpuppet-0d0318f9f0eadff7f9934d3d02a7081bba05164c.tar.gz
puppet-0d0318f9f0eadff7f9934d3d02a7081bba05164c.tar.xz
puppet-0d0318f9f0eadff7f9934d3d02a7081bba05164c.zip
Merge branch 'feature/2.7.x/6978-face-and-action-options-should-have-hooks-for-various-actions' into 2.7.x
Diffstat (limited to 'lib/puppet/interface.rb')
-rw-r--r--lib/puppet/interface.rb39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/puppet/interface.rb b/lib/puppet/interface.rb
index 6570ebe46..5e9355061 100644
--- a/lib/puppet/interface.rb
+++ b/lib/puppet/interface.rb
@@ -117,4 +117,43 @@ class Puppet::Interface
def to_s
"Puppet::Face[#{name.inspect}, #{version.inspect}]"
end
+
+ ########################################################################
+ # Action decoration, whee! You are not expected to care about this code,
+ # which exists to support face building and construction. I marked these
+ # private because the implementation is crude and ugly, and I don't yet know
+ # enough to work out how to make it clean.
+ #
+ # Once we have established that these methods will likely change radically,
+ # to be unrecognizable in the final outcome. At which point we will throw
+ # all this away, replace it with something nice, and work out if we should
+ # be making this visible to the outside world... --daniel 2011-04-14
+ private
+ def __invoke_decorations(type, action, passed_args = [], passed_options = {})
+ [:before, :after].member?(type) or fail "unknown decoration type #{type}"
+
+ # Collect the decoration methods matching our pass.
+ methods = action.options.select do |name|
+ passed_options.has_key? name
+ end.map do |name|
+ action.get_option(name).__decoration_name(type)
+ end
+
+ methods.each do |hook|
+ begin
+ respond_to? hook and self.__send__(hook, action, passed_args, passed_options)
+ rescue => e
+ Puppet.warning("invoking #{action} #{type} hook: #{e}")
+ end
+ end
+ end
+
+ def __decorate(type, name, proc)
+ meta_def(name, &proc)
+ method(name).unbind
+ end
+ def self.__decorate(type, name, proc)
+ define_method(name, proc)
+ instance_method(name)
+ end
end