Class: MGit::Command

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

Constant Summary collapse

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(cmd) ⇒ Object



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

def self.create(cmd)
  cmd = cmd.downcase.to_sym
  klass = @@commands[cmd] || @@aliases[cmd]
  if klass
    klass.new
  else
    raise UnknownCommandError.new(cmd)
  end
end

.instance_eachObject



28
29
30
31
32
# File 'lib/mgit/command.rb', line 28

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

.listObject



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

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

.register_alias(cmd) ⇒ Object



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

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

.register_command(cmd) ⇒ Object



16
17
18
# File 'lib/mgit/command.rb', line 16

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

Instance Method Details

#descriptionObject



42
43
44
# File 'lib/mgit/command.rb', line 42

def description
  raise ImplementationError.new("Command #{self.class.name} doesn't implement the description method.")
end

#helpObject



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

def help
  raise ImplementationError.new("Command #{self.class.name} doesn't implement the help method.")
end

#usageObject



34
35
36
# File 'lib/mgit/command.rb', line 34

def usage
  raise ImplementationError.new("Command #{self.class.name} doesn't implement the usage method.")
end