Class: Arcanus::Command::Base Abstract
- Inherits:
-
Object
- Object
- Arcanus::Command::Base
- Includes:
- Utils
- Defined in:
- lib/arcanus/command/base.rb
Overview
This class is abstract.
Abstract base class of all commands.
Class Method Summary collapse
- .description(desc = nil) ⇒ Object
-
.from_arguments(ui, arguments) ⇒ Arcanus::Command::Base
Create a command from a list of arguments.
- .short_name ⇒ Object
Instance Method Summary collapse
-
#execute ⇒ Object
Executes the command given the previously-parsed arguments.
-
#execute_command(command_arguments) ⇒ Object
Executes another command from the same context as this command.
-
#initialize(ui, arguments) ⇒ Base
constructor
A new instance of Base.
-
#run ⇒ Object
Parses arguments and executes the command.
Methods included from Utils
camel_case, deep_dup, snake_case
Constructor Details
#initialize(ui, arguments) ⇒ Base
Returns a new instance of Base.
40 41 42 43 |
# File 'lib/arcanus/command/base.rb', line 40 def initialize(ui, arguments) @ui = ui @arguments = arguments end |
Class Method Details
.description(desc = nil) ⇒ Object
28 29 30 31 |
# File 'lib/arcanus/command/base.rb', line 28 def description(desc = nil) @description = desc if desc @description end |
.from_arguments(ui, arguments) ⇒ Arcanus::Command::Base
Create a command from a list of arguments.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/arcanus/command/base.rb', line 15 def from_arguments(ui, arguments) cmd = arguments.first begin require "arcanus/command/#{Arcanus::Utils.snake_case(cmd)}" rescue LoadError raise Arcanus::Errors::CommandInvalidError, "`arcanus #{cmd}` is not a valid command" end Arcanus::Command.const_get(Arcanus::Utils.camel_case(cmd)).new(ui, arguments) end |
.short_name ⇒ Object
33 34 35 |
# File 'lib/arcanus/command/base.rb', line 33 def short_name name.split('::').last.downcase end |
Instance Method Details
#execute ⇒ Object
Executes the command given the previously-parsed arguments.
53 54 55 |
# File 'lib/arcanus/command/base.rb', line 53 def execute raise NotImplementedError, 'Define `execute` in Command subclass' end |
#execute_command(command_arguments) ⇒ Object
Executes another command from the same context as this command.
60 61 62 |
# File 'lib/arcanus/command/base.rb', line 60 def execute_command(command_arguments) self.class.from_arguments(ui, command_arguments).execute end |
#run ⇒ Object
Parses arguments and executes the command.
46 47 48 49 50 |
# File 'lib/arcanus/command/base.rb', line 46 def run # TODO: include a parse step here and remove duplicate parsing code from # individual commands execute end |