class RuboCop::Git::DiffParser

Public Class Methods

parse(diff) click to toggle source
# File lib/rubocop/git/diff_parser.rb, line 5
def parse(diff)
  new.parse(diff)
end

Public Instance Methods

parse(diff) click to toggle source
# File lib/rubocop/git/diff_parser.rb, line 10
def parse(diff)
  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 << PseudoResource.new(Regexp.last_match[:path])
    when /^@@/
      in_patch = true
    end

    files.last.patch << line if in_patch
  end

  files
end