diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
commit | 4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch) | |
tree | 5423a1c7516cffe36384133ade12572cf709398d /app/models/bulk_imports/file_transfer/base_config.rb | |
parent | e570267f2f6b326480d284e0164a6464ba4081bc (diff) |
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'app/models/bulk_imports/file_transfer/base_config.rb')
-rw-r--r-- | app/models/bulk_imports/file_transfer/base_config.rb | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/app/models/bulk_imports/file_transfer/base_config.rb b/app/models/bulk_imports/file_transfer/base_config.rb new file mode 100644 index 00000000000..bb04e84ad72 --- /dev/null +++ b/app/models/bulk_imports/file_transfer/base_config.rb @@ -0,0 +1,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 |