Class: RuboCop::Git::DiffParser

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/git/diff_parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(diff) ⇒ Object



2
3
4
# File 'lib/rubocop/git/diff_parser.rb', line 2

def self.parse(diff)
  new.parse(diff)
end

Instance Method Details

#parse(diff) ⇒ Object

rubocop:disable Metrics/MethodLength



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rubocop/git/diff_parser.rb', line 6

def parse(diff) # rubocop:disable Metrics/MethodLength
  files    = []
  in_patch = false

  diff.each_line do |line|
    case line
    when /^diff --git/
      in_patch = false
    when %r{^\+{3} b/(?<path>[^\t\n\r]+)}
      files << RuboCop::Git::PseudoResource.new(Regexp.last_match[:path])
    when /^@@/
      in_patch = true
    end

    files.last.patch << line if in_patch
  end

  files
end