diff options
author | Oswaldo Ferreira <oswaldo@gitlab.com> | 2019-03-13 02:06:45 +0300 |
---|---|---|
committer | Oswaldo Ferreira <oswaldo@gitlab.com> | 2019-03-18 19:21:13 +0300 |
commit | 08f789736e4d5bfedabc127153d9192dffe5ee1e (patch) | |
tree | 3139ab38485ab4f7a0da86a814b10f7a07c624dc /lib/gitlab/diff | |
parent | 30e52b239ce9ac7ba83778e00f4b45d65e61a4a0 (diff) |
Implement suggestion diff lines parser
Diffstat (limited to 'lib/gitlab/diff')
-rw-r--r-- | lib/gitlab/diff/suggestion_diff.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/gitlab/diff/suggestion_diff.rb b/lib/gitlab/diff/suggestion_diff.rb new file mode 100644 index 00000000000..ee153c226b7 --- /dev/null +++ b/lib/gitlab/diff/suggestion_diff.rb @@ -0,0 +1,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}#{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 + end + + def to_content_as_diff + to_content.lines.map { |line| line.prepend('+') }.join + end + end + end +end |