Class: Cuprum::Cli::Integrations::Thor::Task::Builder

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/cuprum/cli/integrations/thor/task.rb

Overview

Generates a Thor::Task wrapping a Cuprum::Cli command class.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command_class) ⇒ Builder

Returns a new instance of Builder.

Parameters:

  • command_class (Class)

    the command to execute.



25
26
27
28
29
30
# File 'lib/cuprum/cli/integrations/thor/task.rb', line 25

def initialize(command_class)
  validate_command_class(command_class)

  @command_class = command_class
  @full_name     = nil
end

Instance Attribute Details

#command_classClass (readonly)

Returns the command to execute.

Returns:

  • (Class)

    the command to execute.



33
34
35
# File 'lib/cuprum/cli/integrations/thor/task.rb', line 33

def command_class
  @command_class
end

Instance Method Details

#build(full_name: nil) ⇒ Class

Generates a Thor::Task wrapping the command class.

The generated task will be assigned Thor metadata automatically, based on the configuration of the command class.

Returns:

  • (Class)

    the generated Task class.



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/cuprum/cli/integrations/thor/task.rb', line 47

def build(full_name: nil)
  @full_name = full_name || command_class.full_name

  tools.assertions.validate_name(@full_name, as: 'full_name')

  Cuprum::Cli::Integrations::Thor::Task
    .subclass(command_class)
    .tap do |task|
      (task)

      task.alias_method short_name, :call_command
    end
end