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

runner.rb « pipeline « bulk_imports « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cf94b500612300efa26b41445a92cff98774b67c (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
# frozen_string_literal: true

module BulkImports
  module Pipeline
    module Runner
      extend ActiveSupport::Concern

      included do
        attr_reader :extractors, :transformers, :loaders

        def initialize
          @extractors = self.class.extractors.map(&method(:instantiate))
          @transformers = self.class.transformers.map(&method(:instantiate))
          @loaders = self.class.loaders.map(&method(:instantiate))

          super
        end

        def run(context)
          extractors.each do |extractor|
            extractor.extract(context).each do |entry|
              transformers.each do |transformer|
                entry = transformer.transform(context, entry)
              end

              loaders.each do |loader|
                loader.load(context, entry)
              end
            end
          end
        end

        def instantiate(class_config)
          class_config[:klass].new(class_config[:options])
        end
      end
    end
  end
end