summaryrefslogtreecommitdiff
path: root/lib/gitlab/import_export/after_export_strategy_builder.rb
blob: 37394f46a996fa7a4961d877227790e7e08ff53c (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
# frozen_string_literal: true

module Gitlab
  module ImportExport
    class AfterExportStrategyBuilder
      StrategyNotFoundError = Class.new(StandardError)

      def self.build!(strategy_klass, attributes = {})
        return default_strategy.new unless strategy_klass

        attributes ||= {}
        klass = strategy_klass.constantize rescue nil

        unless klass && klass < AfterExportStrategies::BaseAfterExportStrategy
          raise StrategyNotFoundError.new("Strategy #{strategy_klass} not found")
        end

        klass.new(**attributes.symbolize_keys)
      end

      def self.default_strategy
        AfterExportStrategies::DownloadNotificationStrategy
      end
    end
  end
end