activesupport 5.2.4.4 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activesupport might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +327 -408
- data/MIT-LICENSE +1 -1
- data/README.rdoc +3 -2
- data/lib/active_support.rb +2 -1
- data/lib/active_support/actionable_error.rb +48 -0
- data/lib/active_support/backtrace_cleaner.rb +28 -1
- data/lib/active_support/cache.rb +45 -23
- data/lib/active_support/cache/file_store.rb +22 -22
- data/lib/active_support/cache/mem_cache_store.rb +17 -2
- data/lib/active_support/cache/memory_store.rb +7 -2
- data/lib/active_support/cache/null_store.rb +5 -0
- data/lib/active_support/cache/redis_cache_store.rb +47 -25
- data/lib/active_support/callbacks.rb +16 -5
- data/lib/active_support/concern.rb +24 -1
- data/lib/active_support/configurable.rb +7 -11
- data/lib/active_support/core_ext/array.rb +1 -1
- data/lib/active_support/core_ext/array/access.rb +18 -6
- data/lib/active_support/core_ext/array/extract.rb +21 -0
- data/lib/active_support/core_ext/array/prepend_and_append.rb +2 -6
- data/lib/active_support/core_ext/class/attribute.rb +11 -16
- data/lib/active_support/core_ext/class/subclasses.rb +1 -1
- data/lib/active_support/core_ext/date/calculations.rb +6 -5
- data/lib/active_support/core_ext/date_and_time/calculations.rb +24 -47
- data/lib/active_support/core_ext/date_time/calculations.rb +1 -1
- data/lib/active_support/core_ext/enumerable.rb +97 -73
- data/lib/active_support/core_ext/hash.rb +1 -2
- data/lib/active_support/core_ext/hash/compact.rb +2 -26
- data/lib/active_support/core_ext/hash/deep_transform_values.rb +46 -0
- data/lib/active_support/core_ext/hash/except.rb +1 -1
- data/lib/active_support/core_ext/hash/keys.rb +0 -29
- data/lib/active_support/core_ext/hash/slice.rb +3 -25
- data/lib/active_support/core_ext/hash/transform_values.rb +2 -29
- data/lib/active_support/core_ext/integer/multiple.rb +1 -1
- data/lib/active_support/core_ext/kernel.rb +0 -1
- data/lib/active_support/core_ext/load_error.rb +1 -1
- data/lib/active_support/core_ext/module.rb +0 -1
- data/lib/active_support/core_ext/module/attribute_accessors.rb +7 -10
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +13 -19
- data/lib/active_support/core_ext/module/delegation.rb +33 -7
- data/lib/active_support/core_ext/module/introspection.rb +37 -13
- data/lib/active_support/core_ext/module/reachable.rb +1 -6
- data/lib/active_support/core_ext/module/redefine_method.rb +8 -17
- data/lib/active_support/core_ext/numeric.rb +0 -1
- data/lib/active_support/core_ext/numeric/conversions.rb +124 -128
- data/lib/active_support/core_ext/numeric/inquiry.rb +2 -25
- data/lib/active_support/core_ext/object/blank.rb +1 -2
- data/lib/active_support/core_ext/object/duplicable.rb +7 -114
- data/lib/active_support/core_ext/object/json.rb +1 -0
- data/lib/active_support/core_ext/object/try.rb +15 -7
- data/lib/active_support/core_ext/object/with_options.rb +1 -1
- data/lib/active_support/core_ext/range/compare_range.rb +22 -13
- data/lib/active_support/core_ext/range/conversions.rb +31 -29
- data/lib/active_support/core_ext/range/include_range.rb +6 -0
- data/lib/active_support/core_ext/regexp.rb +0 -4
- data/lib/active_support/core_ext/securerandom.rb +23 -3
- data/lib/active_support/core_ext/string/access.rb +8 -0
- data/lib/active_support/core_ext/string/filters.rb +42 -1
- data/lib/active_support/core_ext/string/inflections.rb +7 -2
- data/lib/active_support/core_ext/string/multibyte.rb +4 -3
- data/lib/active_support/core_ext/string/output_safety.rb +61 -5
- data/lib/active_support/core_ext/string/strip.rb +3 -1
- data/lib/active_support/core_ext/time/calculations.rb +31 -2
- data/lib/active_support/core_ext/uri.rb +1 -0
- data/lib/active_support/current_attributes.rb +8 -0
- data/lib/active_support/dependencies.rb +69 -16
- data/lib/active_support/dependencies/zeitwerk_integration.rb +110 -0
- data/lib/active_support/deprecation.rb +1 -1
- data/lib/active_support/deprecation/behaviors.rb +1 -1
- data/lib/active_support/deprecation/method_wrappers.rb +8 -20
- data/lib/active_support/deprecation/proxy_wrappers.rb +24 -5
- data/lib/active_support/descendants_tracker.rb +56 -9
- data/lib/active_support/duration.rb +4 -3
- data/lib/active_support/duration/iso8601_parser.rb +2 -3
- data/lib/active_support/duration/iso8601_serializer.rb +3 -4
- data/lib/active_support/encrypted_configuration.rb +0 -4
- data/lib/active_support/encrypted_file.rb +2 -1
- data/lib/active_support/evented_file_update_checker.rb +39 -9
- data/lib/active_support/execution_wrapper.rb +1 -0
- data/lib/active_support/gem_version.rb +4 -4
- data/lib/active_support/hash_with_indifferent_access.rb +22 -18
- data/lib/active_support/i18n.rb +1 -0
- data/lib/active_support/i18n_railtie.rb +9 -1
- data/lib/active_support/inflector/inflections.rb +1 -4
- data/lib/active_support/inflector/methods.rb +15 -27
- data/lib/active_support/inflector/transliterate.rb +47 -18
- data/lib/active_support/json/decoding.rb +23 -23
- data/lib/active_support/json/encoding.rb +6 -2
- data/lib/active_support/key_generator.rb +0 -32
- data/lib/active_support/lazy_load_hooks.rb +5 -1
- data/lib/active_support/locale/en.rb +31 -0
- data/lib/active_support/log_subscriber.rb +31 -8
- data/lib/active_support/logger.rb +0 -15
- data/lib/active_support/logger_silence.rb +28 -12
- data/lib/active_support/logger_thread_safe_level.rb +26 -4
- data/lib/active_support/message_encryptor.rb +3 -5
- data/lib/active_support/message_verifier.rb +3 -3
- data/lib/active_support/multibyte/chars.rb +29 -48
- data/lib/active_support/multibyte/unicode.rb +44 -281
- data/lib/active_support/notifications.rb +41 -4
- data/lib/active_support/notifications/fanout.rb +98 -13
- data/lib/active_support/notifications/instrumenter.rb +79 -8
- data/lib/active_support/number_helper.rb +7 -0
- data/lib/active_support/number_helper/number_to_currency_converter.rb +2 -2
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +3 -1
- data/lib/active_support/number_helper/number_to_human_converter.rb +3 -1
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +3 -1
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +3 -1
- data/lib/active_support/number_helper/number_to_phone_converter.rb +2 -0
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +5 -3
- data/lib/active_support/ordered_options.rb +1 -1
- data/lib/active_support/parameter_filter.rb +129 -0
- data/lib/active_support/rails.rb +0 -6
- data/lib/active_support/reloader.rb +4 -5
- data/lib/active_support/security_utils.rb +1 -1
- data/lib/active_support/subscriber.rb +65 -26
- data/lib/active_support/tagged_logging.rb +13 -4
- data/lib/active_support/test_case.rb +91 -0
- data/lib/active_support/testing/assertions.rb +15 -1
- data/lib/active_support/testing/deprecation.rb +0 -1
- data/lib/active_support/testing/file_fixtures.rb +2 -0
- data/lib/active_support/testing/isolation.rb +2 -2
- data/lib/active_support/testing/method_call_assertions.rb +28 -1
- data/lib/active_support/testing/parallelization.rb +128 -0
- data/lib/active_support/testing/stream.rb +1 -1
- data/lib/active_support/testing/time_helpers.rb +7 -7
- data/lib/active_support/time_with_zone.rb +15 -5
- data/lib/active_support/values/time_zone.rb +12 -7
- data/lib/active_support/xml_mini.rb +2 -9
- data/lib/active_support/xml_mini/jdom.rb +2 -2
- data/lib/active_support/xml_mini/libxml.rb +2 -2
- data/lib/active_support/xml_mini/libxmlsax.rb +4 -4
- data/lib/active_support/xml_mini/nokogiri.rb +2 -2
- data/lib/active_support/xml_mini/nokogirisax.rb +3 -3
- data/lib/active_support/xml_mini/rexml.rb +2 -2
- metadata +34 -9
- data/lib/active_support/core_ext/kernel/agnostics.rb +0 -13
- data/lib/active_support/values/unicode_tables.dat +0 -0
@@ -20,6 +20,8 @@ class String
|
|
20
20
|
# Technically, it looks for the least indented non-empty line
|
21
21
|
# in the whole string, and removes that amount of leading whitespace.
|
22
22
|
def strip_heredoc
|
23
|
-
gsub(/^#{scan(/^[ \t]*(?=\S)/).min}/, "".
|
23
|
+
gsub(/^#{scan(/^[ \t]*(?=\S)/).min}/, "").tap do |stripped|
|
24
|
+
stripped.freeze if frozen?
|
25
|
+
end
|
24
26
|
end
|
25
27
|
end
|
@@ -170,8 +170,7 @@ class Time
|
|
170
170
|
options[:hours] = options.fetch(:hours, 0) + 24 * partial_days
|
171
171
|
end
|
172
172
|
|
173
|
-
d = to_date.advance(options)
|
174
|
-
d = d.gregorian if d.julian?
|
173
|
+
d = to_date.gregorian.advance(options)
|
175
174
|
time_advanced_by_date = change(year: d.year, month: d.month, day: d.day)
|
176
175
|
seconds_to_advance = \
|
177
176
|
options.fetch(:seconds, 0) +
|
@@ -312,4 +311,34 @@ class Time
|
|
312
311
|
end
|
313
312
|
alias_method :eql_without_coercion, :eql?
|
314
313
|
alias_method :eql?, :eql_with_coercion
|
314
|
+
|
315
|
+
# Returns a new time the specified number of days ago.
|
316
|
+
def prev_day(days = 1)
|
317
|
+
advance(days: -days)
|
318
|
+
end
|
319
|
+
|
320
|
+
# Returns a new time the specified number of days in the future.
|
321
|
+
def next_day(days = 1)
|
322
|
+
advance(days: days)
|
323
|
+
end
|
324
|
+
|
325
|
+
# Returns a new time the specified number of months ago.
|
326
|
+
def prev_month(months = 1)
|
327
|
+
advance(months: -months)
|
328
|
+
end
|
329
|
+
|
330
|
+
# Returns a new time the specified number of months in the future.
|
331
|
+
def next_month(months = 1)
|
332
|
+
advance(months: months)
|
333
|
+
end
|
334
|
+
|
335
|
+
# Returns a new time the specified number of years ago.
|
336
|
+
def prev_year(years = 1)
|
337
|
+
advance(years: -years)
|
338
|
+
end
|
339
|
+
|
340
|
+
# Returns a new time the specified number of years in the future.
|
341
|
+
def next_year(years = 1)
|
342
|
+
advance(years: years)
|
343
|
+
end
|
315
344
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "active_support/callbacks"
|
4
|
+
|
3
5
|
module ActiveSupport
|
4
6
|
# Abstract super class that provides a thread-isolated attributes singleton, which resets automatically
|
5
7
|
# before and after each request. This allows you to keep all the per-request attributes easily
|
@@ -117,10 +119,16 @@ module ActiveSupport
|
|
117
119
|
end
|
118
120
|
end
|
119
121
|
|
122
|
+
# Calls this block before #reset is called on the instance. Used for resetting external collaborators that depend on current values.
|
123
|
+
def before_reset(&block)
|
124
|
+
set_callback :reset, :before, &block
|
125
|
+
end
|
126
|
+
|
120
127
|
# Calls this block after #reset is called on the instance. Used for resetting external collaborators, like Time.zone.
|
121
128
|
def resets(&block)
|
122
129
|
set_callback :reset, :after, &block
|
123
130
|
end
|
131
|
+
alias_method :after_reset, :resets
|
124
132
|
|
125
133
|
delegate :set, :reset, to: :instance
|
126
134
|
|
@@ -20,6 +20,9 @@ module ActiveSupport #:nodoc:
|
|
20
20
|
module Dependencies #:nodoc:
|
21
21
|
extend self
|
22
22
|
|
23
|
+
UNBOUND_METHOD_MODULE_NAME = Module.instance_method(:name)
|
24
|
+
private_constant :UNBOUND_METHOD_MODULE_NAME
|
25
|
+
|
23
26
|
mattr_accessor :interlock, default: Interlock.new
|
24
27
|
|
25
28
|
# :doc:
|
@@ -70,6 +73,11 @@ module ActiveSupport #:nodoc:
|
|
70
73
|
# only once. All directories in this set must also be present in +autoload_paths+.
|
71
74
|
mattr_accessor :autoload_once_paths, default: []
|
72
75
|
|
76
|
+
# This is a private set that collects all eager load paths during bootstrap.
|
77
|
+
# Useful for Zeitwerk integration. Its public interface is the config.* path
|
78
|
+
# accessors of each engine.
|
79
|
+
mattr_accessor :_eager_load_paths, default: Set.new
|
80
|
+
|
73
81
|
# An array of qualified constant names that have been loaded. Adding a name
|
74
82
|
# to this array will cause it to be unloaded the next time Dependencies are
|
75
83
|
# cleared.
|
@@ -79,6 +87,12 @@ module ActiveSupport #:nodoc:
|
|
79
87
|
# to allow arbitrary constants to be marked for unloading.
|
80
88
|
mattr_accessor :explicitly_unloadable_constants, default: []
|
81
89
|
|
90
|
+
# The logger used when tracing autoloads.
|
91
|
+
mattr_accessor :logger
|
92
|
+
|
93
|
+
# If true, trace autoloads with +logger.debug+.
|
94
|
+
mattr_accessor :verbose, default: false
|
95
|
+
|
82
96
|
# The WatchStack keeps a stack of the modules being watched as files are
|
83
97
|
# loaded. If a file in the process of being loaded (parent.rb) triggers the
|
84
98
|
# load of another file (child.rb) the stack will ensure that child.rb
|
@@ -140,7 +154,7 @@ module ActiveSupport #:nodoc:
|
|
140
154
|
|
141
155
|
# Normalize the list of new constants, and add them to the list we will return
|
142
156
|
new_constants.each do |suffix|
|
143
|
-
constants << ([namespace, suffix] - ["Object"]).join("::"
|
157
|
+
constants << ([namespace, suffix] - ["Object"]).join("::")
|
144
158
|
end
|
145
159
|
end
|
146
160
|
constants
|
@@ -190,6 +204,11 @@ module ActiveSupport #:nodoc:
|
|
190
204
|
end
|
191
205
|
end
|
192
206
|
|
207
|
+
def self.include_into(base)
|
208
|
+
base.include(self)
|
209
|
+
append_features(base)
|
210
|
+
end
|
211
|
+
|
193
212
|
def const_missing(const_name)
|
194
213
|
from_mod = anonymous? ? guess_for_anonymous(const_name) : self
|
195
214
|
Dependencies.load_missing_constant(from_mod, const_name)
|
@@ -219,6 +238,21 @@ module ActiveSupport #:nodoc:
|
|
219
238
|
base.class_eval do
|
220
239
|
define_method(:load, Kernel.instance_method(:load))
|
221
240
|
private :load
|
241
|
+
|
242
|
+
define_method(:require, Kernel.instance_method(:require))
|
243
|
+
private :require
|
244
|
+
end
|
245
|
+
end
|
246
|
+
|
247
|
+
def self.include_into(base)
|
248
|
+
base.include(self)
|
249
|
+
|
250
|
+
if base.instance_method(:load).owner == base
|
251
|
+
base.remove_method(:load)
|
252
|
+
end
|
253
|
+
|
254
|
+
if base.instance_method(:require).owner == base
|
255
|
+
base.remove_method(:require)
|
222
256
|
end
|
223
257
|
end
|
224
258
|
|
@@ -315,9 +349,9 @@ module ActiveSupport #:nodoc:
|
|
315
349
|
end
|
316
350
|
|
317
351
|
def hook!
|
318
|
-
Object
|
319
|
-
Module
|
320
|
-
Exception.
|
352
|
+
Loadable.include_into(Object)
|
353
|
+
ModuleConstMissing.include_into(Module)
|
354
|
+
Exception.include(Blamable)
|
321
355
|
end
|
322
356
|
|
323
357
|
def unhook!
|
@@ -349,7 +383,7 @@ module ActiveSupport #:nodoc:
|
|
349
383
|
end
|
350
384
|
|
351
385
|
def require_or_load(file_name, const_path = nil)
|
352
|
-
file_name =
|
386
|
+
file_name = file_name.chomp(".rb")
|
353
387
|
expanded = File.expand_path(file_name)
|
354
388
|
return if loaded.include?(expanded)
|
355
389
|
|
@@ -399,7 +433,7 @@ module ActiveSupport #:nodoc:
|
|
399
433
|
# constant paths which would cause Dependencies to attempt to load this
|
400
434
|
# file.
|
401
435
|
def loadable_constants_for_path(path, bases = autoload_paths)
|
402
|
-
path =
|
436
|
+
path = path.chomp(".rb")
|
403
437
|
expanded_path = File.expand_path(path)
|
404
438
|
paths = []
|
405
439
|
|
@@ -408,7 +442,7 @@ module ActiveSupport #:nodoc:
|
|
408
442
|
next unless expanded_path.start_with?(expanded_root)
|
409
443
|
|
410
444
|
root_size = expanded_root.size
|
411
|
-
next if expanded_path[root_size] !=
|
445
|
+
next if expanded_path[root_size] != ?/
|
412
446
|
|
413
447
|
nesting = expanded_path[(root_size + 1)..-1]
|
414
448
|
paths << nesting.camelize unless nesting.blank?
|
@@ -420,7 +454,7 @@ module ActiveSupport #:nodoc:
|
|
420
454
|
|
421
455
|
# Search for a file in autoload_paths matching the provided suffix.
|
422
456
|
def search_for_file(path_suffix)
|
423
|
-
path_suffix
|
457
|
+
path_suffix += ".rb" unless path_suffix.ends_with?(".rb")
|
424
458
|
|
425
459
|
autoload_paths.each do |root|
|
426
460
|
path = File.join(root, path_suffix)
|
@@ -454,6 +488,7 @@ module ActiveSupport #:nodoc:
|
|
454
488
|
return nil unless base_path = autoloadable_module?(path_suffix)
|
455
489
|
mod = Module.new
|
456
490
|
into.const_set const_name, mod
|
491
|
+
log("constant #{qualified_name} autoloaded (module autovivified from #{File.join(base_path, path_suffix)})")
|
457
492
|
autoloaded_constants << qualified_name unless autoload_once_paths.include?(base_path)
|
458
493
|
autoloaded_constants.uniq!
|
459
494
|
mod
|
@@ -495,26 +530,31 @@ module ActiveSupport #:nodoc:
|
|
495
530
|
raise ArgumentError, "A copy of #{from_mod} has been removed from the module tree but is still active!"
|
496
531
|
end
|
497
532
|
|
498
|
-
qualified_name = qualified_name_for
|
533
|
+
qualified_name = qualified_name_for(from_mod, const_name)
|
499
534
|
path_suffix = qualified_name.underscore
|
500
535
|
|
501
536
|
file_path = search_for_file(path_suffix)
|
502
537
|
|
503
538
|
if file_path
|
504
539
|
expanded = File.expand_path(file_path)
|
505
|
-
expanded.sub!(/\.rb\z/, ""
|
540
|
+
expanded.sub!(/\.rb\z/, "")
|
506
541
|
|
507
542
|
if loading.include?(expanded)
|
508
543
|
raise "Circular dependency detected while autoloading constant #{qualified_name}"
|
509
544
|
else
|
510
545
|
require_or_load(expanded, qualified_name)
|
511
|
-
|
512
|
-
|
546
|
+
|
547
|
+
if from_mod.const_defined?(const_name, false)
|
548
|
+
log("constant #{qualified_name} autoloaded from #{expanded}.rb")
|
549
|
+
return from_mod.const_get(const_name)
|
550
|
+
else
|
551
|
+
raise LoadError, "Unable to autoload constant #{qualified_name}, expected #{file_path} to define it"
|
552
|
+
end
|
513
553
|
end
|
514
554
|
elsif mod = autoload_module!(from_mod, const_name, qualified_name, path_suffix)
|
515
555
|
return mod
|
516
|
-
elsif (parent = from_mod.
|
517
|
-
! from_mod.
|
556
|
+
elsif (parent = from_mod.module_parent) && parent != from_mod &&
|
557
|
+
! from_mod.module_parents.any? { |p| p.const_defined?(const_name, false) }
|
518
558
|
# If our parents do not have a constant named +const_name+ then we are free
|
519
559
|
# to attempt to load upwards. If they do have such a constant, then this
|
520
560
|
# const_missing must be due to from_mod::const_name, which should not
|
@@ -558,6 +598,7 @@ module ActiveSupport #:nodoc:
|
|
558
598
|
# as the environment will be in an inconsistent state, e.g. other constants
|
559
599
|
# may have already been unloaded and not accessible.
|
560
600
|
def remove_unloadable_constants!
|
601
|
+
log("removing unloadable constants")
|
561
602
|
autoloaded_constants.each { |const| remove_constant const }
|
562
603
|
autoloaded_constants.clear
|
563
604
|
Reference.clear!
|
@@ -621,7 +662,7 @@ module ActiveSupport #:nodoc:
|
|
621
662
|
|
622
663
|
# Determine if the given constant has been automatically loaded.
|
623
664
|
def autoloaded?(desc)
|
624
|
-
return false if desc.is_a?(Module) && desc.
|
665
|
+
return false if desc.is_a?(Module) && real_mod_name(desc).nil?
|
625
666
|
name = to_constant_name desc
|
626
667
|
return false unless qualified_const_defined?(name)
|
627
668
|
autoloaded_constants.include?(name)
|
@@ -677,7 +718,7 @@ module ActiveSupport #:nodoc:
|
|
677
718
|
when String then desc.sub(/^::/, "")
|
678
719
|
when Symbol then desc.to_s
|
679
720
|
when Module
|
680
|
-
desc
|
721
|
+
real_mod_name(desc) ||
|
681
722
|
raise(ArgumentError, "Anonymous modules have no name to be referenced by")
|
682
723
|
else raise TypeError, "Not a valid constant descriptor: #{desc.inspect}"
|
683
724
|
end
|
@@ -747,6 +788,18 @@ module ActiveSupport #:nodoc:
|
|
747
788
|
# The constant is no longer reachable, just skip it.
|
748
789
|
end
|
749
790
|
end
|
791
|
+
|
792
|
+
def log(message)
|
793
|
+
logger.debug("autoloading: #{message}") if logger && verbose
|
794
|
+
end
|
795
|
+
|
796
|
+
private
|
797
|
+
|
798
|
+
# Returns the original name of a class or module even if `name` has been
|
799
|
+
# overridden.
|
800
|
+
def real_mod_name(mod)
|
801
|
+
UNBOUND_METHOD_MODULE_NAME.bind(mod).call
|
802
|
+
end
|
750
803
|
end
|
751
804
|
end
|
752
805
|
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "set"
|
4
|
+
require "active_support/core_ext/string/inflections"
|
5
|
+
|
6
|
+
module ActiveSupport
|
7
|
+
module Dependencies
|
8
|
+
module ZeitwerkIntegration # :nodoc: all
|
9
|
+
module Decorations
|
10
|
+
def clear
|
11
|
+
Dependencies.unload_interlock do
|
12
|
+
Rails.autoloaders.main.reload
|
13
|
+
rescue Zeitwerk::ReloadingDisabledError
|
14
|
+
raise "reloading is disabled because config.cache_classes is true"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def constantize(cpath)
|
19
|
+
ActiveSupport::Inflector.constantize(cpath)
|
20
|
+
end
|
21
|
+
|
22
|
+
def safe_constantize(cpath)
|
23
|
+
ActiveSupport::Inflector.safe_constantize(cpath)
|
24
|
+
end
|
25
|
+
|
26
|
+
def autoloaded_constants
|
27
|
+
Rails.autoloaders.main.unloadable_cpaths
|
28
|
+
end
|
29
|
+
|
30
|
+
def autoloaded?(object)
|
31
|
+
cpath = object.is_a?(Module) ? real_mod_name(object) : object.to_s
|
32
|
+
Rails.autoloaders.main.unloadable_cpath?(cpath)
|
33
|
+
end
|
34
|
+
|
35
|
+
def verbose=(verbose)
|
36
|
+
l = verbose ? logger || Rails.logger : nil
|
37
|
+
Rails.autoloaders.each { |autoloader| autoloader.logger = l }
|
38
|
+
end
|
39
|
+
|
40
|
+
def unhook!
|
41
|
+
:no_op
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
module RequireDependency
|
46
|
+
def require_dependency(filename)
|
47
|
+
filename = filename.to_path if filename.respond_to?(:to_path)
|
48
|
+
if abspath = ActiveSupport::Dependencies.search_for_file(filename)
|
49
|
+
require abspath
|
50
|
+
else
|
51
|
+
require filename
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
module Inflector
|
57
|
+
def self.camelize(basename, _abspath)
|
58
|
+
basename.camelize
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class << self
|
63
|
+
def take_over(enable_reloading:)
|
64
|
+
setup_autoloaders(enable_reloading)
|
65
|
+
freeze_paths
|
66
|
+
decorate_dependencies
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def setup_autoloaders(enable_reloading)
|
72
|
+
Dependencies.autoload_paths.each do |autoload_path|
|
73
|
+
# Zeitwerk only accepts existing directories in `push_dir` to
|
74
|
+
# prevent misconfigurations.
|
75
|
+
next unless File.directory?(autoload_path)
|
76
|
+
|
77
|
+
autoloader = \
|
78
|
+
autoload_once?(autoload_path) ? Rails.autoloaders.once : Rails.autoloaders.main
|
79
|
+
|
80
|
+
autoloader.push_dir(autoload_path)
|
81
|
+
autoloader.do_not_eager_load(autoload_path) unless eager_load?(autoload_path)
|
82
|
+
end
|
83
|
+
|
84
|
+
Rails.autoloaders.main.enable_reloading if enable_reloading
|
85
|
+
Rails.autoloaders.each(&:setup)
|
86
|
+
end
|
87
|
+
|
88
|
+
def autoload_once?(autoload_path)
|
89
|
+
Dependencies.autoload_once_paths.include?(autoload_path)
|
90
|
+
end
|
91
|
+
|
92
|
+
def eager_load?(autoload_path)
|
93
|
+
Dependencies._eager_load_paths.member?(autoload_path)
|
94
|
+
end
|
95
|
+
|
96
|
+
def freeze_paths
|
97
|
+
Dependencies.autoload_paths.freeze
|
98
|
+
Dependencies.autoload_once_paths.freeze
|
99
|
+
Dependencies._eager_load_paths.freeze
|
100
|
+
end
|
101
|
+
|
102
|
+
def decorate_dependencies
|
103
|
+
Dependencies.unhook!
|
104
|
+
Dependencies.singleton_class.prepend(Decorations)
|
105
|
+
Object.prepend(RequireDependency)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -35,7 +35,7 @@ module ActiveSupport
|
|
35
35
|
# and the second is a library name.
|
36
36
|
#
|
37
37
|
# ActiveSupport::Deprecation.new('2.0', 'MyLibrary')
|
38
|
-
def initialize(deprecation_horizon = "6.
|
38
|
+
def initialize(deprecation_horizon = "6.1", gem_name = "Rails")
|
39
39
|
self.gem_name = gem_name
|
40
40
|
self.deprecation_horizon = deprecation_horizon
|
41
41
|
# By default, warnings are not silenced and debugging is off.
|
@@ -43,7 +43,7 @@ module ActiveSupport
|
|
43
43
|
deprecation_horizon: deprecation_horizon)
|
44
44
|
},
|
45
45
|
|
46
|
-
silence: ->(message, callstack, deprecation_horizon, gem_name) {},
|
46
|
+
silence: ->(message, callstack, deprecation_horizon, gem_name) { },
|
47
47
|
}
|
48
48
|
|
49
49
|
# Behavior module allows to determine how to display deprecation messages.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "active_support/core_ext/module/aliasing"
|
4
3
|
require "active_support/core_ext/array/extract_options"
|
4
|
+
require "active_support/core_ext/module/redefine_method"
|
5
5
|
|
6
6
|
module ActiveSupport
|
7
7
|
class Deprecation
|
@@ -53,37 +53,25 @@ module ActiveSupport
|
|
53
53
|
options = method_names.extract_options!
|
54
54
|
deprecator = options.delete(:deprecator) || self
|
55
55
|
method_names += options.keys
|
56
|
-
mod =
|
56
|
+
mod = nil
|
57
57
|
|
58
58
|
method_names.each do |method_name|
|
59
59
|
if target_module.method_defined?(method_name) || target_module.private_method_defined?(method_name)
|
60
|
-
|
61
|
-
|
62
|
-
without_method = "#{aliased_method}_without_deprecation#{punctuation}"
|
63
|
-
|
64
|
-
target_module.send(:define_method, with_method) do |*args, &block|
|
60
|
+
method = target_module.instance_method(method_name)
|
61
|
+
target_module.redefine_method(method_name) do |*args, &block|
|
65
62
|
deprecator.deprecation_warning(method_name, options[method_name])
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
target_module.send(:alias_method, without_method, method_name)
|
70
|
-
target_module.send(:alias_method, method_name, with_method)
|
71
|
-
|
72
|
-
case
|
73
|
-
when target_module.protected_method_defined?(without_method)
|
74
|
-
target_module.send(:protected, method_name)
|
75
|
-
when target_module.private_method_defined?(without_method)
|
76
|
-
target_module.send(:private, method_name)
|
63
|
+
method.bind(self).call(*args, &block)
|
77
64
|
end
|
78
65
|
else
|
79
|
-
mod
|
66
|
+
mod ||= Module.new
|
67
|
+
mod.define_method(method_name) do |*args, &block|
|
80
68
|
deprecator.deprecation_warning(method_name, options[method_name])
|
81
69
|
super(*args, &block)
|
82
70
|
end
|
83
71
|
end
|
84
72
|
end
|
85
73
|
|
86
|
-
target_module.prepend(mod)
|
74
|
+
target_module.prepend(mod) if mod
|
87
75
|
end
|
88
76
|
end
|
89
77
|
end
|