Class: Gitlab::Diff::PositionTracer

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/diff/position_tracer.rb,
lib/gitlab/diff/position_tracer/base_strategy.rb,
lib/gitlab/diff/position_tracer/line_strategy.rb,
lib/gitlab/diff/position_tracer/image_strategy.rb

Defined Under Namespace

Classes: BaseStrategy, ImageStrategy, LineStrategy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project:, old_diff_refs:, new_diff_refs:, paths: nil) ⇒ PositionTracer

Returns a new instance of PositionTracer.


13
14
15
16
17
18
# File 'lib/gitlab/diff/position_tracer.rb', line 13

def initialize(project:, old_diff_refs:, new_diff_refs:, paths: nil)
  @project = project
  @old_diff_refs = old_diff_refs
  @new_diff_refs = new_diff_refs
  @paths = paths
end

Instance Attribute Details

#new_diff_refsObject

Returns the value of attribute new_diff_refs


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

def new_diff_refs
  @new_diff_refs
end

#old_diff_refsObject

Returns the value of attribute old_diff_refs


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

def old_diff_refs
  @old_diff_refs
end

#pathsObject

Returns the value of attribute paths


11
12
13
# File 'lib/gitlab/diff/position_tracer.rb', line 11

def paths
  @paths
end

#projectObject

Returns the value of attribute project


8
9
10
# File 'lib/gitlab/diff/position_tracer.rb', line 8

def project
  @project
end

Instance Method Details

#ac_diffsObject


29
30
31
32
33
34
35
# File 'lib/gitlab/diff/position_tracer.rb', line 29

def ac_diffs
  @ac_diffs ||= compare(
    old_diff_refs.base_sha || old_diff_refs.start_sha,
    new_diff_refs.base_sha || new_diff_refs.start_sha,
    straight: true
  )
end

#bd_diffsObject


37
38
39
# File 'lib/gitlab/diff/position_tracer.rb', line 37

def bd_diffs
  @bd_diffs ||= compare(old_diff_refs.head_sha, new_diff_refs.head_sha, straight: true)
end

#cd_diffsObject


41
42
43
# File 'lib/gitlab/diff/position_tracer.rb', line 41

def cd_diffs
  @cd_diffs ||= compare(new_diff_refs.start_sha, new_diff_refs.head_sha)
end

#diff_file(position) ⇒ Object


45
46
47
# File 'lib/gitlab/diff/position_tracer.rb', line 45

def diff_file(position)
  position.diff_file(project.repository)
end

#trace(old_position) ⇒ Object


20
21
22
23
24
25
26
27
# File 'lib/gitlab/diff/position_tracer.rb', line 20

def trace(old_position)
  return unless old_diff_refs&.complete? && new_diff_refs&.complete?
  return unless old_position.diff_refs == old_diff_refs

  strategy = old_position.on_text? ? LineStrategy : ImageStrategy

  strategy.new(self).trace(old_position)
end