Skip to content

Commit 92de373

Browse files
committed
Replace CreateContainer with ROM.container
1 parent 48144d3 commit 92de373

File tree

4 files changed

+32
-74
lines changed

4 files changed

+32
-74
lines changed

lib/rom/core.rb

-6
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,9 @@
1616
# rom Global
1717
require "rom/global"
1818

19-
# rom configurations
20-
require "rom/configuration"
21-
2219
# container with registries
2320
require "rom/container"
2421

25-
# container factory
26-
require "rom/create_container"
27-
2822
# register known plugin types
2923
require "rom/schema_plugin"
3024

lib/rom/create_container.rb

-66
This file was deleted.

lib/rom/global.rb

+30
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
# frozen_string_literal: true
22

3+
require "dry/effects"
4+
35
require "rom/plugin_registry"
46
require "rom/global/plugin_dsl"
7+
require "rom/configuration"
8+
require "rom/setup/finalize"
9+
510

611
module ROM
712
# Globally accessible public interface exposed via ROM module
813
#
914
# @api public
1015
module Global
16+
include Dry::Effects::Handler.Reader(:configuration)
17+
1118
# Set base global registries in ROM constant
1219
#
1320
# @api private
@@ -32,6 +39,29 @@ def self.extended(rom)
3239
# @api private
3340
attr_reader :plugin_registry
3441

42+
# @api public
43+
def container(*args, &block)
44+
configuration =
45+
case args.first
46+
when Configuration
47+
args.first
48+
else
49+
Configuration.new(*args, &block)
50+
end
51+
52+
configuration.configure do |config|
53+
configuration.gateways.each_key do |key|
54+
gateway_config = config.gateways[key]
55+
gateway_config.infer_relations = true unless gateway_config.key?(:infer_relations)
56+
end
57+
end
58+
59+
with_configuration(configuration) do
60+
finalize = Finalize.new(configuration)
61+
finalize.run!
62+
end
63+
end
64+
3565
# Global plugin setup DSL
3666
#
3767
# @example

spec/unit/rom/create_container_spec.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
require "spec_helper"
44

5-
RSpec.describe ROM::CreateContainer, "#finalize" do
6-
describe "#finalize" do
5+
RSpec.describe ROM::Global, "#container" do
6+
context "with configuration" do
77
include_context "container"
88

99
it "can register multiple relations with same dataset" do

0 commit comments

Comments
 (0)