Class: Command::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/lighthouse_branch/command/base.rb
Constant Summary
collapse
- @@commands =
{}
Class Method Summary
collapse
Class Method Details
.command_name(name) ⇒ Object
9
10
11
12
|
# File 'lib/lighthouse_branch/command/base.rb', line 9
def self.command_name(name)
name = name.to_s.downcase.to_sym
@@commands.merge!(name => self)
end
|
.command_regexes ⇒ Object
49
50
51
|
# File 'lib/lighthouse_branch/command/base.rb', line 49
def self.command_regexes
@@commands.keys.map { |k| /#{k}/i }
end
|
.commands ⇒ Object
26
27
28
|
# File 'lib/lighthouse_branch/command/base.rb', line 26
def self.commands
return @@commands
end
|
.default_command ⇒ Object
5
6
7
|
# File 'lib/lighthouse_branch/command/base.rb', line 5
def self.default_command
@@commands.merge!(:default => self)
end
|
.invoke(command, branch_name, ticket_id, args) ⇒ Object
53
54
55
56
57
58
59
60
61
|
# File 'lib/lighthouse_branch/command/base.rb', line 53
def self.invoke(command, branch_name, ticket_id, args)
command = @@commands[command.to_s.downcase.to_sym]
if !command
command = @@commands[:default]
end
return nil if ticket_id <= 0
command.run(branch_name, ticket_id, args)
end
|
.number_of_arguments(arguments) ⇒ Object
14
15
16
|
# File 'lib/lighthouse_branch/command/base.rb', line 14
def self.number_of_arguments(arguments)
self.class_eval("@@number_of_arguments = #{arguments}")
end
|
.run(lighthouse_branch, ticket, args) ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/lighthouse_branch/command/base.rb', line 30
def self.run(lighthouse_branch, ticket, args)
return unless defined?(:command_string)
number_of_arguments = (self.class_eval("@@number_of_arguments") || 0)
correct_arguments = false
if number_of_arguments.is_a?(Range)
correct_arguments = number_of_arguments.member?(args.size)
elsif number_of_arguments.is_a?(Fixnum)
correct_arguments = (number_of_arguments == args.size)
end
if correct_arguments
system(self.command_string(lighthouse_branch, ticket, args))
else
puts self.usage and exit
end
end
|
.usage(usage = nil) ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/lighthouse_branch/command/base.rb', line 18
def self.usage(usage=nil)
if usage
return self.class_eval("@@usage = \"#{usage}\"")
else
return self.class_eval("@@usage")
end
end
|