Class: GitSpelunk::Offset

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

Defined Under Namespace

Classes: Chunk

Constant Summary collapse

STATS_PATTERN =
/@@ \-(\d+),(\d+) \+(\d+),(\d+) @@/

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)


157
158
159
# File 'lib/git_spelunk/offset.rb', line 157

def at_beginning_of_time?
  @parent.nil?
end

#line_number_to_parentObject



165
166
167
168
169
170
171
172
173
# 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?Boolean

Returns:

  • (Boolean)


161
162
163
# File 'lib/git_spelunk/offset.rb', line 161

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