My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more
Xavier Noria

1 like

·

1.1K reads

4 comments

Dr Nic Williams
Dr Nic Williams
Nov 1, 2022

To confirm, whilst this idea won't auto discover new subclasses, it will auto-reload changes to any of the STI class files?

·
·1 reply
Xavier Noria
Xavier Noria
Author
·Dec 10, 2022

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.

·
chaadow
chaadow
Nov 1, 2022

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!

·
·1 reply
Xavier Noria
Xavier Noria
Author
·Dec 10, 2022

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.

·