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

Returns a new instance of 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

Returns:

  • (Boolean)


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

def at_beginning_of_time?
  @parent.nil?
end

#first_commit_for_file?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/git_spelunk/offset.rb', line 62

def first_commit_for_file?

end

#line_number_to_parentObject



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/git_spelunk/offset.rb', line 66

def line_number_to_parent
  return :at_beginning_of_time unless @parent && chunks
  chunk = target_chunk(@line_number)
  return :unable_to_trace unless chunk

  parent_starting_line, parent_total_lines = parent_start_and_total(stats_line(chunk))
  return :first_commit_for_file if parent_starting_line == 0 && parent_total_lines == 0

  chunk_starting_line, chunk_total_lines = src_start_and_total(stats_line(chunk))
  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

Returns:

  • (Boolean)


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

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