rom-rb / rom

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

Auto-loadable components #667

Closed solnic closed 2 years ago

solnic commented 2 years ago

This adds support for auto-loading of component files using Zeitwerk. All you need to do is this:

rom = ROM.runtime(:sql, "sqlite::memory") do |cfg|
  cfg.auto_register("path-to-component-dir", auto_load: true) # <= that's it
end

Once this is enabled, whenever you ask for a rom component, it will infer fully qualified constant name based on component's key and try to load a corresponding file using Zeitwerk auto-loading, ie:

If you have top-level namespace enabled, it will be prepended automatically, ie: