Module: Review

Defined in:
lib/review.rb

Class Method Summary collapse

Class Method Details

.add_to_stage(filename) ⇒ Object



28
29
30
31
# File 'lib/review.rb', line 28

def add_to_stage(filename)
	cmd = "git add " + filename
	system(cmd)
end

.ask_to_add(filename) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/review.rb', line 18

def ask_to_add(filename)
	choose do |cmd|
		cmd.index = :none
		cmd.prompt = "Add to stage? "
		cmd.layout = :one_line
		cmd.choice("yes") { add_to_stage filename  }
		cmd.choice("no")
	end
end

.filesObject



7
8
9
10
# File 'lib/review.rb', line 7

def files
	output = `git status --porcelain | grep "^\\(.\\)\\+M" | sed s/^...//`
	output.split("\n")
end

.runObject



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/review.rb', line 58

def run
	if files.size == 0
		puts "There are no unstaged files"
		exit 0
	elsif files.size == 1
		show_diff_for(files.first)
	else
		show_menu
	end

	system("git status -s")
	exit 1
end

.show_diff_for(filename) ⇒ Object



12
13
14
15
16
# File 'lib/review.rb', line 12

def show_diff_for(filename)
	cmd = "git diff " + filename
	system(cmd)
	ask_to_add filename
end

.show_menuObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/review.rb', line 33

def show_menu
	HighLine.color_scheme = HighLine::ColorScheme.new do |cs|
		cs[:system_option] = [ :green ]
		cs[:simple_option] = [ :magenta ]
	end

	choose do |menu|
		menu.header = "Select file to see"
		menu.prompt = "> "

		menu.choice("<%= color('Stop stage review', :system_option) %>") { exit 1 }

		for i in 0...files.size
			filename = files[i]
			option_string = "<%= color('#{filename}', :simple_option)  %>"

			menu.choice(option_string) do
				show_diff_for filename
			end
		end
	end

	show_menu
end