Sha256: 80939c66538437c7d24bdf65dc255ef6cc967deea542409758fef3b725363f41

Contents?: true

Size: 1.51 KB

Versions: 7

Compression:

Stored size: 1.51 KB

Contents

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

module ROM
  class CreateContainer
    include ROM::Support::Publisher

    attr_reader :container

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

    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,
        gateway_map: environment.gateways_map,
        relation_classes: setup.relation_classes,
        command_classes: setup.command_classes,
        mappers: setup.mapper_classes,
        config: environment.config.dup.freeze
      )

      finalize.run!
    end
  end

  class InlineCreateContainer < CreateContainer
    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

  def self.container(*args, &block)
    InlineCreateContainer.new(*args, &block).container
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rom-2.0.2 lib/rom/create_container.rb
rom-2.0.1 lib/rom/create_container.rb
rom-2.0.0 lib/rom/create_container.rb
rom-1.0.0 lib/rom/create_container.rb
rom-1.0.0.rc1 lib/rom/create_container.rb
rom-1.0.0.beta2 lib/rom/create_container.rb
rom-1.0.0.beta1 lib/rom/create_container.rb