Welcome to mirror list, hosted at ThFree Co, Russian Federation.

suggestion_diff.rb « diff « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 783264fe999c07c3ec1a9a673fd8d415e0bace99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# frozen_string_literal: true

module Gitlab
  module Diff
    class SuggestionDiff
      include Gitlab::Utils::StrongMemoize

      delegate :from_content, :to_content, :from_line, to: :@suggestible

      def initialize(suggestible)
        @suggestible = suggestible
      end

      def diff_lines
        Gitlab::Diff::Parser.new.parse(raw_diff.each_line).to_a
      end

      private

      def raw_diff
        "#{diff_header}\n#{from_content_as_diff}\n#{to_content_as_diff}"
      end

      def diff_header
        "@@ -#{from_line} +#{from_line}"
      end

      def from_content_as_diff
        from_content.lines.map { |line| line.prepend('-') }.join.delete_suffix("\n")
      end

      def to_content_as_diff
        to_content.lines.map { |line| line.prepend('+') }.join
      end
    end
  end
end