Class: Pronto::Git::Line

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

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


30
31
32
33
34
35
# File 'lib/pronto/git/line.rb', line 30

def ==(other)
  content == other.content &&
    line_origin == other.line_origin &&
    old_lineno == other.old_lineno &&
    new_lineno == other.new_lineno
end

#commit_lineObject


20
21
22
23
24
25
26
27
28
# File 'lib/pronto/git/line.rb', line 20

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


16
17
18
# File 'lib/pronto/git/line.rb', line 16

def commit_sha
  blame[:final_commit_id] if blame
end

#positionObject


9
10
11
12
13
14
# File 'lib/pronto/git/line.rb', line 9

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