2019-02-15 15:39:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
module Gitlab
|
|
|
|
module Diff
|
|
|
|
module Formatters
|
|
|
|
class TextFormatter < BaseFormatter
|
|
|
|
attr_reader :old_line
|
|
|
|
attr_reader :new_line
|
2020-04-22 19:07:51 +05:30
|
|
|
attr_reader :line_range
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
def initialize(attrs)
|
|
|
|
@old_line = attrs[:old_line]
|
|
|
|
@new_line = attrs[:new_line]
|
2020-04-22 19:07:51 +05:30
|
|
|
@line_range = attrs[:line_range]
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
super(attrs)
|
|
|
|
end
|
|
|
|
|
|
|
|
def key
|
|
|
|
@key ||= super.push(old_line, new_line)
|
|
|
|
end
|
|
|
|
|
|
|
|
def complete?
|
2020-03-13 15:44:24 +05:30
|
|
|
old_line.present? || new_line.present?
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def to_h
|
2020-04-22 19:07:51 +05:30
|
|
|
super.merge(old_line: old_line, new_line: new_line, line_range: line_range)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def line_age
|
|
|
|
if old_line && new_line
|
|
|
|
nil
|
|
|
|
elsif new_line
|
|
|
|
'new'
|
|
|
|
else
|
|
|
|
'old'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def position_type
|
|
|
|
"text"
|
|
|
|
end
|
|
|
|
|
|
|
|
def ==(other)
|
|
|
|
other.is_a?(self.class) &&
|
|
|
|
new_line == other.new_line &&
|
2020-05-24 23:13:21 +05:30
|
|
|
old_line == other.old_line &&
|
|
|
|
line_range == other.line_range
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|