Class: Pronto::Git::Line

Inherits:
Struct
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/pronto/git/line.rb

Constant Summary collapse

COMPARISON_ATTRIBUTES =
%i[content line_origin
old_lineno new_lineno].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hunkObject

Returns the value of attribute hunk

Returns:

  • (Object)

    the current value of hunk



3
4
5
# File 'lib/pronto/git/line.rb', line 3

def hunk
  @hunk
end

#lineObject

Returns the value of attribute line

Returns:

  • (Object)

    the current value of line



3
4
5
# File 'lib/pronto/git/line.rb', line 3

def line
  @line
end

#patchObject

Returns the value of attribute patch

Returns:

  • (Object)

    the current value of patch



3
4
5
# File 'lib/pronto/git/line.rb', line 3

def patch
  @patch
end

Instance Method Details

#==(other) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/pronto/git/line.rb', line 33

def ==(other)
  return false if other.nil?
  return true if line.nil? && other.line.nil?

  COMPARISON_ATTRIBUTES.all? do |attribute|
    send(attribute) == other.send(attribute)
  end
end

#commit_lineObject



23
24
25
26
27
28
29
30
31
# File 'lib/pronto/git/line.rb', line 23

def commit_line
  @commit_line ||= begin
    patches = patch.repo.show_commit(commit_sha)

    result = patches.find_line(patch.new_file_full_path,
                               blame[:orig_start_line_number])
    result || self # no commit_line means that it was just added
  end
end

#commit_shaObject



19
20
21
# File 'lib/pronto/git/line.rb', line 19

def commit_sha
  blame[:final_commit_id] if blame
end

#positionObject



12
13
14
15
16
17
# File 'lib/pronto/git/line.rb', line 12

def position
  hunk_index = patch.hunks.find_index { |h| h.header == hunk.header }
  line_index = patch.lines.find_index(line)

  line_index + hunk_index + 1
end