Skip to content

BulkImports:: Simplify `BulkImports::Pipeline::Context`

Problem To Solve

BulkImports::Pipeline::Context was created with the intention to share some state between pipelines. Although it's working, it has some indirection and unnecessary complexity. Also, as discussed in #276441 (comment 479400918) we might add more shared data to it.

Proposal

  • Simplify BulkImports::Pipeline::Context code removing the LazyAttributes, since the data passed to it is already loaded.
  • Delegate some methods to the received entity for a simpler public API.
module BulkImports
  module Pipeline
    class Context
      attr_reader :entity, :bulk_import

      def initialize(entity)
        @entity = entity
        @bulk_import = entity.bulk_import
      end

      def group
        entity.group
      end

      def current_user
        bulk_import.user
      end

      def configuration
        bulk_import.configuration
      end
    end
  end
end