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

action(name, &block) click to toggle source

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
18 def action(name, &block)
19   @actions ||= {}
20   Puppet.warning _("Redefining action %{name} for %{self}") % { name: name, self: self } if action?(name)
21 
22   action = Puppet::Interface::ActionBuilder.build(self, name, &block)
23 
24   # REVISIT: (#18042) doesn't this mean we can't redefine the default action? -- josh
25   current = get_default_action if action.default
26   if current
27     raise "Actions #{current.name} and #{name} cannot both be default"
28   end
29 
30   @actions[action.name] = action
31 end
action?(name) click to toggle source

@api private

   # File lib/puppet/interface/action_manager.rb
95 def action?(name)
96   actions.include?(name.to_sym)
97 end
actions() click to toggle source

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
36 def actions
37   @actions ||= {}
38   result = @actions.keys
39 
40   if self.is_a?(Class) and superclass.respond_to?(:actions)
41     result += superclass.actions
42   elsif self.class.respond_to?(:actions)
43     result += self.class.actions
44   end
45   # We need to uniq the result, because we duplicate actions when they are
46   # fetched to ensure that they have the correct bindings; they shadow the
47   # parent, and uniq implements that. --daniel 2011-06-01
48   (result - @deactivated_actions.to_a).uniq.sort
49 end
deactivate_action(name) click to toggle source

Deactivate a named action @return [Puppet::Interface::Action] @api public

   # File lib/puppet/interface/action_manager.rb
89 def deactivate_action(name)
90   @deactivated_actions ||= Set.new
91   @deactivated_actions.add name.to_sym
92 end
get_action(name) click to toggle source

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
55 def get_action(name)
56   @actions ||= {}
57   result = @actions[name.to_sym]
58   if result.nil?
59     if self.is_a?(Class) and superclass.respond_to?(:get_action)
60       found = superclass.get_action(name)
61     elsif self.class.respond_to?(:get_action)
62       found = self.class.get_action(name)
63     end
64 
65     if found then
66       # This is not the nicest way to make action equivalent to the Ruby
67       # Method object, rather than UnboundMethod, but it will do for now,
68       # and we only have to make this change in *one* place. --daniel 2011-04-12
69       result = @actions[name.to_sym] = found.__dup_and_rebind_to(self)
70     end
71   end
72   return result
73 end
get_default_action() click to toggle source

Retrieves the default action for the face @return [Puppet::Interface::Action] @api private

   # File lib/puppet/interface/action_manager.rb
78 def get_default_action
79   default = actions.map {|x| get_action(x) }.select {|x| x.default }
80   if default.length > 1
81     raise "The actions #{default.map(&:name).join(", ")} cannot all be default"
82   end
83   default.first
84 end