diff options
author | Douwe Maan <douwe@selenight.nl> | 2016-06-20 20:15:44 +0300 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2016-07-07 01:50:59 +0300 |
commit | a27462a5c6da0182f6b3a55c9417e6405f2c0415 (patch) | |
tree | 6bdf936568c0f9274cbf24db7f8b6517b2200980 /app/models/concerns/note_on_diff.rb | |
parent | 375193455aa5cb752f1035a6cc69160170a58477 (diff) |
Extract parts of LegacyDiffNote into DiffOnNote concern and move part of responsibility to other classes
Diffstat (limited to 'app/models/concerns/note_on_diff.rb')
-rw-r--r-- | app/models/concerns/note_on_diff.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/app/models/concerns/note_on_diff.rb b/app/models/concerns/note_on_diff.rb new file mode 100644 index 00000000000..b511f33b8fa --- /dev/null +++ b/app/models/concerns/note_on_diff.rb @@ -0,0 +1,53 @@ +module NoteOnDiff + extend ActiveSupport::Concern + + NUMBER_OF_TRUNCATED_DIFF_LINES = 16 + + included do + delegate :blob, :highlighted_diff_lines, to: :diff_file, allow_nil: true + end + + def diff_note? + true + end + + def diff_file + raise NotImplementedError + end + + def diff_line + raise NotImplementedError + end + + def for_line?(line) + raise NotImplementedError + end + + def diff_attributes + raise NotImplementedError + end + + def can_be_award_emoji? + false + end + + def truncated_diff_lines + prev_match_line = nil + prev_lines = [] + + highlighted_diff_lines.each do |line| + if line.meta? + prev_lines.clear + prev_match_line = line + else + prev_lines << line + + break if for_line?(line) + + prev_lines.shift if prev_lines.length >= NUMBER_OF_TRUNCATED_DIFF_LINES + end + end + + prev_lines + end +end |