Class: Gerrit::Command::Base Abstract
- Inherits:
-
Object
- Object
- Gerrit::Command::Base
- Includes:
- Utils
- Defined in:
- lib/gerrit/command/base.rb
Overview
This class is abstract.
Abstract base class of all commands.
Direct Known Subclasses
Checkout, Clone, Console, Groups, Help, List, Members, Projects, Push, Setup, Submit, Version
Class Method Summary collapse
-
.from_arguments(config, ui, arguments) ⇒ Gerrit::Command::Base
Create a command from a list of arguments.
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(config, ui, arguments) ⇒ Base
constructor
A new instance of Base.
-
#run ⇒ Object
Parses arguments and executes the command.
Methods included from Utils
camel_case, commit_hash?, human_time, map_in_parallel, snake_case
Constructor Details
#initialize(config, ui, arguments) ⇒ Base
Returns a new instance of Base.
33 34 35 36 37 |
# File 'lib/gerrit/command/base.rb', line 33 def initialize(config, ui, arguments) @config = config @ui = ui @arguments = arguments end |
Class Method Details
.from_arguments(config, ui, arguments) ⇒ Gerrit::Command::Base
Create a command from a list of arguments.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gerrit/command/base.rb', line 17 def self.from_arguments(config, ui, arguments) cmd = arguments.first begin require "gerrit/command/#{Gerrit::Utils.snake_case(cmd)}" rescue LoadError => ex raise Gerrit::Errors::CommandInvalidError, "`gerrit #{cmd}` is not a valid command" end Gerrit::Command.const_get(Gerrit::Utils.camel_case(cmd)).new(config, ui, arguments) end |
Instance Method Details
#execute ⇒ Object
Executes the command given the previously-parsed arguments.
47 48 49 |
# File 'lib/gerrit/command/base.rb', line 47 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.
54 55 56 |
# File 'lib/gerrit/command/base.rb', line 54 def execute_command(command_arguments) self.class.from_arguments(config, ui, command_arguments).execute end |
#run ⇒ Object
Parses arguments and executes the command.
40 41 42 43 44 |
# File 'lib/gerrit/command/base.rb', line 40 def run # TODO: include a parse step here and remove duplicate parsing code from # individual commands execute end |