debian-mirror-gitlab/lib/gitlab/diff/suggestion_diff.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

38 lines
817 B
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# 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
2020-03-13 15:44:24 +05:30
"#{diff_header}\n#{from_content_as_diff}\n#{to_content_as_diff}"
2019-07-07 11:18:12 +05:30
end
def diff_header
"@@ -#{from_line} +#{from_line}"
end
def from_content_as_diff
2020-03-13 15:44:24 +05:30
from_content.lines.map { |line| line.prepend('-') }.join.delete_suffix("\n")
2019-07-07 11:18:12 +05:30
end
def to_content_as_diff
to_content.lines.map { |line| line.prepend('+') }.join
end
end
end
end