aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG.md41
-rw-r--r--activesupport/lib/active_support/core_ext/array/access.rb8
-rw-r--r--activesupport/lib/active_support/dependencies.rb5
-rw-r--r--activesupport/lib/active_support/dependencies/zeitwerk_integration.rb20
4 files changed, 47 insertions, 27 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index f30249cb3f..db9c7e96f3 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -1,16 +1,25 @@
+* In `:zeitwerk` mode, eager load directories in engines and applications only
+ if present in their respective `config.eager_load_paths`.
+
+ A common use case for this is adding `lib` to `config.autoload_paths`, but
+ not to `config.eager_load_paths`. In that configuration, for example, files
+ in the `lib` directory should not be eager loaded.
+
+ *Xavier Noria*
+
* Fix bug in Range comparisons when comparing to an excluded-end Range
Before:
- (1..10).cover?(1...11) => false
+ (1..10).cover?(1...11) # => false
After:
- (1..10).cover?(1...11) => true
+ (1..10).cover?(1...11) # => true
With the same change for `Range#include?` and `Range#===`.
- *Owen Stephens*
+ *Owen Stephens*
* Use weak references in descendants tracker to allow anonymous subclasses to
be garbage collected.
@@ -27,11 +36,11 @@
* Fix `Time#advance` to work with dates before 1001-03-07
Before:
-
+
Time.utc(1001, 3, 6).advance(years: -1) # => 1000-03-05 00:00:00 UTC
-
+
After
-
+
Time.utc(1001, 3, 6).advance(years: -1) # => 1000-03-06 00:00:00 UTC
Note that this doesn't affect `DateTime#advance` as that doesn't use a proleptic calendar.
@@ -46,27 +55,27 @@
I18n.backend.store_translations(:de, i18n: { transliterate: { rule: { "ü" => "ue" } } })
- ActiveSupport::Inflector.transliterate("ü", locale: :de) => "ue"
- "Fünf autos".parameterize(locale: :de) => "fuenf-autos"
- ActiveSupport::Inflector.parameterize("Fünf autos", locale: :de) => "fuenf-autos"
+ ActiveSupport::Inflector.transliterate("ü", locale: :de) # => "ue"
+ "Fünf autos".parameterize(locale: :de) # => "fuenf-autos"
+ ActiveSupport::Inflector.parameterize("Fünf autos", locale: :de) # => "fuenf-autos"
*Kaan Ozkan*, *Sharang Dashputre*
-* Allow Array#excluding and Enumerable#excluding to deal with a passed array gracefully.
+* Allow `Array#excluding` and `Enumerable#excluding` to deal with a passed array gracefully.
- [ 1, 2, 3, 4, 5 ].excluding([4, 5]) => [ 1, 2, 3 ]
+ [ 1, 2, 3, 4, 5 ].excluding([4, 5]) # => [ 1, 2, 3 ]
*DHH*
-* Renamed Array#without and Enumerable#without to Array#excluding and Enumerable#excluding, to create parity with
- Array#including and Enumerable#including. Retained the old names as aliases.
+* Renamed `Array#without` and `Enumerable#without` to `Array#excluding` and `Enumerable#excluding`, to create parity with
+ `Array#including` and `Enumerable#including`. Retained the old names as aliases.
*DHH*
-* Added Array#including and Enumerable#including to conveniently enlarge a collection with more members using a method rather than an operator:
+* Added `Array#including` and `Enumerable#including` to conveniently enlarge a collection with more members using a method rather than an operator:
- [ 1, 2, 3 ].including(4, 5) => [ 1, 2, 3, 4, 5 ]
- post.authors.including(Current.person) => All the authors plus the current person!
+ [ 1, 2, 3 ].including(4, 5) # => [ 1, 2, 3, 4, 5 ]
+ post.authors.including(Current.person) # => All the authors plus the current person!
*DHH*
diff --git a/activesupport/lib/active_support/core_ext/array/access.rb b/activesupport/lib/active_support/core_ext/array/access.rb
index 10e4c6b09d..ea01e5891c 100644
--- a/activesupport/lib/active_support/core_ext/array/access.rb
+++ b/activesupport/lib/active_support/core_ext/array/access.rb
@@ -31,16 +31,16 @@ class Array
# Returns a new array that includes the passed elements.
#
- # [ 1, 2, 3 ].including(4, 5) => [ 1, 2, 3, 4, 5 ]
- # [ [ 0, 1 ] ].including([ [ 1, 0 ] ]) => [ [ 0, 1 ], [ 1, 0 ] ]
+ # [ 1, 2, 3 ].including(4, 5) # => [ 1, 2, 3, 4, 5 ]
+ # [ [ 0, 1 ] ].including([ [ 1, 0 ] ]) # => [ [ 0, 1 ], [ 1, 0 ] ]
def including(*elements)
self + elements.flatten(1)
end
# Returns a copy of the Array excluding the specified elements.
#
- # ["David", "Rafael", "Aaron", "Todd"].excluding("Aaron", "Todd") => ["David", "Rafael"]
- # [ [ 0, 1 ], [ 1, 0 ] ].excluding([ [ 1, 0 ] ]) => [ [ 0, 1 ] ]
+ # ["David", "Rafael", "Aaron", "Todd"].excluding("Aaron", "Todd") # => ["David", "Rafael"]
+ # [ [ 0, 1 ], [ 1, 0 ] ].excluding([ [ 1, 0 ] ]) # => [ [ 0, 1 ] ]
#
# Note: This is an optimization of <tt>Enumerable#excluding</tt> that uses <tt>Array#-</tt>
# instead of <tt>Array#reject</tt> for performance reasons.
diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb
index d5d00b5e6e..82f07c085e 100644
--- a/activesupport/lib/active_support/dependencies.rb
+++ b/activesupport/lib/active_support/dependencies.rb
@@ -70,6 +70,11 @@ module ActiveSupport #:nodoc:
# only once. All directories in this set must also be present in +autoload_paths+.
mattr_accessor :autoload_once_paths, default: []
+ # This is a private set that collects all eager load paths during bootstrap.
+ # Useful for Zeitwerk integration. Its public interface is the config.* path
+ # accessors of each engine.
+ mattr_accessor :_eager_load_paths, default: Set.new
+
# 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.
diff --git a/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb b/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb
index c6fdade006..a43d03cf09 100644
--- a/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb
+++ b/activesupport/lib/active_support/dependencies/zeitwerk_integration.rb
@@ -1,5 +1,6 @@
# frozen_string_literal: true
+require "set"
require "active_support/core_ext/string/inflections"
module ActiveSupport
@@ -52,7 +53,7 @@ module ActiveSupport
class << self
def take_over
setup_autoloaders
- freeze_autoload_paths
+ freeze_paths
decorate_dependencies
end
@@ -64,11 +65,11 @@ module ActiveSupport
# prevent misconfigurations.
next unless File.directory?(autoload_path)
- if autoload_once?(autoload_path)
- Rails.autoloaders.once.push_dir(autoload_path)
- else
- Rails.autoloaders.main.push_dir(autoload_path)
- end
+ autoloader = \
+ autoload_once?(autoload_path) ? Rails.autoloaders.once : Rails.autoloaders.main
+
+ autoloader.push_dir(autoload_path)
+ autoloader.do_not_eager_load(autoload_path) unless eager_load?(autoload_path)
end
Rails.autoloaders.each(&:setup)
@@ -78,9 +79,14 @@ module ActiveSupport
Dependencies.autoload_once_paths.include?(autoload_path)
end
- def freeze_autoload_paths
+ def eager_load?(autoload_path)
+ Dependencies._eager_load_paths.member?(autoload_path)
+ end
+
+ def freeze_paths
Dependencies.autoload_paths.freeze
Dependencies.autoload_once_paths.freeze
+ Dependencies._eager_load_paths.freeze
end
def decorate_dependencies