class GitSpelunk::Offset

Constants

STATS_PATTERN

Attributes

chunks[R]
file_name[R]
repo[R]
sha[R]

Public Class Methods

new(repo, file_name, sha, line_number) click to toggle source
# File lib/git_spelunk/offset.rb, line 41
def initialize(repo, file_name, sha, line_number)
  @repo = repo
  @file_name = file_name
  @sha = sha
  @line_number = line_number
  @parent = @repo.commits(@sha)[0].parents[0]
  true
end

Public Instance Methods

at_beginning_of_time?() click to toggle source
# File lib/git_spelunk/offset.rb, line 157
def at_beginning_of_time?
  @parent.nil?
end
line_number_to_parent() click to toggle source
# File lib/git_spelunk/offset.rb, line 165
def line_number_to_parent
  return :at_beginning_of_time unless @parent && chunks
  chunk = target_chunk(@line_number)
  return :unable_to_trace unless chunk

  return :first_commit_for_file if chunk.minus_offset == 0 && chunk.minus_length == 0

  chunk.find_parent_line_number(@line_number)
end
unable_to_trace_lineage?() click to toggle source
# File lib/git_spelunk/offset.rb, line 161
def unable_to_trace_lineage?
  @parent && (@chunks.nil? || target_chunk.nil?)
end

Private Instance Methods

target_chunk(line_number) click to toggle source
# File lib/git_spelunk/offset.rb, line 177
def target_chunk(line_number)
  chunks.find { |c| c.has_line?(line_number) }
end