grit-ext 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/grit/ext/diff_hunk.rb +14 -10
- data/lib/grit/ext/diff_line.rb +22 -10
- data/lib/grit/ext/version.rb +1 -1
- metadata +2 -2
data/lib/grit/ext/diff_hunk.rb
CHANGED
@@ -4,19 +4,23 @@ module Grit
|
|
4
4
|
|
5
5
|
def initialize(header, diff_hunk)
|
6
6
|
@header = header
|
7
|
-
@lines =
|
7
|
+
@lines = []
|
8
|
+
|
9
|
+
diff_hunk.each_with_index.map do |line, index|
|
8
10
|
content = line[1..line.length - 1]
|
9
|
-
status =
|
10
|
-
when '+' then :added
|
11
|
-
when '-' then :removed
|
12
|
-
when ' ' then :unchanged
|
13
|
-
else
|
14
|
-
nil
|
15
|
-
end
|
11
|
+
status = DiffLine.status_from_char(line[0])
|
16
12
|
|
17
13
|
if status
|
18
|
-
|
19
|
-
|
14
|
+
line_number = header.start + index
|
15
|
+
|
16
|
+
case status
|
17
|
+
when :added, :unchanged
|
18
|
+
line_number = line_number - removed.count
|
19
|
+
when :removed
|
20
|
+
line_number = line_number - added.count
|
21
|
+
end
|
22
|
+
|
23
|
+
@lines << DiffLine.new(content, status, line_number, index)
|
20
24
|
end
|
21
25
|
end.compact
|
22
26
|
end
|
data/lib/grit/ext/diff_line.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module Grit
|
2
|
-
class DiffLine < Struct.new(:content, :status, :diff_position)
|
2
|
+
class DiffLine < Struct.new(:content, :status, :line_number, :diff_position)
|
3
3
|
def added?
|
4
4
|
status == :added
|
5
5
|
end
|
@@ -12,16 +12,28 @@ module Grit
|
|
12
12
|
status == :unchanged
|
13
13
|
end
|
14
14
|
|
15
|
+
def self.status_from_char(char)
|
16
|
+
case char
|
17
|
+
when '+' then :added
|
18
|
+
when '-' then :removed
|
19
|
+
when ' ' then :unchanged
|
20
|
+
else
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
15
25
|
def to_s
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
"#{char_from_status}#{content}"
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def char_from_status
|
32
|
+
case status
|
33
|
+
when :added then '+'
|
34
|
+
when :removed then '-'
|
35
|
+
when :unchanged then ' '
|
36
|
+
end
|
25
37
|
end
|
26
38
|
end
|
27
39
|
end
|
data/lib/grit/ext/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grit-ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-07-
|
12
|
+
date: 2013-07-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: grit
|