Skip to content

Commit 5cb8140

Browse files
sato11ocarta-l
authored andcommitted
get_loaded_model_by_path is supposed to be nil-safe (ctran#883)
This commit partially reverts ctran#801, which by declaring conditional return has turned `get_loaded_model_by_path` to a less safe method that can return nil when its the condition is not met. Apparently the very same condition has been brought to `annotate_model_file` by ctran#774, which seems to cover the "bug" insisted in ctran#801 as well. On the other hand ctran#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 up printing a bunch of "Unable to annotate ..." messages. Now it seems tests added by ctran#801 are running right and I do not find a problem restoring the previous behaviour and turn it nil-safe again.
1 parent 8bf269f commit 5cb8140

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

lib/annotate/annotate_models.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,7 @@ def get_loaded_model(model_path, file)
618618

619619
# Retrieve loaded model class by path to the file where it's supposed to be defined.
620620
def get_loaded_model_by_path(model_path)
621-
klass = ActiveSupport::Inflector.constantize(ActiveSupport::Inflector.camelize(model_path))
622-
623-
klass if klass.is_a?(Class) && klass < ActiveRecord::Base
621+
ActiveSupport::Inflector.constantize(ActiveSupport::Inflector.camelize(model_path))
624622
rescue StandardError, LoadError
625623
# Revert to the old way but it is not really robust
626624
ObjectSpace.each_object(::Class)

0 commit comments

Comments
 (0)