diff options
| author | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-07 17:58:07 -0700 |
|---|---|---|
| committer | Daniel Pittman <daniel@puppetlabs.com> | 2011-04-07 18:01:33 -0700 |
| commit | 0f24db1c3fd0aa6601ba032aedbe25be36010954 (patch) | |
| tree | 08af1180a4468145af66ee429ce3a80236e08fff /lib/puppet/interface/action_manager.rb | |
| parent | af792351a62399f8bbeba0d2425f2b88eabb3dff (diff) | |
| parent | 79f4774182046d2fdf392c1eb27ee78505659199 (diff) | |
| download | puppet-0f24db1c3fd0aa6601ba032aedbe25be36010954.tar.gz puppet-0f24db1c3fd0aa6601ba032aedbe25be36010954.tar.xz puppet-0f24db1c3fd0aa6601ba032aedbe25be36010954.zip | |
Merge puppet-interfaces into puppet.
This joins the two repositories, including full history, into a single run, as
well as landing the interfaces work on the next branch ready for release.
Diffstat (limited to 'lib/puppet/interface/action_manager.rb')
| -rw-r--r-- | lib/puppet/interface/action_manager.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/puppet/interface/action_manager.rb b/lib/puppet/interface/action_manager.rb new file mode 100644 index 000000000..bb0e5bf57 --- /dev/null +++ b/lib/puppet/interface/action_manager.rb @@ -0,0 +1,49 @@ +require 'puppet/interface/action_builder' + +module Puppet::Interface::ActionManager + # Declare that this app can take a specific action, and provide + # the code to do so. + def action(name, &block) + @actions ||= {} + raise "Action #{name} already defined for #{self}" if action?(name) + action = Puppet::Interface::ActionBuilder.build(self, name, &block) + @actions[action.name] = action + end + + # This is the short-form of an action definition; it doesn't use the + # builder, just creates the action directly from the block. + def script(name, &block) + @actions ||= {} + raise "Action #{name} already defined for #{self}" if action?(name) + @actions[name] = Puppet::Interface::Action.new(self, name, :when_invoked => block) + end + + def actions + @actions ||= {} + result = @actions.keys + + if self.is_a?(Class) and superclass.respond_to?(:actions) + result += superclass.actions + elsif self.class.respond_to?(:actions) + result += self.class.actions + end + result.sort + end + + def get_action(name) + @actions ||= {} + result = @actions[name.to_sym] + if result.nil? + if self.is_a?(Class) and superclass.respond_to?(:get_action) + result = superclass.get_action(name) + elsif self.class.respond_to?(:get_action) + result = self.class.get_action(name) + end + end + return result + end + + def action?(name) + actions.include?(name.to_sym) + end +end |
