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

Instance Method Summary collapse

Methods included from Output

#perror, #pinfo, #ptable, #pwarn

Class Method Details

.execute(name, args) ⇒ Object



13
14
15
16
17
# File 'lib/mgit/command.rb', line 13

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

.instance_eachObject



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

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

.listObject



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

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

.load_commandsObject



8
9
10
11
# File 'lib/mgit/command.rb', line 8

def self.load_commands
  require_commands_from_directory File.expand_path('../commands', __FILE__)
  require_commands_from_directory Configuration.plugindir
end

.register_alias(cmd) ⇒ Object



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

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

.register_command(cmd) ⇒ Object



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

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

Instance Method Details

#check_arity(args) ⇒ Object



37
38
39
40
41
# File 'lib/mgit/command.rb', line 37

def check_arity(args)
  arity_min, arity_max = self.arity
  raise TooFewArgumentsError.new(self) if arity_min && args.size < arity_min
  raise TooManyArgumentsError.new(self) if arity_max && args.size > arity_max
end