From 6f83a5036d8a9c3f8ed74755ff6d42bc3f6e9982 Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Tue, 22 Jun 2010 23:17:20 +0200 Subject: renames load_(once_)paths to autoload_(once_)paths in dependencies and config --- activesupport/CHANGELOG | 2 ++ activesupport/lib/active_support/dependencies.rb | 24 ++++++++-------- activesupport/test/dependencies_test.rb | 36 ++++++++++++------------ 3 files changed, 32 insertions(+), 30 deletions(-) (limited to 'activesupport') diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index abd0664118..59ad57ede8 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *Rails 3.0.0 [Release Candidate] (unreleased)* +* Renamed ActiveSupport::Dependecies.load_(once_)paths to autoload_(once_)paths. [fxn] + * Added ActiveSupport::FileUpdateChecker to execute a block only if a set of files changed, used by Router and I18n locale files. [José Valim] * Added ActiveSupport::DescendantsTracker to track descendants with support to constants reloading. [José Valim] diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index e8210dfe37..f7b92cf896 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -33,14 +33,14 @@ module ActiveSupport #:nodoc: # The set of directories from which we may automatically load files. Files # under these directories will be reloaded on each request in development mode, - # unless the directory also appears in load_once_paths. - mattr_accessor :load_paths - self.load_paths = [] + # unless the directory also appears in autoload_once_paths. + mattr_accessor :autoload_paths + self.autoload_paths = [] # The set of directories from which automatically loaded constants are loaded - # only once. All directories in this set must also be present in +load_paths+. - mattr_accessor :load_once_paths - self.load_once_paths = [] + # only once. All directories in this set must also be present in +autoload_paths+. + mattr_accessor :autoload_once_paths + self.autoload_once_paths = [] # An array of qualified constant names that have been loaded. Adding a name to # this array will cause it to be unloaded the next time Dependencies are cleared. @@ -352,7 +352,7 @@ module ActiveSupport #:nodoc: # Given +path+, a filesystem path to a ruby file, return an array of constant # paths which would cause Dependencies to attempt to load this file. - def loadable_constants_for_path(path, bases = load_paths) + def loadable_constants_for_path(path, bases = autoload_paths) expanded_path = Pathname.new(path[/\A(.*?)(\.rb)?\Z/, 1]).expand_path bases.inject([]) do |paths, root| @@ -363,11 +363,11 @@ module ActiveSupport #:nodoc: end.uniq end - # Search for a file in load_paths matching the provided suffix. + # Search for a file in autoload_paths matching the provided suffix. def search_for_file(path_suffix) path_suffix = path_suffix.sub(/(\.rb)?$/, ".rb") - load_paths.each do |root| + autoload_paths.each do |root| path = File.join(root, path_suffix) return path if File.file? path end @@ -377,14 +377,14 @@ module ActiveSupport #:nodoc: # Does the provided path_suffix correspond to an autoloadable module? # Instead of returning a boolean, the autoload base for this module is returned. def autoloadable_module?(path_suffix) - load_paths.each do |load_path| + autoload_paths.each do |load_path| return load_path if File.directory? File.join(load_path, path_suffix) end nil end def load_once_path?(path) - load_once_paths.any? { |base| path.starts_with? base } + autoload_once_paths.any? { |base| path.starts_with? base } end # Attempt to autoload the provided module name by searching for a directory @@ -396,7 +396,7 @@ module ActiveSupport #:nodoc: return nil unless base_path = autoloadable_module?(path_suffix) mod = Module.new into.const_set const_name, mod - autoloaded_constants << qualified_name unless load_once_paths.include?(base_path) + autoloaded_constants << qualified_name unless autoload_once_paths.include?(base_path) return mod end diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index 5422c75f5f..c7088638c7 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -25,11 +25,11 @@ class DependenciesTest < Test::Unit::TestCase this_dir = File.dirname(__FILE__) parent_dir = File.dirname(this_dir) $LOAD_PATH.unshift(parent_dir) unless $LOAD_PATH.include?(parent_dir) - prior_load_paths = ActiveSupport::Dependencies.load_paths - ActiveSupport::Dependencies.load_paths = from.collect { |f| "#{this_dir}/#{f}" } + prior_autoload_paths = ActiveSupport::Dependencies.autoload_paths + ActiveSupport::Dependencies.autoload_paths = from.collect { |f| "#{this_dir}/#{f}" } yield ensure - ActiveSupport::Dependencies.load_paths = prior_load_paths + ActiveSupport::Dependencies.autoload_paths = prior_autoload_paths ActiveSupport::Dependencies.mechanism = old_mechanism ActiveSupport::Dependencies.explicitly_unloadable_constants = [] end @@ -264,7 +264,7 @@ class DependenciesTest < Test::Unit::TestCase def test_loadable_constants_for_path_should_provide_all_results fake_root = '/usr/apps/backpack' with_loading fake_root, fake_root + '/lib' do - root = ActiveSupport::Dependencies.load_paths.first + root = ActiveSupport::Dependencies.autoload_paths.first assert_equal ["Lib::A::B", "A::B"], ActiveSupport::Dependencies.loadable_constants_for_path(root + '/lib/a/b') end end @@ -272,7 +272,7 @@ class DependenciesTest < Test::Unit::TestCase def test_loadable_constants_for_path_should_uniq_results fake_root = '/usr/apps/backpack/lib' with_loading fake_root, fake_root + '/' do - root = ActiveSupport::Dependencies.load_paths.first + root = ActiveSupport::Dependencies.autoload_paths.first assert_equal ["A::B"], ActiveSupport::Dependencies.loadable_constants_for_path(root + '/a/b') end end @@ -344,7 +344,7 @@ class DependenciesTest < Test::Unit::TestCase def test_file_search with_loading 'dependencies' do - root = ActiveSupport::Dependencies.load_paths.first + root = ActiveSupport::Dependencies.autoload_paths.first assert_equal nil, ActiveSupport::Dependencies.search_for_file('service_three') assert_equal nil, ActiveSupport::Dependencies.search_for_file('service_three.rb') assert_equal root + '/service_one.rb', ActiveSupport::Dependencies.search_for_file('service_one') @@ -354,14 +354,14 @@ class DependenciesTest < Test::Unit::TestCase def test_file_search_uses_first_in_load_path with_loading 'dependencies', 'autoloading_fixtures' do - deps, autoload = ActiveSupport::Dependencies.load_paths + deps, autoload = ActiveSupport::Dependencies.autoload_paths assert_match %r/dependencies/, deps assert_match %r/autoloading_fixtures/, autoload assert_equal deps + '/conflict.rb', ActiveSupport::Dependencies.search_for_file('conflict') end with_loading 'autoloading_fixtures', 'dependencies' do - autoload, deps = ActiveSupport::Dependencies.load_paths + autoload, deps = ActiveSupport::Dependencies.autoload_paths assert_match %r/dependencies/, deps assert_match %r/autoloading_fixtures/, autoload @@ -418,7 +418,7 @@ class DependenciesTest < Test::Unit::TestCase def test_removal_from_tree_should_be_detected with_loading 'dependencies' do - root = ActiveSupport::Dependencies.load_paths.first + root = ActiveSupport::Dependencies.autoload_paths.first c = ServiceOne ActiveSupport::Dependencies.clear assert ! defined?(ServiceOne) @@ -433,7 +433,7 @@ class DependenciesTest < Test::Unit::TestCase def test_references_should_work with_loading 'dependencies' do - root = ActiveSupport::Dependencies.load_paths.first + root = ActiveSupport::Dependencies.autoload_paths.first c = ActiveSupport::Dependencies.ref("ServiceOne") service_one_first = ServiceOne assert_equal service_one_first, c.get @@ -460,9 +460,9 @@ class DependenciesTest < Test::Unit::TestCase end end - def test_load_once_paths_do_not_add_to_autoloaded_constants + def test_autoload_once_paths_do_not_add_to_autoloaded_constants with_autoloading_fixtures do - ActiveSupport::Dependencies.load_once_paths = ActiveSupport::Dependencies.load_paths.dup + ActiveSupport::Dependencies.autoload_once_paths = ActiveSupport::Dependencies.autoload_paths.dup assert ! ActiveSupport::Dependencies.autoloaded?("ModuleFolder") assert ! ActiveSupport::Dependencies.autoloaded?("ModuleFolder::NestedClass") @@ -473,7 +473,7 @@ class DependenciesTest < Test::Unit::TestCase end ensure Object.class_eval { remove_const :ModuleFolder } - ActiveSupport::Dependencies.load_once_paths = [] + ActiveSupport::Dependencies.autoload_once_paths = [] end def test_application_should_special_case_application_controller @@ -760,20 +760,20 @@ class DependenciesTest < Test::Unit::TestCase def test_load_once_constants_should_not_be_unloaded with_autoloading_fixtures do - ActiveSupport::Dependencies.load_once_paths = ActiveSupport::Dependencies.load_paths + ActiveSupport::Dependencies.autoload_once_paths = ActiveSupport::Dependencies.autoload_paths ::A.to_s assert defined?(A) ActiveSupport::Dependencies.clear assert defined?(A) end ensure - ActiveSupport::Dependencies.load_once_paths = [] + ActiveSupport::Dependencies.autoload_once_paths = [] Object.class_eval { remove_const :A if const_defined?(:A) } end - def test_load_once_paths_should_behave_when_recursively_loading + def test_autoload_once_paths_should_behave_when_recursively_loading with_loading 'dependencies', 'autoloading_fixtures' do - ActiveSupport::Dependencies.load_once_paths = [ActiveSupport::Dependencies.load_paths.last] + ActiveSupport::Dependencies.autoload_once_paths = [ActiveSupport::Dependencies.autoload_paths.last] assert !defined?(CrossSiteDependency) assert_nothing_raised { CrossSiteDepender.nil? } assert defined?(CrossSiteDependency) @@ -784,7 +784,7 @@ class DependenciesTest < Test::Unit::TestCase "CrossSiteDependency shouldn't have been unloaded!" end ensure - ActiveSupport::Dependencies.load_once_paths = [] + ActiveSupport::Dependencies.autoload_once_paths = [] end def test_hook_called_multiple_times -- cgit v1.2.3