Class: GitSpelunk::Offset

Inherits:
Object
  • Object
show all
Defined in:
lib/git_spelunk/offset.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo, file_name, sha, line_number) ⇒ Offset



41
42
43
44
45
46
47
48
# 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

Instance Attribute Details

#chunksObject (readonly)

Returns the value of attribute chunks.



39
40
41
# File 'lib/git_spelunk/offset.rb', line 39

def chunks
  @chunks
end

#file_nameObject (readonly)

Returns the value of attribute file_name.



39
40
41
# File 'lib/git_spelunk/offset.rb', line 39

def file_name
  @file_name
end

#repoObject (readonly)

Returns the value of attribute repo.



39
40
41
# File 'lib/git_spelunk/offset.rb', line 39

def repo
  @repo
end

#shaObject (readonly)

Returns the value of attribute sha.



39
40
41
# File 'lib/git_spelunk/offset.rb', line 39

def sha
  @sha
end

Instance Method Details

#at_beginning_of_time?Boolean



54
55
56
# File 'lib/git_spelunk/offset.rb', line 54

def at_beginning_of_time?
  @parent.nil?
end

#line_number_to_parentObject



62
63
64
65
66
67
68
69
70
71
# File 'lib/git_spelunk/offset.rb', line 62

def line_number_to_parent
  return nil unless @parent && chunks
  chunk = target_chunk(@line_number)
  return nil unless chunk

  chunk_starting_line, chunk_total_lines = src_start_and_total(stats_line(chunk))
  parent_starting_line = parent_start_and_total(stats_line(chunk))[0]
  parent_line_offset = find_parent_line_number(diff_lines(chunk), @line_number, chunk_starting_line, chunk_total_lines)
  parent_starting_line + parent_line_offset
end

#unable_to_trace_lineage?Boolean



58
59
60
# File 'lib/git_spelunk/offset.rb', line 58

def unable_to_trace_lineage?
  @parent && (@chunks.nil? || target_chunk.nil?)
end