lib/active_support/dependencies.rb in activesupport-4.2.0.beta3 vs lib/active_support/dependencies.rb in activesupport-4.2.0.beta4

- old
+ new

@@ -28,10 +28,14 @@ # All files currently loaded. 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 # The set of directories from which we may automatically load files. Files @@ -315,10 +319,11 @@ end def clear log_call loaded.clear + loading.clear remove_unloadable_constants! end def require_or_load(file_name, const_path = nil) log_call file_name, const_path @@ -327,10 +332,11 @@ return if loaded.include?(expanded) # 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? log "loading #{file_name}" @@ -349,10 +355,12 @@ result = require file_name end rescue Exception loaded.delete expanded raise + ensure + loading.pop end # Record history *after* loading so first load gets warnings. history << expanded result @@ -473,10 +481,10 @@ if file_path 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) raise LoadError, "Unable to autoload constant #{qualified_name}, expected #{file_path} to define it" unless from_mod.const_defined?(const_name, false) return from_mod.const_get(const_name)