Module: Puppet::Interface::ActionManager
- Included in:
- Puppet::Interface, Puppet::Interface
- Defined in:
- lib/vendor/puppet/interface/action_manager.rb
Instance Method Summary collapse
-
#action(name, &block) ⇒ Object
Declare that this app can take a specific action, and provide the code to do so.
- #action?(name) ⇒ Boolean
- #actions ⇒ Object
- #get_action(name) ⇒ Object
- #get_default_action ⇒ Object
-
#script(name, &block) ⇒ Object
This is the short-form of an action definition; it doesn’t use the builder, just creates the action directly from the block.
Instance Method Details
#action(name, &block) ⇒ Object
Declare that this app can take a specific action, and provide the code to do so.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/vendor/puppet/interface/action_manager.rb', line 7 def action(name, &block) @actions ||= {} raise "Action #{name} already defined for #{self}" if action?(name) action = Puppet::Interface::ActionBuilder.build(self, name, &block) if action.default and current = get_default_action raise "Actions #{current.name} and #{name} cannot both be default" end @actions[action.name] = action end |
#action?(name) ⇒ Boolean
71 72 73 |
# File 'lib/vendor/puppet/interface/action_manager.rb', line 71 def action?(name) actions.include?(name.to_sym) end |
#actions ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/vendor/puppet/interface/action_manager.rb', line 28 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 # We need to uniq the result, because we duplicate actions when they are # fetched to ensure that they have the correct bindings; they shadow the # parent, and uniq implements that. --daniel 2011-06-01 result.uniq.sort end |
#get_action(name) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/vendor/puppet/interface/action_manager.rb', line 43 def get_action(name) @actions ||= {} result = @actions[name.to_sym] if result.nil? if self.is_a?(Class) and superclass.respond_to?(:get_action) found = superclass.get_action(name) elsif self.class.respond_to?(:get_action) found = self.class.get_action(name) end if found then # This is not the nicest way to make action equivalent to the Ruby # Method object, rather than UnboundMethod, but it will do for now, # and we only have to make this change in *one* place. --daniel 2011-04-12 result = @actions[name.to_sym] = found.__dup_and_rebind_to(self) end end return result end |
#get_default_action ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/vendor/puppet/interface/action_manager.rb', line 63 def get_default_action default = actions.map {|x| get_action(x) }.select {|x| x.default } if default.length > 1 raise "The actions #{default.map(&:name).join(", ")} cannot all be default" end default.first end |
#script(name, &block) ⇒ Object
This is the short-form of an action definition; it doesn’t use the builder, just creates the action directly from the block.
22 23 24 25 26 |
# File 'lib/vendor/puppet/interface/action_manager.rb', line 22 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 |