Skip to content

Commit 4384721

Browse files
committed
Ignore 'already initialized constant' warnings when models are in additional auto_load roots, #281
1 parent 0caccf1 commit 4384721

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/annotate/annotate_models.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ def get_model_class(file)
481481
rescue LoadError
482482
# this is for non-rails projects, which don't get Rails auto-require magic
483483
file_path = File.expand_path(file)
484-
if File.file?(file_path) && Kernel.require(file_path)
484+
if File.file?(file_path) && silence_warnings { Kernel.require(file_path) }
485485
retry
486486
elsif model_path.match(/\//)
487487
model_path = model_path.split('/')[1..-1].join('/').to_s
@@ -612,5 +612,13 @@ def classified_sort(cols)
612612

613613
return ([id] << rest_cols << timestamps << associations).flatten
614614
end
615+
616+
# Ignore warnings for the duration of the block ()
617+
def silence_warnings
618+
old_verbose, $VERBOSE = $VERBOSE, nil
619+
yield
620+
ensure
621+
$VERBOSE = old_verbose
622+
end
615623
end
616624
end

0 commit comments

Comments
 (0)