In other words, does it work similarly to development mode but caches the classes as they are required? Or are all models loaded upfront?
If the latter, how does Rails know to load a model which is a dependency (of another model) before the model which depends on it?
I’d like to know so I can evaluate how feasible it is to load Rails models into a vanilla Ruby project without using the Rails script runner.
The classes are required upfront. Rails basically does
require_dependencyon everything inconfig.eager_load_paths, in alphabetic order (see here).require_dependencyis part of Active Support, and is in a nutshell load/require but that integrates with Active Support’s dependency tracking. If during this process rails comes across something which is not already loaded (e.g. if A was a subclass of B) then the usualconst_missinghooks will fire and loadb.rb.You should be able to setup Active Support like rails does and call the same methods from your non rails project.