Class: Gitlab::Diff::FileCollection::MergeRequestDiffBase

Inherits:
Base
  • Object
show all
Extended by:
Utils::Override
Defined in:
lib/gitlab/diff/file_collection/merge_request_diff_base.rb

Direct Known Subclasses

MergeRequestDiff, MergeRequestDiffBatch

Instance Attribute Summary

Attributes inherited from Base

#diff_options, #diff_refs, #diffable, #fallback_diff_refs, #project

Instance Method Summary collapse

Methods included from Utils::Override

extended, extensions, included, method_added, override, prepended, queue_verification, verify!

Methods inherited from Base

default_options, #diff_file_paths, #diff_file_with_new_path, #diff_file_with_old_path, #diff_paths, #diffs, #overflow?, #pagination_data, #unfold_diff_files

Methods included from Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(merge_request_diff, diff_options:) ⇒ MergeRequestDiffBase

Returns a new instance of MergeRequestDiffBase.


11
12
13
14
15
16
17
18
19
20
# File 'lib/gitlab/diff/file_collection/merge_request_diff_base.rb', line 11

def initialize(merge_request_diff, diff_options:)
  @merge_request_diff = merge_request_diff

  super(merge_request_diff,
        project: merge_request_diff.project,
        diff_options: diff_options,
        diff_refs: merge_request_diff.diff_refs,
        fallback_diff_refs: merge_request_diff.fallback_diff_refs
  )
end

Instance Method Details

#clear_cacheObject


45
46
47
48
# File 'lib/gitlab/diff/file_collection/merge_request_diff_base.rb', line 45

def clear_cache
  highlight_cache.clear
  diff_stats_cache.clear
end

#diff_files(sorted: false) ⇒ Object


22
23
24
25
26
27
28
29
30
# File 'lib/gitlab/diff/file_collection/merge_request_diff_base.rb', line 22

def diff_files(sorted: false)
  strong_memoize(:diff_files) do
    diff_files = super

    diff_files.each { |diff_file| highlight_cache.decorate(diff_file) }

    diff_files
  end
end

#raw_diff_files(sorted: false) ⇒ Object


32
33
34
35
36
# File 'lib/gitlab/diff/file_collection/merge_request_diff_base.rb', line 32

def raw_diff_files(sorted: false)
  # We force `sorted` to `false` as we don't need to sort the diffs when
  # dealing with `MergeRequestDiff` since we sort its files on create.
  super(sorted: false)
end

#write_cacheObject


39
40
41
42
# File 'lib/gitlab/diff/file_collection/merge_request_diff_base.rb', line 39

def write_cache
  highlight_cache.write_if_empty
  diff_stats_cache.write_if_empty(diff_stats_collection)
end