Skip to content

Commit

Permalink
wip - provide command compiler via configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic committed Jun 16, 2021
1 parent b3e3674 commit 4c6d96e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 14 deletions.
5 changes: 5 additions & 0 deletions lib/rom/components/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ def relations
configuration.relations
end

# @api public
def command_compiler
configuration.command_compiler
end

# @api public
def notifications
configuration.notifications
Expand Down
6 changes: 3 additions & 3 deletions lib/rom/components/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def adapter
# @return [ROM::Relation]
#
# @api public
def build(command_compiler:)
def build
unless adapter
raise MissingAdapterIdentifierError,
"Relation class +#{constant}+ is missing the adapter identifier"
Expand Down Expand Up @@ -60,7 +60,7 @@ def build(command_compiler:)
relation = constant.new(dataset, **options)

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

relation
end
Expand All @@ -86,7 +86,7 @@ def finalize_mappers
end

# @api private
def finalize_commands(command_compiler, relation)
def finalize_commands(relation)
commands = components.commands
.select { |command| command.relation_name == constant.relation_name.relation }
.map { |command| command.build(relation: relation) }
Expand Down
11 changes: 11 additions & 0 deletions lib/rom/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ def finalize
self
end

# @api private
def command_compiler
@command_compiler ||= CommandCompiler.new(
gateways,
relations,
Registry.new,
notifications,
inflector: inflector
)
end

# Apply a plugin to the configuration
#
# @param [Mixed] plugin The plugin identifier, usually a Symbol
Expand Down
12 changes: 1 addition & 11 deletions lib/rom/setup/finalize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,8 @@ def relations
#
# @api private
def load_relations
command_compiler = CommandCompiler.new(
configuration.gateways,
relations,
Registry.new,
notifications,
inflector: configuration.inflector
)

components.relations.each do |component|
relation = component.build(command_compiler: command_compiler)

relations.add(component.key, relation)
relation = relations.add(component.key, component.build)

notifications.trigger(
"configuration.relations.object.registered",
Expand Down

0 comments on commit 4c6d96e

Please sign in to comment.