grit-ext 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -0
- data/lib/grit/ext/diff.rb +19 -5
- data/lib/grit/ext/diff_hunk.rb +5 -3
- data/lib/grit/ext/diff_line.rb +1 -1
- data/lib/grit/ext/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
data/lib/grit/ext/diff.rb
CHANGED
@@ -1,12 +1,26 @@
|
|
1
1
|
module Grit
|
2
2
|
class Diff
|
3
3
|
def hunks
|
4
|
-
|
5
|
-
|
4
|
+
header_lines.each_with_index
|
5
|
+
.map { |header, index|
|
6
|
+
next_header = header_lines[index + 1]
|
7
|
+
next_line_number = next_header ? next_header[1] : lines.count
|
8
|
+
DiffHunk.new(header[0], lines[header[1], next_line_number - 1])
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def lines
|
15
|
+
@lines ||= diff.split("\n")
|
16
|
+
end
|
17
|
+
|
18
|
+
def header_lines
|
19
|
+
@header_lines ||= lines.each_with_index
|
6
20
|
.find_all { |line, index| line.start_with?('@@') }
|
7
|
-
.map { |line, index|
|
8
|
-
|
9
|
-
|
21
|
+
.map { |line, index|
|
22
|
+
header = DiffHeader.new(line)
|
23
|
+
[header, index]
|
10
24
|
}
|
11
25
|
end
|
12
26
|
end
|
data/lib/grit/ext/diff_hunk.rb
CHANGED
@@ -11,11 +11,13 @@ module Grit
|
|
11
11
|
when '-' then :removed
|
12
12
|
when ' ' then :unchanged
|
13
13
|
else
|
14
|
-
|
14
|
+
nil
|
15
15
|
end
|
16
|
-
position = header.start + index
|
17
16
|
|
18
|
-
|
17
|
+
if status
|
18
|
+
diff_position = header.start + index
|
19
|
+
DiffLine.new(content, status, diff_position)
|
20
|
+
end
|
19
21
|
end.compact
|
20
22
|
end
|
21
23
|
|
data/lib/grit/ext/diff_line.rb
CHANGED
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.4
|
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-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: grit
|