2019-02-15 15:39:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
module Gitlab
|
|
|
|
module ImportExport
|
|
|
|
class AfterExportStrategyBuilder
|
|
|
|
StrategyNotFoundError = Class.new(StandardError)
|
|
|
|
|
|
|
|
def self.build!(strategy_klass, attributes = {})
|
|
|
|
return default_strategy.new unless strategy_klass
|
|
|
|
|
|
|
|
attributes ||= {}
|
2022-08-27 11:52:29 +05:30
|
|
|
klass = begin
|
|
|
|
strategy_klass.constantize
|
|
|
|
rescue StandardError
|
|
|
|
nil
|
|
|
|
end
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
unless klass && klass < AfterExportStrategies::BaseAfterExportStrategy
|
2021-06-08 01:23:25 +05:30
|
|
|
raise StrategyNotFoundError, "Strategy #{strategy_klass} not found"
|
2018-05-09 12:01:36 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
klass.new(**attributes.symbolize_keys)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.default_strategy
|
|
|
|
AfterExportStrategies::DownloadNotificationStrategy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|