Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor setup/finalization #637

Merged
merged 9 commits into from
Jun 21, 2021

Conversation

solnic
Copy link
Member

@solnic solnic commented Jun 13, 2021

This is a new implementation of the setup/configure/finalize code which drastically simplifies internals and makes it possible to easily extend ROM with more component types. This could be simplified further but a prerequisite is to simplify command compiler first, which I'll most likely do in a separate PR.

This is meant to be backward compatible, I'll test it out with other adapters and apps to ensure things work.

Here's a simple example of how things work internally now:

> config = ROM::Configuration.new(:memory)
# => #<ROM::Configuration:0x00007fdbd5fc3e70

> config.relation(:users)
# => ROM::Relation[Users]

> relation_component = config.components.relations.first
# => [#<ROM::Components::Relation:0x00007fdbd5f13070 @constant=ROM::Relation[Users], @key=:users>]

> ROM.with_configuration(config) { relation_component.build }
# => #<ROM::Relation[Users] name=ROM::Relation::Name(users) dataset=#<ROM::Memory::Dataset data=[]>>

This is a gigantic improvement because it demystifies how rom loads its components and isolates component-specific setup/build code in dedicated component classes. It opens up doors to a lot of interesting features that we'll be able to add later. ie using different configurations for the same component, providing pre-configured components from "the outside" (ie a bunch of preconfigured relations provided by a gem) and so on, lots of possibilities.

A quick follow-up after this is merged will be adding Components::Struct and Components::Repository - making them 1st-class core components that are easy to set up and use.

I will also make ROM's container 100% compatible with dry-system/hanami2 so that things like my_container.import(persistence: rom_container) will work OOTB.

Refs #607

@solnic solnic added the wip label Jun 13, 2021
solnic added 2 commits June 16, 2021 11:09
  - Use components directly in the loader
  - Use components when finalizing schemas
  - Use components when finalizing relations
  - Use components when finalizing commands
  - Use components when finalizing mappers
  - Remove usage for *_classes methods
  - Components => Components::Registry
  - Introduce Components::Relation
  - Drastically simplify handling of environment and notifications
  - Remove unused environment config from finalize
  - Remove unused repo_adapter
  - Use configuration in Finalize instead of options
  - Remove redundant configuration.finalize
  - Move setting default command registry to relation class method
@solnic solnic force-pushed the 607-refactor-handling-of-component-classes branch from 4c6d96e to 92de373 Compare June 16, 2021 11:13
@solnic solnic marked this pull request as ready for review June 16, 2021 11:26
@solnic solnic removed the wip label Jun 21, 2021
@solnic solnic merged commit cba7574 into master Jun 21, 2021
@solnic solnic deleted the 607-refactor-handling-of-component-classes branch June 21, 2021 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant