Class: MGit::Command
- Inherits:
-
Object
show all
- Includes:
- Output
- Defined in:
- lib/mgit/command.rb
Direct Known Subclasses
AddCommand, BranchesCommand, CheckoutCommand, CloneCommand, ConfigCommand, FFMergeCommand, FetchCommand, ForEachCommand, GrepCommand, HeadCommand, HelpCommand, ListCommand, LogCommand, RemoveAllCommand, RemoveCommand, ShowCommand, StatusCommand, TagsCommand, VersionCommand
Constant Summary
collapse
- @@commands =
{}
- @@aliases =
{}
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Output
#perror, #pinfo, #psystem, #ptable, #pwarn
Class Method Details
.create(cmd) ⇒ Object
49
50
51
52
53
54
55
56
57
|
# File 'lib/mgit/command.rb', line 49
def self.create(cmd)
cmd = cmd.downcase.to_sym
klass = @@commands[cmd] || @@aliases[cmd]
if klass
klass.new
else
fail UnknownCommandError, cmd
end
end
|
.execute(name, args) ⇒ Object
13
14
15
16
17
|
# File 'lib/mgit/command.rb', line 13
def self.execute(name, args)
cmd = create(name)
cmd.check_arity(args)
cmd.execute(args)
end
|
.instance_each ⇒ Object
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
|
.list ⇒ Object
27
28
29
|
# File 'lib/mgit/command.rb', line 27
def self.list
'[' + @@commands.keys.join(', ') + ']'
end
|
.load_commands ⇒ Object
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
|
.require_commands_from_directory(dir) ⇒ Object
59
60
61
|
# File 'lib/mgit/command.rb', line 59
def self.require_commands_from_directory(dir)
Dir["#{dir}/*.rb"].each { |file| require file }
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 = arity
fail TooFewArgumentsError, self if arity_min && args.size < arity_min
fail TooManyArgumentsError, self if arity_max && args.size > arity_max
end
|