get_loaded_model_by_path
is supposed to be nil-safe
#883
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 commit partially reverts #801, which by declaring conditional return
has turned
get_loaded_model_by_path
to a less safe method that canreturn nil when its condition is not met.
Apparently the very same condition has been brought to
annotate_model_file
by #774, which seems to cover the "bug" insisted in #801 as well.
On the other hand #801 has brought an inconvenient behaviour as well:
whenever a non-activerecord model file is found,
get_loaded_model_by_path
returns nil, which leads to raising
BadModelFileError
and ends upprinting a bunch of "Unable to annotate ..." messages.
Now it seems tests added by #801 are running right and I do not find
a problem restoring the previous behaviour and turn it nil-safe again.
Say we have a file like
app/models/foo/bar.rb
which is NOT a subclass of ActiveRecord::Base:We do not want this to get annotated but the current code does give it a try, ending up showing a bunch of error messages like this:
With this change the behaviour in v3.1.1 is restored and these un-informational errors are gone.