Skip to content

Commit

Permalink
Raise exception if nested file will never be found
Browse files Browse the repository at this point in the history
It is possible to give autoload an invalid path, and that issue will
never be found until the associated constant is vivified.  This causes
issues where people forget to remove the require_nested calls when they
remove the files.  Now, it's not possible to forget, because an
exception will be raised as soon as the parent file is loaded.
  • Loading branch information
Fryguy committed Nov 20, 2019
1 parent 13e4517 commit 2a116ec
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions lib/extensions/require_nested.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def require_nested(name)
filename = "#{self}::#{name}".underscore
filename = name.to_s.underscore if self == Object
if Rails.application.config.cache_classes
raise LoadError, "No such file to load -- #{filename}" unless ActiveSupport::Dependencies.search_for_file(filename)
autoload name, filename
else
require_dependency filename
Expand Down

0 comments on commit 2a116ec

Please sign in to comment.