grit-ext 0.0.3 → 0.0.4

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 CHANGED
@@ -1,5 +1,7 @@
1
1
  # grit-ext
2
2
 
3
+ [![Build Status](https://secure.travis-ci.org/mmozuras/grit-ext.png)](http://travis-ci.org/mmozuras/grit-ext)
4
+
3
5
  ## Resources
4
6
 
5
7
  * [grit](https://github.com/mojombo/grit)
data/lib/grit/ext/diff.rb CHANGED
@@ -1,12 +1,26 @@
1
1
  module Grit
2
2
  class Diff
3
3
  def hunks
4
- lines = diff.split("\n")
5
- lines.each_with_index
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| [DiffHeader.new(line), index] }
8
- .map { |header, index|
9
- DiffHunk.new(header, lines[index, header.count + 1])
21
+ .map { |line, index|
22
+ header = DiffHeader.new(line)
23
+ [header, index]
10
24
  }
11
25
  end
12
26
  end
@@ -11,11 +11,13 @@ module Grit
11
11
  when '-' then :removed
12
12
  when ' ' then :unchanged
13
13
  else
14
- :ignore
14
+ nil
15
15
  end
16
- position = header.start + index
17
16
 
18
- DiffLine.new(content, status, position) if status != :ignore
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
 
@@ -1,5 +1,5 @@
1
1
  module Grit
2
- class DiffLine < Struct.new(:content, :status, :position)
2
+ class DiffLine < Struct.new(:content, :status, :diff_position)
3
3
  def added?
4
4
  status == :added
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module Grit
2
2
  module Ext
3
- VERSION = '0.0.3'
3
+ VERSION = '0.0.4'
4
4
  end
5
5
  end
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.3
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-01 00:00:00.000000000 Z
12
+ date: 2013-07-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: grit