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

base_config.rb « file_transfer « bulk_imports « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bb04e84ad7280c92b92d67bf51ea4d4d119a62e2 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# frozen_string_literal: true

module BulkImports
  module FileTransfer
    class BaseConfig
      include Gitlab::Utils::StrongMemoize

      def initialize(portable)
        @portable = portable
      end

      def portable_tree
        attributes_finder.find_root(portable_class_sym)
      end

      def export_path
        strong_memoize(:export_path) do
          relative_path = File.join(base_export_path, SecureRandom.hex)

          ::Gitlab::ImportExport.export_path(relative_path: relative_path)
        end
      end

      def portable_relations
        import_export_config.dig(:tree, portable_class_sym).keys.map(&:to_s)
      end

      private

      attr_reader :portable

      def attributes_finder
        strong_memoize(:attributes_finder) do
          ::Gitlab::ImportExport::AttributesFinder.new(config: import_export_config)
        end
      end

      def import_export_config
        ::Gitlab::ImportExport::Config.new(config: import_export_yaml).to_h
      end

      def portable_class
        @portable_class ||= portable.class
      end

      def portable_class_sym
        @portable_class_sym ||= portable_class.to_s.demodulize.underscore.to_sym
      end

      def import_export_yaml
        raise NotImplementedError
      end

      def base_export_path
        raise NotImplementedError
      end
    end
  end
end