Sha256: 1ac1af06085ad016c02e14544c44c7b88cfe7285886893f08a8e6a256dad66b0

Contents?: true

Size: 932 Bytes

Versions: 1

Compression:

Stored size: 932 Bytes

Contents

module RuboCop::Git
# copy from https://github.com/thoughtbot/hound/blob/d2f3933/app/models/commit_file.rb
class CommitFile
  def initialize(file, commit)
    @file = file
    @commit = commit
  end

  def absolute_path
    @file.absolute_path
  end

  def filename
    @file.filename
  end

  def content
    @content ||= begin
      unless removed?
        @commit.file_content(filename)
      end
    end
  end

  def relevant_line?(line_number)
    modified_lines.detect do |modified_line|
      modified_line.line_number == line_number
    end
  end

  def removed?
    @file.status == 'removed'
  end

  def ruby?
    filename.match(/.*\.rb$/)
  end

  def modified_lines
    @modified_lines ||= patch.additions
  end

  def modified_line_at(line_number)
    modified_lines.detect do |modified_line|
      modified_line.line_number == line_number
    end
  end

  private

  def patch
    Patch.new(@file.patch)
  end
end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cs-rubocop-git-0.1.4 lib/rubocop/git/commit_file.rb