summaryrefslogtreecommitdiff
path: root/lib/bulk_imports/pipeline/context.rb
blob: ad19f5cad7dd9235e081172787793e8bc0660fd0 (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
# frozen_string_literal: true

module BulkImports
  module Pipeline
    class Context
      include Gitlab::Utils::LazyAttributes

      Attribute = Struct.new(:name, :type)

      PIPELINE_ATTRIBUTES = [
        Attribute.new(:current_user, User),
        Attribute.new(:entity, ::BulkImports::Entity),
        Attribute.new(:configuration, ::BulkImports::Configuration)
      ].freeze

      def initialize(args)
        assign_attributes(args)
      end

      private

      PIPELINE_ATTRIBUTES.each do |attr|
        lazy_attr_reader attr.name, type: attr.type
      end

      def assign_attributes(values)
        values.slice(*PIPELINE_ATTRIBUTES.map(&:name)).each do |name, value|
          instance_variable_set("@#{name}", value)
        end
      end
    end
  end
end