Skip to content

Commit 4c6d96e

Browse files
committedJun 16, 2021
wip - provide command compiler via configuration
1 parent b3e3674 commit 4c6d96e

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed
 

‎lib/rom/components/core.rb

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ def relations
4343
configuration.relations
4444
end
4545

46+
# @api public
47+
def command_compiler
48+
configuration.command_compiler
49+
end
50+
4651
# @api public
4752
def notifications
4853
configuration.notifications

‎lib/rom/components/relation.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def adapter
2525
# @return [ROM::Relation]
2626
#
2727
# @api public
28-
def build(command_compiler:)
28+
def build
2929
unless adapter
3030
raise MissingAdapterIdentifierError,
3131
"Relation class +#{constant}+ is missing the adapter identifier"
@@ -60,7 +60,7 @@ def build(command_compiler:)
6060
relation = constant.new(dataset, **options)
6161

6262
# TODO: this will be removed once command registry is lazy-by-default
63-
finalize_commands(command_compiler, relation)
63+
finalize_commands(relation)
6464

6565
relation
6666
end
@@ -86,7 +86,7 @@ def finalize_mappers
8686
end
8787

8888
# @api private
89-
def finalize_commands(command_compiler, relation)
89+
def finalize_commands(relation)
9090
commands = components.commands
9191
.select { |command| command.relation_name == constant.relation_name.relation }
9292
.map { |command| command.build(relation: relation) }

‎lib/rom/configuration.rb

+11
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ def finalize
7676
self
7777
end
7878

79+
# @api private
80+
def command_compiler
81+
@command_compiler ||= CommandCompiler.new(
82+
gateways,
83+
relations,
84+
Registry.new,
85+
notifications,
86+
inflector: inflector
87+
)
88+
end
89+
7990
# Apply a plugin to the configuration
8091
#
8192
# @param [Mixed] plugin The plugin identifier, usually a Symbol

‎lib/rom/setup/finalize.rb

+1-11
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,8 @@ def relations
5656
#
5757
# @api private
5858
def load_relations
59-
command_compiler = CommandCompiler.new(
60-
configuration.gateways,
61-
relations,
62-
Registry.new,
63-
notifications,
64-
inflector: configuration.inflector
65-
)
66-
6759
components.relations.each do |component|
68-
relation = component.build(command_compiler: command_compiler)
69-
70-
relations.add(component.key, relation)
60+
relation = relations.add(component.key, component.build)
7161

7262
notifications.trigger(
7363
"configuration.relations.object.registered",

0 commit comments

Comments
 (0)