diff options
author | Xavier Noria <fxn@hashref.com> | 2014-10-25 13:50:42 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2014-10-25 14:06:33 +0200 |
commit | ae07806858072cd66611c165d1eed2a113e639e5 (patch) | |
tree | b8c5622a88dc410ffa4eeb7076b01610e93dd324 /activesupport/lib | |
parent | c4767e13d4ae927e6d605cad3846c9807745b883 (diff) | |
download | rails-ae07806858072cd66611c165d1eed2a113e639e5.tar.gz rails-ae07806858072cd66611c165d1eed2a113e639e5.tar.bz2 rails-ae07806858072cd66611c165d1eed2a113e639e5.zip |
fixes circularity check in dependencies
The check for circular loading should depend on a stack of files being
loaded at the moment, rather than the collection of loaded files.
This showed up indirectly in #16468, where a misspelled helper would
incorrectly result in a circularity error message.
References #16468
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/dependencies.rb | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 93a11d4586..a89c769e34 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -30,6 +30,10 @@ module ActiveSupport #:nodoc: mattr_accessor :loaded self.loaded = Set.new + # Stack of files being loaded. + mattr_accessor :loading + self.loading = [] + # Should we load files or require them? mattr_accessor :mechanism self.mechanism = ENV['NO_RELOAD'] ? :require : :load @@ -317,6 +321,7 @@ module ActiveSupport #:nodoc: def clear log_call loaded.clear + loading.clear remove_unloadable_constants! end @@ -329,6 +334,7 @@ module ActiveSupport #:nodoc: # Record that we've seen this file *before* loading it to avoid an # infinite loop with mutual dependencies. loaded << expanded + loading << expanded begin if load? @@ -351,6 +357,8 @@ module ActiveSupport #:nodoc: rescue Exception loaded.delete expanded raise + ensure + loading.pop end # Record history *after* loading so first load gets warnings. @@ -475,7 +483,7 @@ module ActiveSupport #:nodoc: expanded = File.expand_path(file_path) expanded.sub!(/\.rb\z/, '') - if loaded.include?(expanded) + if loading.include?(expanded) raise "Circular dependency detected while autoloading constant #{qualified_name}" else require_or_load(expanded, qualified_name) |