Class: Gitlab::Cng::Commands::Base

Inherits:
Thor
  • Object
show all
Defined in:
lib/gitlab/cng/commands/base.rb

Direct Known Subclasses

Version

Class Method Summary collapse

Class Method Details

.register_commands(base) ⇒ void

This method returns an undefined value.

Register all public methods as commands in another Thor class

Parameters:

  • base (Object)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gitlab/cng/commands/base.rb', line 11

def self.register_commands(base)
  klass = self

  commands.each do |name, command|
    next if base.commands[name]

    # check if the method takes arguments
    pass_args = klass.new.method(name).arity != 0

    base.commands[name] = command
    base.define_method(name) do |*args|
      pass_args ? invoke(klass, name, *args) : invoke(klass, name)
    end
  end
end