Use ObjectSpace to locate models by their file names. #70
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
This PR is an attempt to fix #22.
I changed a bit the way model classes are located. After requiring model file we scan
ObjectSpace
for the class that has underscored name matching relative file path inside the models directory.This approach eliminates necessity to guess model name by file name that allow to process models with any kind of non-standard capitalization in class and module names.
Though, it still requires that underscored file name matches underscored model class name.
If the file is located not at the top level of the models directory then we assume that model is either nested in the corresponding chain of modules or is not nested at all.
To be more precise it's possible to capture state of
ObjectSpace
before requiring model file and after the file is required checkObjectSpace
for new classes. In that case it'd be easier to spot the model itself, but there might be problem if for some reason model class was already loaded before explicit requiring its file. So, I'm not sure whether it's a good idea or not.I enabled one pending test case and added some new tests that all are passing now. I might have broken some edge cases. If so, let me know.