Sha256: 44128726ce8fe7618e511f464ccddb111c942e2ffb7e27df1628456294facc6a

Contents?: true

Size: 1.79 KB

Versions: 15

Compression:

Stored size: 1.79 KB

Contents

module MotherBrain
  module Cli
    module SubCommand
      # 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 {SubCommand::Component.fabricate} to create an anonymous class of this type.
      #
      # @api private
      class Component < SubCommand::Base
        class << self
          extend Forwardable

          def_delegator :component, :description

          # Return the component associated with this instance of the class
          #
          # @return [MB::Component]
          attr_reader :component

          # @param [MB::Component] component
          #
          # @return [SubCommand::Component]
          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 the component for this instance of the class and tailor the class for the
          # given component.
          #
          # @param [MB::Component] component
          def set_component(component)
            self.namespace(component.name)
            @component = component
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
motherbrain-1.5.0 lib/mb/cli/sub_command/component.rb
motherbrain-1.4.0 lib/mb/cli/sub_command/component.rb
motherbrain-1.3.0 lib/mb/cli/sub_command/component.rb
motherbrain-1.2.1 lib/mb/cli/sub_command/component.rb
motherbrain-1.2.0 lib/mb/cli/sub_command/component.rb
motherbrain-1.1.3 lib/mb/cli/sub_command/component.rb
motherbrain-1.1.2 lib/mb/cli/sub_command/component.rb
motherbrain-1.1.1 lib/mb/cli/sub_command/component.rb
motherbrain-1.1.0 lib/mb/cli/sub_command/component.rb
motherbrain-1.0.0 lib/mb/cli/sub_command/component.rb
motherbrain-0.14.5 lib/mb/cli/sub_command/component.rb
motherbrain-0.14.4 lib/mb/cli/sub_command/component.rb
motherbrain-0.14.3 lib/mb/cli/sub_command/component.rb
motherbrain-0.14.2 lib/mb/cli/sub_command/component.rb
motherbrain-0.13.1 lib/mb/cli/sub_command/component.rb