Skip to content

Commit 9086e0b

Browse files
Hammsocarta-l
authored andcommitted
Allow get_loaded_model to succeed when $LOAD_PATH contains non-string 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
1 parent 69926b8 commit 9086e0b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/annotate/annotate_models.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,8 @@ def get_loaded_model(model_path, file)
608608
# auto_load/eager_load paths. Try all possible model paths one by one.
609609
absolute_file = File.expand_path(file)
610610
model_paths =
611-
$LOAD_PATH.select { |path| absolute_file.include?(path) }
611+
$LOAD_PATH.map(&:to_s)
612+
.select { |path| absolute_file.include?(path) }
612613
.map { |path| absolute_file.sub(path, '').sub(/\.rb$/, '').sub(/^\//, '') }
613614
model_paths
614615
.map { |path| get_loaded_model_by_path(path) }

0 commit comments

Comments
 (0)