module Puppet::Interface::ActionManager
This class is not actually public API, but the method {Puppet::Interface::ActionManager#action action} is public when used as part of the Faces DSL (i.e. from within a {Puppet::Interface.define define} block). @api public
Public Instance Methods
Defines a new action. This takes a block to build the action using the methods on {Puppet::Interface::ActionBuilder}. @param name [Symbol] The name that will be used to invoke the
action
@overload action(name, {|| block}) @return [void] @api public @dsl Faces
# File lib/puppet/interface/action_manager.rb 19 def action(name, &block) 20 @actions ||= {} 21 Puppet.warning _("Redefining action %{name} for %{self}") % { name: name, self: self } if action?(name) 22 23 action = Puppet::Interface::ActionBuilder.build(self, name, &block) 24 25 # REVISIT: (#18042) doesn't this mean we can't redefine the default action? -- josh 26 current = get_default_action if action.default 27 if current 28 raise "Actions #{current.name} and #{name} cannot both be default" 29 end 30 31 @actions[action.name] = action 32 end
@api private
# File lib/puppet/interface/action_manager.rb 96 def action?(name) 97 actions.include?(name.to_sym) 98 end
Returns the list of available actions for this face. @return [Array<Symbol>] The names of the actions for this face @api private
# File lib/puppet/interface/action_manager.rb 37 def actions 38 @actions ||= {} 39 result = @actions.keys 40 41 if self.is_a?(Class) and superclass.respond_to?(:actions) 42 result += superclass.actions 43 elsif self.class.respond_to?(:actions) 44 result += self.class.actions 45 end 46 # We need to uniq the result, because we duplicate actions when they are 47 # fetched to ensure that they have the correct bindings; they shadow the 48 # parent, and uniq implements that. --daniel 2011-06-01 49 (result - @deactivated_actions.to_a).uniq.sort 50 end
Deactivate a named action @return [Puppet::Interface::Action] @api public
# File lib/puppet/interface/action_manager.rb 90 def deactivate_action(name) 91 @deactivated_actions ||= Set.new 92 @deactivated_actions.add name.to_sym 93 end
Retrieves a named action @param name [Symbol] The name of the action @return [Puppet::Interface::Action] The action object @api private
# File lib/puppet/interface/action_manager.rb 56 def get_action(name) 57 @actions ||= {} 58 result = @actions[name.to_sym] 59 if result.nil? 60 if self.is_a?(Class) and superclass.respond_to?(:get_action) 61 found = superclass.get_action(name) 62 elsif self.class.respond_to?(:get_action) 63 found = self.class.get_action(name) 64 end 65 66 if found then 67 # This is not the nicest way to make action equivalent to the Ruby 68 # Method object, rather than UnboundMethod, but it will do for now, 69 # and we only have to make this change in *one* place. --daniel 2011-04-12 70 result = @actions[name.to_sym] = found.__dup_and_rebind_to(self) 71 end 72 end 73 return result 74 end
Retrieves the default action for the face @return [Puppet::Interface::Action] @api private
# File lib/puppet/interface/action_manager.rb 79 def get_default_action 80 default = actions.map {|x| get_action(x) }.select {|x| x.default } 81 if default.length > 1 82 raise "The actions #{default.map(&:name).join(", ")} cannot all be default" 83 end 84 default.first 85 end