Class: RapidDiffs::Viewers::Text::ParallelHunkComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/rapid_diffs/viewers/text/parallel_hunk_component.rb

Instance Method Summary collapse

Constructor Details

#initialize(diff_hunk:, file_hash:, file_path:) ⇒ ParallelHunkComponent

Returns a new instance of ParallelHunkComponent.



9
10
11
12
13
# File 'app/components/rapid_diffs/viewers/text/parallel_hunk_component.rb', line 9

def initialize(diff_hunk:, file_hash:, file_path:)
  @diff_hunk = diff_hunk
  @file_hash = file_hash
  @file_path = file_path
end

Instance Method Details

#id(line) ⇒ Object



15
16
17
# File 'app/components/rapid_diffs/viewers/text/parallel_hunk_component.rb', line 15

def id(line)
  line.id(@file_hash)
end

#line_pairsObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/components/rapid_diffs/viewers/text/parallel_hunk_component.rb', line 19

def line_pairs
  @diff_hunk.parallel_lines.map do |pair|
    {
      line_id: id(pair[:left] || pair[:right]),
      sides: [
        {
          line: pair[:left],
          position: :old
        },
        {
          line: pair[:right],
          position: :new
        }
      ],
      expanded: pair[:left]&.expanded? || pair[:right]&.expanded?
    }
  end
end