-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
62 lines (53 loc) · 1.26 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
namespace :workshop do
desc 'Initialize the workshop environment'
task :init do
system 'bundle install'
system 'for remote in `git branch -r | grep -v master `; do git checkout --track $remote ; git checkout master ; done'
end
desc 'Move to next step'
task :next do
init_git
step = next_step
if step
move_to step
else
puts "No more step ! You are now a Ruby killer."
end
end
desc 'Move to previous step'
task :prev do
init_git
step = prev_step
if step
move_to step
else
puts "You are where everything starts."
end
end
desc 'Move to a specific step'
task :step, :step do |t, args|
init_git
step = "step-#{args[:step]}"
raise "Step #{step} is not valid" if [email protected][step]
move_to(@git.branches[step])
end
def init_git
require 'git'
@git = Git.open('.')
end
def move_to(branch)
puts "Moving to #{branch}"
@git.reset
branch.checkout
end
def next_step
@git.branches["step-#{current_branch + 1}"] || nil
end
def prev_step
prev = current_branch == 1 ? 'master' : "step-#{current_branch - 1}"
@git.branches[prev] || nil
end
def current_branch
@git.current_branch.to_s.gsub('master','0',).gsub('step-','').to_i
end
end