aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2019-04-28 00:22:13 +0200
committerXavier Noria <fxn@hashref.com>2019-04-28 13:48:26 +0200
commitb6e17b6a4b67ccc9fac5fe16741c3db720f00959 (patch)
treeb95094671664b01428f934f2faff9ae7f7989490 /railties/lib
parentf9330abd986ba59a534f10836875ce9c1199aced (diff)
downloadrails-b6e17b6a4b67ccc9fac5fe16741c3db720f00959.tar.gz
rails-b6e17b6a4b67ccc9fac5fe16741c3db720f00959.tar.bz2
rails-b6e17b6a4b67ccc9fac5fe16741c3db720f00959.zip
new config to opt-out from adding app directories to $LOAD_PATH
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/rails/application/configuration.rb3
-rw-r--r--railties/lib/rails/engine.rb13
2 files changed, 10 insertions, 6 deletions
diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb
index ac86cc89be..0b758dd3dd 100644
--- a/railties/lib/rails/application/configuration.rb
+++ b/railties/lib/rails/application/configuration.rb
@@ -19,7 +19,7 @@ module Rails
:beginning_of_week, :filter_redirect, :x, :enable_dependency_loading,
:read_encrypted_secrets, :log_level, :content_security_policy_report_only,
:content_security_policy_nonce_generator, :require_master_key, :credentials,
- :disable_sandbox
+ :disable_sandbox, :add_autoload_paths_to_load_path
attr_reader :encoding, :api_only, :loaded_config_version, :autoloader
@@ -67,6 +67,7 @@ module Rails
@credentials.key_path = default_credentials_key_path
@autoloader = :classic
@disable_sandbox = false
+ @add_autoload_paths_to_load_path = true
end
def load_defaults(target_version)
diff --git a/railties/lib/rails/engine.rb b/railties/lib/rails/engine.rb
index 06b4019fc7..d1b8c7803f 100644
--- a/railties/lib/rails/engine.rb
+++ b/railties/lib/rails/engine.rb
@@ -559,9 +559,8 @@ module Rails
end
end
- # Add configured load paths to Ruby's load path, and remove duplicate entries.
- initializer :set_load_path, before: :bootstrap_hook do
- _all_load_paths.reverse_each do |path|
+ initializer :set_load_path, before: :bootstrap_hook do |app|
+ _all_load_paths(app.config.add_autoload_paths_to_load_path).reverse_each do |path|
$LOAD_PATH.unshift(path) if File.directory?(path)
end
$LOAD_PATH.uniq!
@@ -709,8 +708,12 @@ module Rails
@_all_autoload_paths ||= (config.autoload_paths + config.eager_load_paths + config.autoload_once_paths).uniq
end
- def _all_load_paths
- @_all_load_paths ||= (config.paths.load_paths + _all_autoload_paths).uniq
+ def _all_load_paths(add_autoload_paths_to_load_path)
+ @_all_load_paths ||= begin
+ load_paths = config.paths.load_paths
+ load_paths += _all_autoload_paths if add_autoload_paths_to_load_path
+ load_paths.uniq
+ end
end
def build_request(env)