grit-ext 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2013 Mindaugas Mozūras
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ # grit-ext
@@ -0,0 +1,26 @@
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
@@ -0,0 +1,13 @@
1
+ module Grit
2
+ class Diff
3
+ def hunks
4
+ lines = diff.split("\n")
5
+ lines.each_with_index
6
+ .find_all { |line, index| line.start_with?('@@') }
7
+ .map { |line, index| [DiffHunkHeader.new(line), index] }
8
+ .map { |header, index|
9
+ DiffHunk.new(header, lines[index, header.count])
10
+ }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,41 @@
1
+ module Grit
2
+ class DiffHunk
3
+ def initialize(header, diff_hunk)
4
+ @lines = diff_hunk.each_with_index.map do |line, index|
5
+ content = line[1..line.length - 1]
6
+ status = case line[0]
7
+ when '+' then :added
8
+ when '-' then :removed
9
+ when ' ' then :unchanged
10
+ end
11
+ {
12
+ content: content,
13
+ status: status,
14
+ position: header.start + index
15
+ }
16
+ end
17
+ end
18
+
19
+ def lines
20
+ @lines
21
+ end
22
+
23
+ def added
24
+ lines_by_status(:added)
25
+ end
26
+
27
+ def removed
28
+ lines_by_status(:removed)
29
+ end
30
+
31
+ def unchanged
32
+ lines_by_status(:unchanged)
33
+ end
34
+
35
+ private
36
+
37
+ def lines_by_status(status)
38
+ @lines.find_all { |line| line[:status] == status }
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,11 @@
1
+ module Grit
2
+ class DiffHunkHeader
3
+ attr_reader :start, :count
4
+
5
+ def initialize(hunk_header)
6
+ start, count = hunk_header.split('+').last.sub(' @@', '').split(',')
7
+ @start = start.to_i
8
+ @count = count.to_i
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Grit
2
+ module Ext
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
data/lib/grit-ext.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'grit'
2
+ require 'grit/ext/diff'
3
+ require 'grit/ext/diff_hunk'
4
+ require 'grit/ext/diff_hunk_header'
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grit-ext
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Mindaugas Mozūras
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: grit
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.5.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.5.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 10.1.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 10.1.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: 2.13.0
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 2.13.0
62
+ description: Collection of extensions for grit
63
+ email:
64
+ - mindaugas.mozuras@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - lib/grit/ext/commit.rb
70
+ - lib/grit/ext/diff.rb
71
+ - lib/grit/ext/diff_hunk.rb
72
+ - lib/grit/ext/diff_hunk_header.rb
73
+ - lib/grit/ext/version.rb
74
+ - lib/grit-ext.rb
75
+ - LICENSE
76
+ - README.md
77
+ homepage: http://github.org/mmozuras/grit-ext
78
+ licenses: []
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: 1.3.6
95
+ requirements: []
96
+ rubyforge_project: grit-ext
97
+ rubygems_version: 1.8.23
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: grit-ext
101
+ test_files: []