Skip to content

Commit 4baa4e9

Browse files
committed
[#969] Add support for Rails autoloader collapsed directories
Signed-off-by: Baron Bloomer <baronbloomer@gmail.com>
1 parent ae0b79c commit 4baa4e9

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/annotate/annotate_models.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,15 @@ def get_loaded_model(model_path, file)
611611
$LOAD_PATH.map(&:to_s)
612612
.select { |path| absolute_file.include?(path) }
613613
.map { |path| absolute_file.sub(path, '').sub(/\.rb$/, '').sub(/^\//, '') }
614+
615+
# Handle Rails apps with collapsed model paths
616+
model_paths = model_paths
617+
.select do |model_path|
618+
defined?(Rails) &&
619+
Rails.autoloaders.main.collapse_dirs.any? &&
620+
Rails.autoloaders.main.collapse_dirs.select { |path| path.match(model_path) }
621+
end.map { |model_path| model_path.sub(/\/models/, '') }
622+
614623
model_paths
615624
.map { |path| get_loaded_model_by_path(path) }
616625
.find { |loaded_model| !loaded_model.nil? }

0 commit comments

Comments
 (0)