Welcome to mirror list, hosted at ThFree Co, Russian Federation.

diff_stats_collection.rb « git « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7e49d79676e8c9bd862da5ad37df46fbeb4fb9a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# frozen_string_literal: true

module Gitlab
  module Git
    class DiffStatsCollection
      include Gitlab::Utils::StrongMemoize
      include Enumerable

      def initialize(diff_stats)
        @collection = diff_stats
      end

      def each(&block)
        @collection.each(&block)
      end

      def find_by_path(path)
        indexed_by_path[path]
      end

      def paths
        @collection.map(&:path)
      end

      def real_size
        max_files = ::Commit.max_diff_options[:max_files]
        if paths.size > max_files
          "#{max_files}+"
        else
          paths.size.to_s
        end
      end

      private

      def indexed_by_path
        strong_memoize(:indexed_by_path) do
          index_by { |stats| stats.path }
        end
      end
    end
  end
end