grit-ext 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +13 -0
- data/lib/grit/ext/diff.rb +1 -1
- data/lib/grit/ext/diff_header.rb +26 -0
- data/lib/grit/ext/diff_hunk.rb +8 -18
- data/lib/grit/ext/diff_line.rb +15 -0
- data/lib/grit/ext/version.rb +1 -1
- data/lib/grit-ext.rb +2 -1
- metadata +3 -2
- data/lib/grit/ext/diff_hunk_header.rb +0 -11
data/README.md
CHANGED
@@ -1 +1,14 @@
|
|
1
1
|
# grit-ext
|
2
|
+
|
3
|
+
## Resources
|
4
|
+
|
5
|
+
* [grit](https://github.com/mojombo/grit)
|
6
|
+
* [grit-ext on RubyGems](https://rubygems.org/gems/grit-ext)
|
7
|
+
|
8
|
+
## How to Use
|
9
|
+
|
10
|
+
To use grit-ext, after installing, just require 'grit-ext':
|
11
|
+
|
12
|
+
require 'grit-ext'
|
13
|
+
|
14
|
+
All of the extensions, additionally to normal grit classes, will be available to you.
|
data/lib/grit/ext/diff.rb
CHANGED
@@ -4,7 +4,7 @@ module Grit
|
|
4
4
|
lines = diff.split("\n")
|
5
5
|
lines.each_with_index
|
6
6
|
.find_all { |line, index| line.start_with?('@@') }
|
7
|
-
.map { |line, index| [
|
7
|
+
.map { |line, index| [DiffHeader.new(line), index] }
|
8
8
|
.map { |header, index|
|
9
9
|
DiffHunk.new(header, lines[index, header.count])
|
10
10
|
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Grit
|
2
|
+
class DiffHeader
|
3
|
+
attr_reader :removed_start, :removed_count,
|
4
|
+
:added_start, :added_count
|
5
|
+
|
6
|
+
alias_method :start, :added_start
|
7
|
+
alias_method :count, :added_count
|
8
|
+
|
9
|
+
def initialize(hunk_header)
|
10
|
+
groups = hunk_header.split('-').last.split('+')
|
11
|
+
|
12
|
+
removed = groups.first.strip
|
13
|
+
added = groups.last.sub(' @@', '').strip
|
14
|
+
|
15
|
+
@removed_start, @removed_count = get_numbers(removed)
|
16
|
+
@added_start, @added_count = get_numbers(added)
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def get_numbers(s)
|
22
|
+
start, count = s.split(',')
|
23
|
+
[start.to_i, count.to_i]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/grit/ext/diff_hunk.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Grit
|
2
2
|
class DiffHunk
|
3
|
+
attr_reader :lines
|
4
|
+
|
3
5
|
def initialize(header, diff_hunk)
|
4
6
|
@lines = diff_hunk.each_with_index.map do |line, index|
|
5
7
|
content = line[1..line.length - 1]
|
@@ -8,34 +10,22 @@ module Grit
|
|
8
10
|
when '-' then :removed
|
9
11
|
when ' ' then :unchanged
|
10
12
|
end
|
11
|
-
|
12
|
-
content: content,
|
13
|
-
status: status,
|
14
|
-
position: header.start + index
|
15
|
-
}
|
16
|
-
end
|
17
|
-
end
|
13
|
+
position = header.start + index
|
18
14
|
|
19
|
-
|
20
|
-
|
15
|
+
DiffLine.new(content, status, position)
|
16
|
+
end
|
21
17
|
end
|
22
18
|
|
23
19
|
def added
|
24
|
-
|
20
|
+
@lines.find_all { |line| line.added? }
|
25
21
|
end
|
26
22
|
|
27
23
|
def removed
|
28
|
-
|
24
|
+
@lines.find_all { |line| line.removed? }
|
29
25
|
end
|
30
26
|
|
31
27
|
def unchanged
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
private
|
36
|
-
|
37
|
-
def lines_by_status(status)
|
38
|
-
@lines.find_all { |line| line[:status] == status }
|
28
|
+
@lines.find_all { |line| line.unchanged? }
|
39
29
|
end
|
40
30
|
end
|
41
31
|
end
|
data/lib/grit/ext/version.rb
CHANGED
data/lib/grit-ext.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.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -68,8 +68,9 @@ extra_rdoc_files: []
|
|
68
68
|
files:
|
69
69
|
- lib/grit/ext/commit.rb
|
70
70
|
- lib/grit/ext/diff.rb
|
71
|
+
- lib/grit/ext/diff_header.rb
|
71
72
|
- lib/grit/ext/diff_hunk.rb
|
72
|
-
- lib/grit/ext/
|
73
|
+
- lib/grit/ext/diff_line.rb
|
73
74
|
- lib/grit/ext/version.rb
|
74
75
|
- lib/grit-ext.rb
|
75
76
|
- LICENSE
|