Permalink
Browse files

deprecates load_(once_)paths in dependencies and app config in favor …

…of autolaod_(once_)paths
  • Loading branch information...
1 parent 68bfd8a commit 4a745ca67054f840a67b438277de6cf7ad6f4f15 @fxn fxn committed Jun 23, 2010
View
@@ -1,5 +1,7 @@
*2.3.9 (unreleased)*
+* Deprecates ActiveSupport::Dependencies.load_(once_)paths in favor of autolaod_(once_)paths. [fxn]
+
* Deprecates Array#random_element in favor of Array#sample, backported from Ruby 1.9, thanks to
Marc-Andre Lafortune. [fxn]
@@ -20,14 +20,38 @@ module Dependencies #: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 = []
+
+ # Deprecated, use autoload_paths.
+ def self.load_paths
+ ActiveSupport::Deprecation.warn("ActiveSupport::Dependencies.load_paths is deprecated and removed in Rails 3, please use autoload_paths instead", caller)
+ autoload_paths
+ end
+
+ # Deprecated, use autoload_paths=.
+ def self.load_paths=(paths)
+ ActiveSupport::Deprecation.warn("ActiveSupport::Dependencies.load_paths= is deprecated and removed in Rails 3, please use autoload_paths= instead", caller)
+ self.autoload_paths = paths
+ end
# 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 = []
+
+ # Deprecated, use autoload_once_paths.
+ def self.load_once_paths
+ ActiveSupport::Deprecation.warn("ActiveSupport::Dependencies.load_once_paths is deprecated and removed in Rails 3, please use autoload_once_paths instead", caller)
+ autoload_once_paths
+ end
+
+ # Deprecated, use autoload_once_paths=.
+ def self.load_once_paths=(paths)
+ ActiveSupport::Deprecation.warn("ActiveSupport::Dependencies.load_once_paths= is deprecated and removed in Rails 3, please use autoload_once_paths= instead", caller)
+ self.autoload_once_paths = paths
+ end
# 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.
@@ -305,7 +329,7 @@ def uninherited_const_defined?(mod, const) #: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)
path = $1 if path =~ /\A(.*)\.rb\Z/
expanded_path = File.expand_path(path)
@@ -326,10 +350,10 @@ def loadable_constants_for_path(path, bases = load_paths)
end.flatten.compact.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 + '.rb' unless path_suffix.ends_with? '.rb'
- load_paths.each do |root|
+ autoload_paths.each do |root|
path = File.join(root, path_suffix)
return path if File.file? path
end
@@ -339,14 +363,14 @@ def search_for_file(path_suffix)
# 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
@@ -358,7 +382,7 @@ def autoload_module!(into, const_name, qualified_name, path_suffix)
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
@@ -13,7 +13,7 @@ module ModuleWithConstant
InheritedConstant = "Hello"
end
-class DependenciesTest < Test::Unit::TestCase
+class DependenciesTest < ActiveSupport::TestCase
def teardown
ActiveSupport::Dependencies.clear
end
@@ -23,11 +23,11 @@ def with_loading(*from)
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
@@ -261,15 +261,15 @@ def test_loadable_constants_for_path_should_handle_relative_paths
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
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
@@ -338,7 +338,7 @@ def test_qualified_name_for
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')
@@ -348,14 +348,14 @@ def test_file_search
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
@@ -412,7 +412,7 @@ def test_const_missing_within_anonymous_module
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,9 +433,9 @@ def test_nested_load_error_isnt_rescued
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")
@@ -446,7 +446,7 @@ def test_load_once_paths_do_not_add_to_autoloaded_constants
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
@@ -741,20 +741,20 @@ def test_remove_constant_handles_double_colon_at_start
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)
@@ -765,7 +765,7 @@ def test_load_once_paths_should_behave_when_recursively_loading
"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
@@ -779,4 +779,11 @@ def test_unhook
ensure
ActiveSupport::Dependencies.hook!
end
+
+ def test_paths_deprecations
+ assert_deprecated(/use autoload_paths(?!=)/) { ActiveSupport::Dependencies.load_paths }
+ assert_deprecated(/use autoload_paths=/) { ActiveSupport::Dependencies.load_paths = [] }
+ assert_deprecated(/use autoload_once_paths(?!=)/) { ActiveSupport::Dependencies.load_once_paths }
+ assert_deprecated(/use autoload_once_paths=/) { ActiveSupport::Dependencies.load_once_paths = [] }
+ end
end
View
@@ -1,6 +1,6 @@
*2.3.9 (unreleased)*
-* ...
+* Deprecates config.load_(once_)paths in favor of autolaod_(once_)paths. [fxn]
*2.3.8 (May 24, 2010)*
@@ -12,7 +12,7 @@
# -- all .rb files in that directory are automatically loaded.
# Add additional load paths for your own custom dirs
- # config.load_paths += %W( #{RAILS_ROOT}/extras )
+ # config.autoload_paths += %W( #{RAILS_ROOT}/extras )
# Specify gems that this application depends on and have them installed with rake gems:install
# config.gem "bj"
@@ -236,29 +236,29 @@ def install_gem_spec_stubs
end
# Set the <tt>$LOAD_PATH</tt> based on the value of
- # Configuration#load_paths. Duplicates are removed.
+ # Configuration#autoload_paths. Duplicates are removed.
def set_load_path
- load_paths = configuration.load_paths + configuration.framework_paths
+ load_paths = configuration.autoload_paths + configuration.framework_paths
load_paths.reverse_each { |dir| $LOAD_PATH.unshift(dir) if File.directory?(dir) }
$LOAD_PATH.uniq!
end
# Set the paths from which Rails will automatically load source files, and
# the load_once paths.
def set_autoload_paths
- ActiveSupport::Dependencies.load_paths = configuration.load_paths.uniq
- ActiveSupport::Dependencies.load_once_paths = configuration.load_once_paths.uniq
+ ActiveSupport::Dependencies.autoload_paths = configuration.autoload_paths.uniq
+ ActiveSupport::Dependencies.autoload_once_paths = configuration.autoload_once_paths.uniq
- extra = ActiveSupport::Dependencies.load_once_paths - ActiveSupport::Dependencies.load_paths
+ extra = ActiveSupport::Dependencies.autoload_once_paths - ActiveSupport::Dependencies.autoload_paths
unless extra.empty?
abort <<-end_error
- load_once_paths must be a subset of the load_paths.
- Extra items in load_once_paths: #{extra * ','}
+ autoload_once_paths must be a subset of the autoload_paths.
+ Extra items in autoload_once_paths: #{extra * ','}
end_error
end
# Freeze the arrays so future modifications will fail rather than do nothing mysteriously
- configuration.load_once_paths.freeze
+ configuration.autoload_once_paths.freeze
end
# Requires all frameworks specified by the Configuration#frameworks
@@ -696,15 +696,39 @@ class Configuration
# An array of additional paths to prepend to the load path. By default,
# all +app+, +lib+, +vendor+ and mock paths are included in this list.
- attr_accessor :load_paths
+ attr_accessor :autoload_paths
+
+ # Deprecated, use autoload_paths.
+ def load_paths
+ $stderr.puts("config.load_paths is deprecated and removed in Rails 3, please use autoload_paths instead")
+ autoload_paths
+ end
+
+ # Deprecated, use autoload_paths=.
+ def load_paths=(paths)
+ $stderr.puts("config.load_paths= is deprecated and removed in Rails 3, please use autoload_paths= instead")
+ self.autoload_paths = paths
+ end
# An array of paths from which Rails will automatically load from only once.
- # All elements of this array must also be in +load_paths+.
- attr_accessor :load_once_paths
+ # All elements of this array must also be in +autoload_paths+.
+ attr_accessor :autoload_once_paths
+
+ # Deprecated, use autoload_once_paths.
+ def load_once_paths
+ $stderr.puts("config.load_once_paths is deprecated and removed in Rails 3, please use autoload_once_paths instead")
+ autoload_once_paths
+ end
+
+ # Deprecated, use autoload_once_paths=.
+ def load_once_paths=(paths)
+ $stderr.puts("config.load_once_paths= is deprecated and removed in Rails 3, please use autoload_once_paths= instead")
+ self.autoload_once_paths = paths
+ end
# An array of paths from which Rails will eager load on boot if cache
# classes is enabled. All elements of this array must also be in
- # +load_paths+.
+ # +autoload_paths+.
attr_accessor :eager_load_paths
# The log level to use for the default Rails logger. In production mode,
@@ -764,12 +788,12 @@ def plugins=(plugins)
# If <tt>reload_plugins?</tt> is false, add this to your plugin's <tt>init.rb</tt>
# to make it reloadable:
#
- # ActiveSupport::Dependencies.load_once_paths.delete lib_path
+ # ActiveSupport::Dependencies.autoload_once_paths.delete lib_path
#
# If <tt>reload_plugins?</tt> is true, add this to your plugin's <tt>init.rb</tt>
# to only load it once:
#
- # ActiveSupport::Dependencies.load_once_paths << lib_path
+ # ActiveSupport::Dependencies.autoload_once_paths << lib_path
#
attr_accessor :reload_plugins
@@ -836,8 +860,8 @@ def initialize
set_root_path!
self.frameworks = default_frameworks
- self.load_paths = default_load_paths
- self.load_once_paths = default_load_once_paths
+ self.autoload_paths = default_autoload_paths
+ self.autoload_once_paths = default_autoload_once_paths
self.eager_load_paths = default_eager_load_paths
self.log_path = default_log_path
self.log_level = default_log_level
@@ -967,7 +991,7 @@ def default_frameworks
[ :active_record, :action_controller, :action_view, :action_mailer, :active_resource ]
end
- def default_load_paths
+ def default_autoload_paths
paths = []
# Add the old mock paths only if the directories exists
@@ -991,8 +1015,8 @@ def default_load_paths
paths.concat builtin_directories
end
- # Doesn't matter since plugins aren't in load_paths yet.
- def default_load_once_paths
+ # Doesn't matter since plugins aren't in autoload_paths yet.
+ def default_autoload_once_paths
[]
end
Oops, something went wrong.

0 comments on commit 4a745ca

Please sign in to comment.