On a Rails application I'm working on, I have a model "Type" that relates to the single-table-inheritance model "Node": any possible subclass of Node is defined as a Type in the types table.
Right now this is made possible loading all classes in an initializer, but I'd like to load the subclasses only when they are required.
The best solution I can think of would be having a fallback on an uninitialized constant that would check if that constant can represent a class in the application, something similar to what method_missing does.
I'd like some advice on how and where to define this logic, or if there's a better solution altogether.