Class: Snaptoken::Commands::Undiff
Constant Summary
Constants inherited
from BaseCommand
BaseCommand::ERROR_MSG
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BaseCommand
#current_or_latest_step, #current_step, inherited, #initialize, #latest_step, #needs!, #select_step, #step_path, #steps
Class Method Details
.name ⇒ Object
2
3
4
|
# File 'lib/snaptoken/commands/undiff.rb', line 2
def self.name
"undiff"
end
|
.summary ⇒ Object
6
7
8
|
# File 'lib/snaptoken/commands/undiff.rb', line 6
def self.summary
"Convert steps.diff to steps folder"
end
|
Instance Method Details
#run ⇒ Object
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
|
# File 'lib/snaptoken/commands/undiff.rb', line 10
def run
needs! :config, :diff, not: :steps_folder
FileUtils.cd(@config[:path]) do
FileUtils.mkdir("steps")
FileUtils.cd("steps") do
File.open("../steps.diff", "r") do |f|
step_num = 0
step = Snaptoken::Step.new(0, nil, [])
prev_step = nil
cur_diff = nil
while line = f.gets
if line =~ /^~~~ step: ([\s\w-]+)$/
if cur_diff
apply_diff(step, cur_diff)
cur_diff = nil
end
prev_step = step
step = Snaptoken::Step.from_commit_msg(prev_step.number + 1, $1)
if step.number == 1
FileUtils.mkdir(step.folder_name)
else
FileUtils.cp_r(prev_step.folder_name, step.folder_name)
end
elsif line =~ /^diff --git/
apply_diff(step, cur_diff) if cur_diff
cur_diff = line
elsif cur_diff
cur_diff << line
end
end
apply_diff(step, cur_diff) if cur_diff
end
end
end
end
|