Sha256: b82a0e95568d9ebd72a96a2865a8b8f20f1544958e44b1497174ae76edc2aeee

Contents?: true

Size: 851 Bytes

Versions: 1

Compression:

Stored size: 851 Bytes

Contents

module RuboCop::Git
# copy from https://github.com/thoughtbot/hound/blob/5269fa5/app/models/patch.rb
class Patch
  RANGE_INFORMATION_LINE = /^@@ .+\+(?<line_number>\d+),/
  MODIFIED_LINE = /^\+(?!\+|\+)/
  NOT_REMOVED_LINE = /^[^-]/

  def initialize(body)
    @body = body || ''
  end

  def changed_lines # rubocop:disable Metrics/MethodLength
    line_number = 0
    lines.
      each_with_object({}).
      with_index do |(content, hash), patch_position|
      case content
      when RANGE_INFORMATION_LINE
        line_number = Regexp.last_match[:line_number].to_i
      when MODIFIED_LINE
        line = Line.new(content, line_number, patch_position)
        hash[line_number] = line
        line_number += 1
      when NOT_REMOVED_LINE
        line_number += 1
      end
    end
  end

  private

  def lines
    @body.each_line
  end
end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-git2-0.1.4 lib/rubocop/git/patch.rb