Class: ReflogReview
- Inherits:
-
Object
show all
- Defined in:
- lib/reflog_review.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ReflogReview.
8
9
10
|
# File 'lib/reflog_review.rb', line 8
def initialize
@log = Reflog.new
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
44
45
46
47
|
# File 'lib/reflog_review.rb', line 44
def method_missing(method, *args)
puts "Invalid input."
command_?
end
|
Instance Attribute Details
#log ⇒ Object
Returns the value of attribute log.
6
7
8
|
# File 'lib/reflog_review.rb', line 6
def log
@log
end
|
Instance Method Details
#command_? ⇒ Boolean
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/reflog_review.rb', line 12
def command_?
puts [
"j - next commit",
"k - previous commit",
"s - show current head",
"p - pick commit",
"q - quit",
"? - print help",
].join("\n").colorize(:light_red)
end
|
#command_j ⇒ Object
23
24
25
|
# File 'lib/reflog_review.rb', line 23
def command_j
log.next and show_head
end
|
#command_k ⇒ Object
27
28
29
|
# File 'lib/reflog_review.rb', line 27
def command_k
log.prev and show_head
end
|
#command_p ⇒ Object
35
36
37
|
# File 'lib/reflog_review.rb', line 35
def command_p
log.pick and command_q
end
|
#command_q ⇒ Object
39
40
41
42
|
# File 'lib/reflog_review.rb', line 39
def command_q
puts "\n\nYou just lost the game.".colorize(:black)
exit
end
|
#command_s ⇒ Object
31
32
33
|
# File 'lib/reflog_review.rb', line 31
def command_s
show_head
end
|
#iterate ⇒ Object
71
72
73
74
75
76
77
|
# File 'lib/reflog_review.rb', line 71
def iterate
show_head
loop do
prompt!
send("command_#{gets.chomp.to_sym}")
end
end
|
#prompt! ⇒ Object
49
50
51
52
|
# File 'lib/reflog_review.rb', line 49
def prompt!
status = "Is this the drone you are looking for [j,k,s,p,q,?]? "
print status.colorize(:light_blue)
end
|
#show_head ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/reflog_review.rb', line 54
def show_head
log.show.split("\n").each do |line|
if line.match /^\+/
puts line.colorize(:green)
elsif line.match /^\-/
puts line.colorize(:red)
elsif new_line = line.match(/commit [a-f0-9]{40}$/)
puts new_line.to_s.colorize(:yellow)
elsif line.match /^@@/
print line.split('@@ ')[0] + '@@ '.colorize(:light_blue)
puts line.split('@@ ')[1]
else
puts line
end
end
end
|