Skip to content

Conversation

solnic
Copy link
Member

@solnic solnic commented Jun 22, 2021

This cleans up how gateways are configured and set up and clearly separates loading adapter files via require vs actually loading gateway objects.

The practical outcome is that gateways are now initialized with the actual config that was used to set them up. This makes it possible to easily access configuration from within a gateway and it also simplifies how gateway plugins can access their configurations. This will make it much simpler to implement default configurations, like default struct namespace etc.

> configuration = ROM::Configuration(:sql, "postgres://postgres@db/rom")

> configuration.config.gateways
#<ROM::Configurable::Config:0x00007ff930bbf1d0 @settings={:default=>#<ROM::Configurable::Config:0x00007ff930bbc390 @settings={:adapter=>:sql, :args=>["postgres://postgres@db/rom"], :name=>:default}>}>

> configuration.gateways.default.config
#<ROM::Configurable::Config:0x00007ff930bbc390 @settings={:adapter=>:sql, :args=>["postgres://postgres@db/rom"], :name=>:default}>

> configuration.gateways.default.name
:default

The configuration.config part is yuck so I'm inclined to rename it somehow later on. This and previous refactors also reminded me that plugins and notifications are still global which I completely forgot (that's why we have flaky specs now). I'll finally address this in another PR. This is super important because we need to have configs and plugins on a per-container basis, rather than global. One example of this is auto_restrictions which are now enabled globally, so if you connect to two databases, both setups will have the plugin enabled.

@solnic solnic force-pushed the improve-gateway-setup branch from c53cb34 to dfa7dc6 Compare June 23, 2021 14:14
@solnic solnic marked this pull request as ready for review June 23, 2021 14:14
This makes gateway setup more inline with how components are handled.
It'll make it easier to extend configuration with support for global
defaults and simplify handling of gateways at runtime, because they
now have a name under which they are registered + all config and opts
associated with a gateway instance are stored within the gateway registry
which makes it easily accessible.

It didn't make sense to improve Gateway abstract class because making it
backward compatible would be too much work and breaking API would be even
more work, considering all the adapters that would have to be updated.

In summary:

  - Simplify gateway handling
  - Simplify configuring gateways
  - Add Gateway#name
  - Move config stuff from gateways environment to Configuration
  - Stop memoizing plugins in components
  - Turn Environment into a standard registry with gateways
  - Move Configuration#relation_classes to rom/compat
@solnic solnic force-pushed the improve-gateway-setup branch from dfa7dc6 to 1a788f0 Compare June 23, 2021 14:22
@solnic solnic added the wip label Jun 23, 2021
@solnic solnic merged commit 6abbc4e into master Jun 25, 2021
@solnic solnic deleted the improve-gateway-setup branch June 25, 2021 13:23
@solnic solnic removed the wip label Jun 25, 2021
@solnic solnic added this to the 6.0.0 milestone Jun 25, 2021
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