Skip to content

Commit

Permalink
Allow get_loaded_model to succeed when $LOAD_PATH contains non-st…
Browse files Browse the repository at this point in the history
…ring values (ctran#848)

As currently implemented, `get_loaded_model` inspects the `$LOAD_PATH` global for path values when trying to find the path for a model file.  This would be fine, except that variable is affected by userspace, which means that it will sometimes contain non-string values, often Pathnames.  To avoid responding with the error `Unable to annotate #{model_path}: no implicit conversion of Pathname into String` in this situation, we simply add an explicit `to_s` call before performing string-specific operations.

Fixes ctran#758
  • Loading branch information
Hamms authored and ocarta-l committed Jun 18, 2021
1 parent 69926b8 commit 9086e0b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/annotate/annotate_models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,8 @@ def get_loaded_model(model_path, file)
# auto_load/eager_load paths. Try all possible model paths one by one.
absolute_file = File.expand_path(file)
model_paths =
$LOAD_PATH.select { |path| absolute_file.include?(path) }
$LOAD_PATH.map(&:to_s)
.select { |path| absolute_file.include?(path) }
.map { |path| absolute_file.sub(path, '').sub(/\.rb$/, '').sub(/^\//, '') }
model_paths
.map { |path| get_loaded_model_by_path(path) }
Expand Down

0 comments on commit 9086e0b

Please sign in to comment.