Class: Gitlab::Diff::File

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/diff/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(diff, diff_refs) ⇒ File

Returns a new instance of File


9
10
11
12
# File 'lib/gitlab/diff/file.rb', line 9

def initialize(diff, diff_refs)
  @diff = diff
  @diff_refs = diff_refs
end

Instance Attribute Details

#diffObject (readonly)

Returns the value of attribute diff


4
5
6
# File 'lib/gitlab/diff/file.rb', line 4

def diff
  @diff
end

#diff_refsObject (readonly)

Returns the value of attribute diff_refs


4
5
6
# File 'lib/gitlab/diff/file.rb', line 4

def diff_refs
  @diff_refs
end

Instance Method Details

#added_linesObject


69
70
71
# File 'lib/gitlab/diff/file.rb', line 69

def added_lines
  diff_lines.count(&:added?)
end

#diff_linesObject

Array of Gitlab::DIff::Line objects


23
24
25
# File 'lib/gitlab/diff/file.rb', line 23

def diff_lines
  @lines ||= parser.parse(raw_diff.each_line).to_a
end

#file_pathObject


61
62
63
64
65
66
67
# File 'lib/gitlab/diff/file.rb', line 61

def file_path
  if diff.new_path.present?
    diff.new_path
  elsif diff.old_path.present?
    diff.old_path
  end
end

#highlighted_diff_linesObject


31
32
33
# File 'lib/gitlab/diff/file.rb', line 31

def highlighted_diff_lines
  Gitlab::Diff::Highlight.new(self).highlight
end

#mode_changed?Boolean

Returns:

  • (Boolean)

39
40
41
# File 'lib/gitlab/diff/file.rb', line 39

def mode_changed?
  !!(diff.a_mode && diff.b_mode && diff.a_mode != diff.b_mode)
end

#new_refObject


18
19
20
# File 'lib/gitlab/diff/file.rb', line 18

def new_ref
  diff_refs[1] if diff_refs
end

#next_line(index) ⇒ Object


51
52
53
# File 'lib/gitlab/diff/file.rb', line 51

def next_line(index)
  diff_lines[index + 1]
end

#old_refObject


14
15
16
# File 'lib/gitlab/diff/file.rb', line 14

def old_ref
  diff_refs[0] if diff_refs
end

#parallel_diff_linesObject


35
36
37
# File 'lib/gitlab/diff/file.rb', line 35

def parallel_diff_lines
  Gitlab::Diff::ParallelDiff.new(self).parallelize
end

#parserObject


43
44
45
# File 'lib/gitlab/diff/file.rb', line 43

def parser
  Gitlab::Diff::Parser.new
end

#prev_line(index) ⇒ Object


55
56
57
58
59
# File 'lib/gitlab/diff/file.rb', line 55

def prev_line(index)
  if index > 0
    diff_lines[index - 1]
  end
end

#raw_diffObject


47
48
49
# File 'lib/gitlab/diff/file.rb', line 47

def raw_diff
  diff.diff.to_s
end

#removed_linesObject


73
74
75
# File 'lib/gitlab/diff/file.rb', line 73

def removed_lines
  diff_lines.count(&:removed?)
end

#too_large?Boolean

Returns:

  • (Boolean)

27
28
29
# File 'lib/gitlab/diff/file.rb', line 27

def too_large?
  diff.too_large?
end