Module: Puppet::Interface::ActionManager

Included in:
Puppet::Interface, Puppet::Interface
Defined in:
lib/puppet/interface/action_manager.rb

Overview

This class is not actually public API, but the method action is public when used as part of the Faces DSL (i.e. from within a define block).

Instance Method Summary (collapse)

Instance Method Details

- action(name, {|| block})  DSL

This method returns an undefined value.

Defines a new action. This takes a block to build the action using the methods on Puppet::Interface::ActionBuilder.

Parameters:

  • name (Symbol)

    The name that will be used to invoke the action

DSL:

  • Faces



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/puppet/interface/action_manager.rb', line 21

def action(name, &block)
  @actions ||= {}
  Puppet.warning "Redefining action #{name} for #{self}" if action?(name)

  action = Puppet::Interface::ActionBuilder.build(self, name, &block)

  # REVISIT: (#18042) doesn't this mean we can't redefine the default action? -- josh
  if action.default and current = get_default_action
    raise "Actions #{current.name} and #{name} cannot both be default"
  end

  @actions[action.name] = action
end

- (Boolean) action?(name)  private

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


101
102
103
# File 'lib/puppet/interface/action_manager.rb', line 101

def action?(name)
  actions.include?(name.to_sym)
end

- (Array<Symbol>) actions  private

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the list of available actions for this face.

Returns:

  • (Array<Symbol>)

    The names of the actions for this face



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/puppet/interface/action_manager.rb', line 50

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

- (Puppet::Interface::Action) get_action(name)  private

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Retrieves a named action

Parameters:

  • name (Symbol)

    The name of the action

Returns:



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/puppet/interface/action_manager.rb', line 69

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

- (Puppet::Interface::Action) get_default_action  private

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Retrieves the default action for the face



92
93
94
95
96
97
98
# File 'lib/puppet/interface/action_manager.rb', line 92

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

- (Object) script(name, &block)  deprecated

Deprecated.

Defines an action without using ActionBuilder. The block given is the code that will be executed when the action is invoked.



39
40
41
42
43
44
45
# File 'lib/puppet/interface/action_manager.rb', line 39

def script(name, &block)
  @actions ||= {}
  Puppet.warning "Redefining action #{name} for #{self}" if action?(name)

  # REVISIT: (#18048) it's possible to create multiple default actions
  @actions[name] = Puppet::Interface::Action.new(self, name, :when_invoked => block)
end