Class: MGit::Command

Inherits:
Object
  • Object
show all
Includes:
Output
Defined in:
lib/mgit/command.rb

Constant Summary collapse

@@commands =
{}
@@aliases =
{}

Class Method Summary collapse

Methods included from Output

#perror, #pinfo, #ptable, #pwarn

Class Method Details

.execute(name, args) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/mgit/command.rb', line 8

def self.execute(name, args)
  cmd = self.create(name)

  arity_min, arity_max = cmd.arity
  raise TooFewArgumentsError.new(cmd) if arity_min && args.size < arity_min
  raise TooManyArgumentsError.new(cmd) if arity_max && args.size > arity_max

  cmd.execute(args)
end

.instance_eachObject



30
31
32
33
34
# File 'lib/mgit/command.rb', line 30

def self.instance_each
  @@commands.each do |_, klass|
    yield klass.new
  end
end

.listObject



26
27
28
# File 'lib/mgit/command.rb', line 26

def self.list
  '[' + @@commands.keys.join(', ') + ']'
end

.register_alias(cmd) ⇒ Object



22
23
24
# File 'lib/mgit/command.rb', line 22

def self.register_alias(cmd)
  @@aliases[cmd] = self
end

.register_command(cmd) ⇒ Object



18
19
20
# File 'lib/mgit/command.rb', line 18

def self.register_command(cmd)
  @@commands[cmd] = self
end