rom-rb / rom

Data mapping and persistence toolkit for Ruby
https://rom-rb.org
MIT License
2.07k stars 161 forks source link

Improve plugin API #671

Closed solnic closed 2 years ago

solnic commented 2 years ago

This unifies use interface and improves internal handling of plugins so that all scenarios are still supported while at the same time it adds support for extending either DSL or component's constant (in a generic way). Plugins are now configured in the settings for each component, so that you can actually see which plugins have been enabled for a given component instance, ie:

> users
#<ROM::Relations::Users name=ROM::Relation::Name(users) dataset=#...>

> users.config.component.plugins.detect { |pl| pl.name == :pg_explain }
#<ROM::Plugin type=:relation name=:pg_explain mod=ROM::Plugins::Relation::SQL::Postgres::Explain adapter=:sql config=#<ROM::OpenStruct {:enabled=>true, :target=>ROM::Relations::Users, :applied=>true}> dsl=nil>

With this done, it should be possible to easily convert "default views" in rom-sql into a plugin and it should prevent auto_restrictions from being loaded more than once (which happened before and caused issues with method being defined multiple times, that's why we used to have a guard clause checking if a method isn't defined yet which was always just a hack to silence the warning).