rom-rb / rom

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

Make auto_registration more flexible #353

Closed solnic closed 8 years ago

solnic commented 8 years ago

Currently ROM::Configuration#auto_registration supports :namespace option but it is only an on/off toggle, when it's turned on, then the first directory under provided path is treated as the namespace, then we assume there are relations, commands and mappers sub-dirs under that namespace dir. ie auto_registration('lib/persistence', namespace: true) will look for lib/persistence/(relations|mappers|commands)/**/*.rb and assumes module hierarchy is Persistence::(Relations|Mappers|Commands::*.

So, it'd be nice to make it more flexible, so that we can do this:

/cc @janjiss

Closes #338

solnic commented 8 years ago

There's also #331 that wasn't finish, we could probably make it completely flexible by allowing passing a custom dir/constant resolver

janjiss commented 8 years ago

@solnic Wondering about the api for custom dir/constant resolver. Do you think we should add another parameter or change existing one :namespace to allow custom resolver? If we use the same parameter name, can we have some kind of type that has to inherit from base strategy?

solnic commented 8 years ago

Let's hold off with any further improvements until somebody asks for something more customized, then we can revisit.

wmaciejak commented 7 years ago

Hi @solnic ! I wrote some months ago about my case on gitter. I don't like classic separation components by type (f.e. directories app/relations/users.rb, analogical mappers and commands) because IMO better, more efficient way is separation by business feature(f.e. app/contexts/user/relation.rb, app/contexts/post/relation.rb). I created one, quite big project with that approach and it saved my life(and common sense :D ). I used ROM v1, and created a custom registration of components cause that kind of directories configuration was unsupported.

I wonder if there is a way to smart auto-register components in that configuration or maybe it's so significant difference between approaches?