diff_parser 1.3.3 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjU2NDZhMjhlYmRhOGFkZjczOWQ0OWE4NDUwYmY1MTVhNTljNjAxMQ==
4
+ NjE3OTU3NGU5MzNhZTIzODQ3NWRiOTU0ZmNlNDU2OTNhZmU2ZWU4Yg==
5
5
  data.tar.gz: !binary |-
6
- NDk3YjFkNzQ4N2Q4Y2JkNTIzMjYyMmRkNDQyNDQ5YTc2ZGNmMmQxNQ==
6
+ MzcxNmQwN2I0ZGI2ZGFjMzY3MmRjOTY3ZjUxYWI0Njg2ZmZmNDMwYg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZTU2YzgxYjgwOTYxZTUwNmE5YWQwYWFiZTYxMGQ1NjkxZGQ1MTc4M2U5NGNk
10
- MjcyYzRhODM2NDZlNWJjYmYxN2ViMWJkODRiN2MzNzlhZTYzNzU3YzBiNzkz
11
- ODBiMmZmNDkyYTM5NTliMjAxY2U3N2Q4YzFkYmM2YTFlYjI5Njc=
9
+ NGMxYzcwM2E4YjMyYWY1NDRlYjBhNzNkZDEzMGMwYzg2NDI3NjY2NzRiOTQ4
10
+ NjY3Y2QyNmNlMjJiZjkyZWYzNjJlZGU4ZGRiMjljOGM0NWVkOWRmMzhhMTJm
11
+ NjRiN2MyM2NhMWQzMTUzZmIxNjkzYTlhYThhZWRhMDUxNzUzNDc=
12
12
  data.tar.gz: !binary |-
13
- OThlNDFkY2UxOTI0NjE4NmE3MTQ3ZDM2Y2Q5ZTMxODJlNTAzNmM4NmIxZWEz
14
- N2M4OWRjMTQ3Nzk1ZmFjOTJmNzdkY2MwNDhlYmRjNWEyODRmN2Y0ZWQwZDA1
15
- YmFlMzJmMTEyODRkN2ZlZDZkOWYzYTU0NWM3OGNlNDRiNDMyY2M=
13
+ Mjk5MTMzZTMyMGU1Y2FlYzlmYjAxNzlhMDhkN2E5MWFhYmQxNmM4NGUzNGEz
14
+ MmZiNGYyNzBhMmRmODJkNDk0ZmRkNmFlYWIxYTBmODA5ZGNjYjQyNzFjNzI4
15
+ ODJmNzk5YTBmMTAwZmQxYTJiMjNlYjA4NjlmNjY5MmJmYjI1ODc=
@@ -1,7 +1,9 @@
1
1
  module DiffParser
2
2
  class Diff
3
+ extend Forwardable
4
+
3
5
  attr_reader :raw, :info, :commit, :options
4
- delegate :github, :repo, :sha, to: :commit
6
+ delegate [:github, :repo, :sha] => :commit
5
7
 
6
8
  def initialize(commit, options)
7
9
  @commit = commit
@@ -9,16 +11,18 @@ module DiffParser
9
11
  @info = github.commit(repo, sha)
10
12
 
11
13
  @raw = Rails.cache.fetch(diff_cache_key) do
12
- diff = github.commit(repo, sha, accept: 'application/vnd.github.VERSION.diff')
13
-
14
- if diff.encoding == Encoding::ASCII_8BIT
15
- diff.encode('utf-8', 'ASCII-8BIT', invalid: :replace, undef: :replace, replace: '')
14
+ if raw_diff.encoding == Encoding::ASCII_8BIT
15
+ raw_diff.encode('utf-8', 'ASCII-8BIT', invalid: :replace, undef: :replace, replace: '')
16
16
  else
17
- diff
17
+ raw_diff
18
18
  end
19
19
  end
20
20
  end
21
21
 
22
+ def raw_diff
23
+ @raw_diff ||= github.commit(repo, sha, accept: 'application/vnd.github.VERSION.diff')
24
+ end
25
+
22
26
  def diff_cache_key
23
27
  "diff-#{repo}-#{sha}"
24
28
  end
@@ -39,7 +39,7 @@ module DiffParser
39
39
  end
40
40
  end
41
41
 
42
- yield current_file
42
+ yield current_file unless current_file.nil?
43
43
  end
44
44
 
45
45
  private
@@ -1,8 +1,10 @@
1
1
  module DiffParser
2
2
  class File
3
- attr_accessor :line_old, :line_new, :lines
4
- attr_reader :path, :file_info, :diff, :file_number, :type
5
- delegate :additions, :deletions, to: :file_info
3
+ extend Forwardable
4
+
5
+ attr_accessor :line_old, :line_new, :lines, :type
6
+ attr_reader :path, :file_info, :diff, :file_number
7
+ delegate [:additions, :deletions] => :file_info
6
8
 
7
9
  def initialize(path, diff, file_number=0)
8
10
  @path = preprocess_path(path)
@@ -36,10 +38,6 @@ module DiffParser
36
38
  end
37
39
  end
38
40
 
39
- def type=(str)
40
- @type = str.inquiry
41
- end
42
-
43
41
  def sha
44
42
  diff.sha
45
43
  end
@@ -1,3 +1,3 @@
1
1
  module DiffParser
2
- VERSION = "1.3.3"
2
+ VERSION = '1.3.4'
3
3
  end
data/lib/diff_parser.rb CHANGED
@@ -6,11 +6,21 @@ require 'diff_parser/raw_line'
6
6
  require 'diff_parser/diff_line'
7
7
 
8
8
  module DiffParser
9
- mattr_accessor :max_changes_to_render
10
- @@max_changes_to_render = 500
9
+ def self.max_changes_to_render
10
+ @@max_changes_to_render || 500
11
+ end
12
+
13
+ def self.max_changes_to_render=(changes_count)
14
+ @@max_changes_to_render = changes_count
15
+ end
11
16
 
12
- mattr_accessor :max_unfolded_diff_size
13
- @@max_unfolded_diff_size = 1.megabyte
17
+ def self.max_unfolded_diff_size
18
+ @@max_unfolded_diff_size || 1.megabyte
19
+ end
20
+
21
+ def self.max_unfolded_diff_size=(max_size)
22
+ @@max_unfolded_diff_size = max_size
23
+ end
14
24
 
15
25
  def self.setup
16
26
  yield self
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diff_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - stevo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-07 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2014-02-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ! '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: Allows parsing diffs for presentation purposes - extracted from marvelous
14
28
  GitLab project
15
29
  email: