debian-mirror-gitlab/lib/bulk_imports/pipeline.rb

85 lines
1.7 KiB
Ruby
Raw Normal View History

2021-01-29 00:20:46 +05:30
# frozen_string_literal: true
module BulkImports
module Pipeline
extend ActiveSupport::Concern
2021-02-22 17:27:13 +05:30
include Gitlab::ClassAttributes
2021-03-11 19:13:27 +05:30
include Runner
2021-01-29 00:20:46 +05:30
2021-03-11 19:13:27 +05:30
def initialize(context)
@context = context
end
2021-02-22 17:27:13 +05:30
2021-03-11 19:13:27 +05:30
included do
2021-02-22 17:27:13 +05:30
private
2021-03-11 19:13:27 +05:30
attr_reader :context
2021-03-08 18:12:59 +05:30
def extractor
@extractor ||= instantiate(self.class.get_extractor)
2021-02-22 17:27:13 +05:30
end
def transformers
@transformers ||= self.class.transformers.map(&method(:instantiate))
end
2021-03-08 18:12:59 +05:30
def loader
@loaders ||= instantiate(self.class.get_loader)
2021-02-22 17:27:13 +05:30
end
def pipeline
@pipeline ||= self.class.name
end
def instantiate(class_config)
class_config[:klass].new(class_config[:options])
end
def abort_on_failure?
self.class.abort_on_failure?
end
end
class_methods do
def extractor(klass, options = nil)
2021-03-08 18:12:59 +05:30
class_attributes[:extractor] = { klass: klass, options: options }
2021-02-22 17:27:13 +05:30
end
def transformer(klass, options = nil)
add_attribute(:transformers, klass, options)
end
def loader(klass, options = nil)
2021-03-08 18:12:59 +05:30
class_attributes[:loader] = { klass: klass, options: options }
2021-02-22 17:27:13 +05:30
end
2021-03-08 18:12:59 +05:30
def get_extractor
class_attributes[:extractor]
2021-02-22 17:27:13 +05:30
end
def transformers
class_attributes[:transformers]
end
2021-03-08 18:12:59 +05:30
def get_loader
class_attributes[:loader]
2021-02-22 17:27:13 +05:30
end
def abort_on_failure!
class_attributes[:abort_on_failure] = true
end
def abort_on_failure?
class_attributes[:abort_on_failure]
end
private
def add_attribute(sym, klass, options)
class_attributes[sym] ||= []
class_attributes[sym] << { klass: klass, options: options }
end
2021-01-29 00:20:46 +05:30
end
end
end