1 like
·
1.1K reads
4 comments
To confirm, whilst this idea won't auto discover new subclasses, it will auto-reload changes to any of the STI class files?
Dr Nic Williams Sorry, got no notification for your comment!
Yes, these classes will be reloaded when the application reloads, and the files watched too.
Could we go an extra mile and delay eager loading until some model in the hierarchy is loaded? Perhaps. Maybe Rails includes something like this in the future if we find an even better technique, we'll see.
Can't we use something like Rails.autoloaders.main.on_load('MyModel') { ... }
?
This can be useful when applying the strategy pattern, in the same vein as having a _sti
as a suffi, a team can use a xxxBase
suffix.
Which makes me want to ask you this question: Can we use a regular expression with the on_load
hook?. This in combination with the _sti
prefix idea, we can eager load a directory if it exists.
Basically the Base
class will act as a router, look through the descendants and return the first applicable strategy class ( like ActiveJob::Serializers does )
Do you think this is feasible? Thanks for the article!
chaadow Sorry, I got no notification for these comments!
That is a good idea and a version of that was documented. Problem is that it may lead to unsolvable circular dependencies that depend on load order. I am revamping the section in the guides about this topic.