diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2005-11-23 21:31:51 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2005-11-23 21:31:51 +0000 |
commit | b94d6c06549b83aa2e97fa80d86f99ee81729775 (patch) | |
tree | ce729d0b044b0c85a13b24d9f4ef4b5bf2181d05 /activesupport/lib/active_support | |
parent | c66ac2102be2d7a53872c7bb96939f616275010e (diff) | |
download | rails-b94d6c06549b83aa2e97fa80d86f99ee81729775.tar.gz rails-b94d6c06549b83aa2e97fa80d86f99ee81729775.tar.bz2 rails-b94d6c06549b83aa2e97fa80d86f99ee81729775.zip |
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
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/dependencies.rb | 36 |
1 files changed, 26 insertions, 10 deletions
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) |