Class: MotherBrain::Cli::SubCommand::Component Private

Inherits:
Base
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/mb/cli/sub_command/component.rb

Overview

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

A set of component tasks collected into a SubCommand to be registered with the CliGateway. This class should not be instantiated, configured, and used by itself. Use Component.fabricate to create an anonymous class of this type.

Class Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Base

define_task, description, usage

Methods inherited from Base

register_subcommand, ui

Class Attribute Details

.componentMB::Component (readonly)

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.

Return the component associated with this instance of the class

Returns:



18
19
20
# File 'lib/mb/cli/sub_command/component.rb', line 18

def component
  @component
end

Class Method Details

.fabricate(component) ⇒ SubCommand::Component

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.

Parameters:

Returns:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mb/cli/sub_command/component.rb', line 23

def fabricate(component)
  environment = CliGateway.invoked_opts[:environment]

  Class.new(self) do
    set_component(component)

    component.commands.each do |command|
      define_task(command)
    end

    desc("nodes", "List all nodes grouped by Group")
    define_method(:nodes) do
      ui.say "Listing nodes for '#{component.name}' in '#{environment}':"
      nodes = component.nodes(environment).each do |group, nodes|
        nodes.collect! { |node| "#{node.public_hostname} (#{node.public_ipv4})" }
      end
      ui.say nodes.to_yaml
    end
  end
end

.set_component(component) ⇒ Object

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.

Set the component for this instance of the class and tailor the class for the given component.

Parameters:



48
49
50
51
# File 'lib/mb/cli/sub_command/component.rb', line 48

def set_component(component)
  self.namespace(component.name)
  @component = component
end