From b94d6c06549b83aa2e97fa80d86f99ee81729775 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Wed, 23 Nov 2005 21:31:51 +0000 Subject: Enable warnings on first load only. File which are loaded but raise an exception are not added to loaded set. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3169 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/lib/active_support/dependencies.rb | 36 +++++++++++++++++------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index b0aca1ee97..ed32334240 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -1,3 +1,4 @@ +require 'set' require File.dirname(__FILE__) + '/module_attribute_accessors' require File.dirname(__FILE__) + '/core_ext/load_error' require File.dirname(__FILE__) + '/core_ext/kernel' @@ -5,20 +6,24 @@ require File.dirname(__FILE__) + '/core_ext/kernel' module Dependencies #:nodoc: extend self - @@loaded = [ ] + # All files ever loaded. + mattr_accessor :history + self.history = Set.new + + # All files currently loaded. mattr_accessor :loaded + self.loaded = Set.new - @@mechanism = :load + # Should we load files or require them? mattr_accessor :mechanism - + self.mechanism = :load + def load? mechanism == :load end - + def depend_on(file_name, swallow_load_errors = false) unless loaded.include?(file_name) - loaded << file_name - begin require_or_load(file_name) rescue LoadError @@ -30,18 +35,29 @@ module Dependencies #:nodoc: def associate_with(file_name) depend_on(file_name, true) end - + def clear - self.loaded = [ ] + loaded.clear end def require_or_load(file_name) - file_name = "#{file_name}.rb" unless ! load? || file_name[-3..-1] == '.rb' if load? - enable_warnings { load file_name } + # Append .rb if we have a bare file name. + load_file_name = "#{file_name}.rb" unless file_name[-3..-1] == '.rb' + + # Enable warnings iff this file has not been loaded before. + if history.include?(file_name) + load load_file_name + else + enable_warnings { load load_file_name } + end else require file_name end + + # Record that we've seen this file. + loaded << file_name + history << file_name end def remove_subclasses_for(*classes) -- cgit v1.2.3