grit-ext 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +4 -0
- data/lib/grit/ext/diff.rb +1 -1
- data/lib/grit/ext/diff_header.rb +4 -0
- data/lib/grit/ext/diff_hunk.rb +9 -2
- data/lib/grit/ext/diff_line.rb +12 -0
- data/lib/grit/ext/version.rb +1 -1
- metadata +1 -2
- data/lib/grit/ext/commit.rb +0 -26
data/README.md
CHANGED
@@ -12,3 +12,7 @@ To use grit-ext, after installing, just require 'grit-ext':
|
|
12
12
|
require 'grit-ext'
|
13
13
|
|
14
14
|
All of the extensions, additionally to normal grit classes, will be available to you.
|
15
|
+
|
16
|
+
## Diff#hunks
|
17
|
+
|
18
|
+
[Diff#hunks](https://github.com/mmozuras/grit-ext/blob/master/lib/grit/ext/diff.rb) method returns an array of [DiffHunk](https://github.com/mmozuras/grit-ext/blob/master/lib/grit/ext/diff_hunk.rb). These hunks provide structured information about the diff.
|
data/lib/grit/ext/diff.rb
CHANGED
@@ -6,7 +6,7 @@ module Grit
|
|
6
6
|
.find_all { |line, index| line.start_with?('@@') }
|
7
7
|
.map { |line, index| [DiffHeader.new(line), index] }
|
8
8
|
.map { |header, index|
|
9
|
-
DiffHunk.new(header, lines[index, header.count])
|
9
|
+
DiffHunk.new(header, lines[index, header.count + 1])
|
10
10
|
}
|
11
11
|
end
|
12
12
|
end
|
data/lib/grit/ext/diff_header.rb
CHANGED
data/lib/grit/ext/diff_hunk.rb
CHANGED
@@ -3,17 +3,20 @@ module Grit
|
|
3
3
|
attr_reader :lines
|
4
4
|
|
5
5
|
def initialize(header, diff_hunk)
|
6
|
+
@header = header
|
6
7
|
@lines = diff_hunk.each_with_index.map do |line, index|
|
7
8
|
content = line[1..line.length - 1]
|
8
9
|
status = case line[0]
|
9
10
|
when '+' then :added
|
10
11
|
when '-' then :removed
|
11
12
|
when ' ' then :unchanged
|
13
|
+
else
|
14
|
+
:ignore
|
12
15
|
end
|
13
16
|
position = header.start + index
|
14
17
|
|
15
|
-
DiffLine.new(content, status, position)
|
16
|
-
end
|
18
|
+
DiffLine.new(content, status, position) if status != :ignore
|
19
|
+
end.compact
|
17
20
|
end
|
18
21
|
|
19
22
|
def added
|
@@ -27,5 +30,9 @@ module Grit
|
|
27
30
|
def unchanged
|
28
31
|
@lines.find_all { |line| line.unchanged? }
|
29
32
|
end
|
33
|
+
|
34
|
+
def to_s
|
35
|
+
"#{@header}\n#{lines.join("\n")}"
|
36
|
+
end
|
30
37
|
end
|
31
38
|
end
|
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.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -66,7 +66,6 @@ executables: []
|
|
66
66
|
extensions: []
|
67
67
|
extra_rdoc_files: []
|
68
68
|
files:
|
69
|
-
- lib/grit/ext/commit.rb
|
70
69
|
- lib/grit/ext/diff.rb
|
71
70
|
- lib/grit/ext/diff_header.rb
|
72
71
|
- lib/grit/ext/diff_hunk.rb
|
data/lib/grit/ext/commit.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module Grit
|
2
|
-
class Commit
|
3
|
-
def changed_files
|
4
|
-
diffs.map do |diff|
|
5
|
-
diff.b_path
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
def added_lines
|
10
|
-
diffs.map do |diff|
|
11
|
-
diff.hunks.map do |number, lines|
|
12
|
-
result = []
|
13
|
-
lines.each do |line|
|
14
|
-
if line.start_with?('+')
|
15
|
-
result << { number: number, content: line }
|
16
|
-
end
|
17
|
-
|
18
|
-
number += 1
|
19
|
-
end
|
20
|
-
|
21
|
-
result
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|