Sha256: 3efaa519f89ba7c672f24ca9b6b1fd44cfb9b2136b08ddb75eebb31c1a69b58f

Contents?: true

Size: 1.65 KB

Versions: 15

Compression:

Stored size: 1.65 KB

Contents

# frozen_string_literal: true

require 'rom/configuration'
require 'rom/environment'
require 'rom/setup'
require 'rom/setup/finalize'

module ROM
  # @api private
  class CreateContainer
    # @api private
    attr_reader :container

    # @api private
    def initialize(environment, setup)
      @container = finalize(environment, setup)
    end

    private

    # @api private
    def finalize(environment, setup)
      environment.configure do |config|
        environment.gateways.each_key do |key|
          gateway_config = config.gateways[key]
          gateway_config.infer_relations = true unless gateway_config.key?(:infer_relations)
        end
      end

      finalize = Finalize.new(
        gateways: environment.gateways,
        relation_classes: setup.relation_classes,
        command_classes: setup.command_classes,
        mappers: setup.mapper_classes,
        plugins: setup.plugins,
        notifications: setup.notifications,
        config: environment.config.dup.freeze
      )

      finalize.run!
    end
  end

  # @api private
  class InlineCreateContainer < CreateContainer
    # @api private
    def initialize(*args, &block)
      case args.first
      when Configuration
        environment = args.first.environment
        setup = args.first.setup
      when Environment
        environment = args.first
        setup = args[1]
      else
        configuration = Configuration.new(*args, &block)
        environment = configuration.environment
        setup = configuration.setup
      end

      super(environment, setup)
    end
  end

  # @api private
  def self.container(*args, &block)
    InlineCreateContainer.new(*args, &block).container
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rom-core-5.3.2 lib/rom/create_container.rb
rom-core-5.3.1 lib/rom/create_container.rb
rom-core-5.3.0 lib/rom/create_container.rb
rom-core-5.2.6 lib/rom/create_container.rb
rom-core-5.2.5 lib/rom/create_container.rb
rom-core-5.2.4 lib/rom/create_container.rb
rom-core-5.2.3 lib/rom/create_container.rb
rom-core-5.2.2 lib/rom/create_container.rb
rom-core-5.2.1 lib/rom/create_container.rb
rom-core-5.1.2 lib/rom/create_container.rb
rom-core-5.1.1 lib/rom/create_container.rb
rom-core-5.1.0 lib/rom/create_container.rb
rom-core-5.0.2 lib/rom/create_container.rb
rom-core-5.0.1 lib/rom/create_container.rb
rom-core-5.0.0 lib/rom/create_container.rb