Class: Gerrit::Command::Base Abstract

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.

Parameters:



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.

Parameters:

Returns:



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

#executeObject

Executes the command given the previously-parsed arguments.

Raises:

  • (NotImplementedError)


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.

Parameters:

  • command_arguments (Array<String>)


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

#runObject

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