activesupport 6.0.0 → 6.0.3
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 +90 -2
- data/README.rdoc +1 -1
- data/lib/active_support/backtrace_cleaner.rb +0 -1
- data/lib/active_support/cache.rb +29 -28
- data/lib/active_support/cache/file_store.rb +7 -8
- data/lib/active_support/cache/mem_cache_store.rb +8 -8
- data/lib/active_support/cache/memory_store.rb +8 -7
- data/lib/active_support/cache/null_store.rb +3 -3
- data/lib/active_support/cache/redis_cache_store.rb +8 -8
- data/lib/active_support/cache/strategy/local_cache.rb +23 -23
- data/lib/active_support/callbacks.rb +0 -3
- data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +18 -0
- data/lib/active_support/concurrency/share_lock.rb +0 -1
- data/lib/active_support/core_ext/array/conversions.rb +5 -5
- data/lib/active_support/core_ext/date_and_time/zones.rb +0 -1
- data/lib/active_support/core_ext/date_time/conversions.rb +0 -1
- data/lib/active_support/core_ext/hash/conversions.rb +1 -1
- data/lib/active_support/core_ext/module/delegation.rb +8 -1
- data/lib/active_support/core_ext/module/introspection.rb +1 -0
- data/lib/active_support/core_ext/object/try.rb +2 -0
- data/lib/active_support/core_ext/range/compare_range.rb +9 -3
- data/lib/active_support/core_ext/range/each.rb +0 -1
- data/lib/active_support/core_ext/range/include_time_with_zone.rb +2 -2
- data/lib/active_support/core_ext/string/output_safety.rb +2 -1
- data/lib/active_support/dependencies.rb +0 -2
- data/lib/active_support/dependencies/zeitwerk_integration.rb +9 -2
- data/lib/active_support/deprecation/method_wrappers.rb +12 -6
- data/lib/active_support/deprecation/proxy_wrappers.rb +5 -1
- data/lib/active_support/descendants_tracker.rb +0 -1
- data/lib/active_support/duration.rb +15 -13
- data/lib/active_support/duration/iso8601_parser.rb +0 -1
- data/lib/active_support/duration/iso8601_serializer.rb +0 -1
- data/lib/active_support/encrypted_file.rb +1 -1
- data/lib/active_support/evented_file_update_checker.rb +0 -1
- data/lib/active_support/file_update_checker.rb +0 -1
- data/lib/active_support/gem_version.rb +1 -1
- data/lib/active_support/i18n_railtie.rb +4 -0
- data/lib/active_support/inflector/inflections.rb +0 -1
- data/lib/active_support/inflector/methods.rb +1 -2
- data/lib/active_support/json/decoding.rb +0 -1
- data/lib/active_support/lazy_load_hooks.rb +0 -1
- data/lib/active_support/locale/en.rb +4 -2
- data/lib/active_support/log_subscriber.rb +0 -1
- data/lib/active_support/logger.rb +1 -1
- data/lib/active_support/message_encryptor.rb +1 -1
- data/lib/active_support/message_verifier.rb +2 -2
- data/lib/active_support/messages/metadata.rb +3 -2
- data/lib/active_support/messages/rotator.rb +4 -4
- data/lib/active_support/multibyte/chars.rb +1 -2
- data/lib/active_support/multibyte/unicode.rb +0 -1
- data/lib/active_support/notifications/instrumenter.rb +4 -4
- data/lib/active_support/number_helper.rb +4 -0
- data/lib/active_support/number_helper/number_converter.rb +4 -5
- data/lib/active_support/number_helper/number_to_currency_converter.rb +7 -8
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +0 -1
- data/lib/active_support/number_helper/number_to_human_converter.rb +0 -1
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +0 -1
- data/lib/active_support/number_helper/number_to_phone_converter.rb +0 -1
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +0 -1
- data/lib/active_support/option_merger.rb +21 -3
- data/lib/active_support/ordered_hash.rb +1 -1
- data/lib/active_support/ordered_options.rb +5 -1
- data/lib/active_support/parameter_filter.rb +1 -2
- data/lib/active_support/string_inquirer.rb +0 -1
- data/lib/active_support/testing/parallelization.rb +8 -2
- data/lib/active_support/testing/stream.rb +0 -1
- data/lib/active_support/testing/time_helpers.rb +0 -2
- data/lib/active_support/xml_mini.rb +0 -1
- data/lib/active_support/xml_mini/jdom.rb +0 -1
- metadata +12 -9
@@ -33,14 +33,14 @@ module ActiveSupport
|
|
33
33
|
end
|
34
34
|
|
35
35
|
private
|
36
|
-
def read_entry(key, options)
|
36
|
+
def read_entry(key, **options)
|
37
37
|
end
|
38
38
|
|
39
|
-
def write_entry(key, entry, options)
|
39
|
+
def write_entry(key, entry, **options)
|
40
40
|
true
|
41
41
|
end
|
42
42
|
|
43
|
-
def delete_entry(key, options)
|
43
|
+
def delete_entry(key, **options)
|
44
44
|
false
|
45
45
|
end
|
46
46
|
end
|
@@ -74,7 +74,7 @@ module ActiveSupport
|
|
74
74
|
# Support raw values in the local cache strategy.
|
75
75
|
module LocalCacheWithRaw # :nodoc:
|
76
76
|
private
|
77
|
-
def read_entry(key, options)
|
77
|
+
def read_entry(key, **options)
|
78
78
|
entry = super
|
79
79
|
if options[:raw] && local_cache && entry
|
80
80
|
entry = deserialize_entry(entry.value)
|
@@ -82,24 +82,24 @@ module ActiveSupport
|
|
82
82
|
entry
|
83
83
|
end
|
84
84
|
|
85
|
-
def write_entry(key, entry, options)
|
85
|
+
def write_entry(key, entry, **options)
|
86
86
|
if options[:raw] && local_cache
|
87
87
|
raw_entry = Entry.new(serialize_entry(entry, raw: true))
|
88
88
|
raw_entry.expires_at = entry.expires_at
|
89
|
-
super(key, raw_entry, options)
|
89
|
+
super(key, raw_entry, **options)
|
90
90
|
else
|
91
91
|
super
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
-
def write_multi_entries(entries, options)
|
95
|
+
def write_multi_entries(entries, **options)
|
96
96
|
if options[:raw] && local_cache
|
97
97
|
raw_entries = entries.map do |key, entry|
|
98
98
|
raw_entry = Entry.new(serialize_entry(entry, raw: true))
|
99
99
|
raw_entry.expires_at = entry.expires_at
|
100
100
|
end.to_h
|
101
101
|
|
102
|
-
super(raw_entries, options)
|
102
|
+
super(raw_entries, **options)
|
103
103
|
else
|
104
104
|
super
|
105
105
|
end
|
@@ -346,13 +346,13 @@ module ActiveSupport
|
|
346
346
|
|
347
347
|
# Store provider interface:
|
348
348
|
# Read an entry from the cache.
|
349
|
-
def read_entry(key, options
|
349
|
+
def read_entry(key, **options)
|
350
350
|
failsafe :read_entry do
|
351
351
|
deserialize_entry redis.with { |c| c.get(key) }
|
352
352
|
end
|
353
353
|
end
|
354
354
|
|
355
|
-
def read_multi_entries(names,
|
355
|
+
def read_multi_entries(names, **options)
|
356
356
|
if mget_capable?
|
357
357
|
read_multi_mget(*names)
|
358
358
|
else
|
@@ -471,7 +471,7 @@ module ActiveSupport
|
|
471
471
|
|
472
472
|
def failsafe(method, returning: nil)
|
473
473
|
yield
|
474
|
-
rescue ::Redis::
|
474
|
+
rescue ::Redis::BaseError => e
|
475
475
|
handle_exception exception: e, method: method, returning: returning
|
476
476
|
returning
|
477
477
|
end
|
@@ -50,27 +50,27 @@ module ActiveSupport
|
|
50
50
|
@data.clear
|
51
51
|
end
|
52
52
|
|
53
|
-
def read_entry(key, options)
|
53
|
+
def read_entry(key, **options)
|
54
54
|
@data[key]
|
55
55
|
end
|
56
56
|
|
57
|
-
def read_multi_entries(keys, options)
|
57
|
+
def read_multi_entries(keys, **options)
|
58
58
|
values = {}
|
59
59
|
|
60
60
|
keys.each do |name|
|
61
|
-
entry = read_entry(name, options)
|
61
|
+
entry = read_entry(name, **options)
|
62
62
|
values[name] = entry.value if entry
|
63
63
|
end
|
64
64
|
|
65
65
|
values
|
66
66
|
end
|
67
67
|
|
68
|
-
def write_entry(key, value, options)
|
68
|
+
def write_entry(key, value, **options)
|
69
69
|
@data[key] = value
|
70
70
|
true
|
71
71
|
end
|
72
72
|
|
73
|
-
def delete_entry(key, options)
|
73
|
+
def delete_entry(key, **options)
|
74
74
|
!!@data.delete(key)
|
75
75
|
end
|
76
76
|
|
@@ -92,34 +92,34 @@ module ActiveSupport
|
|
92
92
|
local_cache_key)
|
93
93
|
end
|
94
94
|
|
95
|
-
def clear(options
|
95
|
+
def clear(**options) # :nodoc:
|
96
96
|
return super unless cache = local_cache
|
97
97
|
cache.clear(options)
|
98
98
|
super
|
99
99
|
end
|
100
100
|
|
101
|
-
def cleanup(options
|
101
|
+
def cleanup(**options) # :nodoc:
|
102
102
|
return super unless cache = local_cache
|
103
103
|
cache.clear
|
104
104
|
super
|
105
105
|
end
|
106
106
|
|
107
|
-
def increment(name, amount = 1, options
|
107
|
+
def increment(name, amount = 1, **options) # :nodoc:
|
108
108
|
return super unless local_cache
|
109
109
|
value = bypass_local_cache { super }
|
110
|
-
write_cache_value(name, value, options)
|
110
|
+
write_cache_value(name, value, **options)
|
111
111
|
value
|
112
112
|
end
|
113
113
|
|
114
|
-
def decrement(name, amount = 1, options
|
114
|
+
def decrement(name, amount = 1, **options) # :nodoc:
|
115
115
|
return super unless local_cache
|
116
116
|
value = bypass_local_cache { super }
|
117
|
-
write_cache_value(name, value, options)
|
117
|
+
write_cache_value(name, value, **options)
|
118
118
|
value
|
119
119
|
end
|
120
120
|
|
121
121
|
private
|
122
|
-
def read_entry(key, options)
|
122
|
+
def read_entry(key, **options)
|
123
123
|
if cache = local_cache
|
124
124
|
cache.fetch_entry(key) { super }
|
125
125
|
else
|
@@ -127,42 +127,42 @@ module ActiveSupport
|
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
130
|
-
def read_multi_entries(keys, options)
|
130
|
+
def read_multi_entries(keys, **options)
|
131
131
|
return super unless local_cache
|
132
132
|
|
133
|
-
local_entries = local_cache.read_multi_entries(keys, options)
|
133
|
+
local_entries = local_cache.read_multi_entries(keys, **options)
|
134
134
|
missed_keys = keys - local_entries.keys
|
135
135
|
|
136
136
|
if missed_keys.any?
|
137
|
-
local_entries.merge!(super(missed_keys, options))
|
137
|
+
local_entries.merge!(super(missed_keys, **options))
|
138
138
|
else
|
139
139
|
local_entries
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
|
-
def write_entry(key, entry, options)
|
143
|
+
def write_entry(key, entry, **options)
|
144
144
|
if options[:unless_exist]
|
145
|
-
local_cache.delete_entry(key, options) if local_cache
|
145
|
+
local_cache.delete_entry(key, **options) if local_cache
|
146
146
|
else
|
147
|
-
local_cache.write_entry(key, entry, options) if local_cache
|
147
|
+
local_cache.write_entry(key, entry, **options) if local_cache
|
148
148
|
end
|
149
149
|
|
150
150
|
super
|
151
151
|
end
|
152
152
|
|
153
|
-
def delete_entry(key, options)
|
154
|
-
local_cache.delete_entry(key, options) if local_cache
|
153
|
+
def delete_entry(key, **options)
|
154
|
+
local_cache.delete_entry(key, **options) if local_cache
|
155
155
|
super
|
156
156
|
end
|
157
157
|
|
158
|
-
def write_cache_value(name, value, options)
|
158
|
+
def write_cache_value(name, value, **options)
|
159
159
|
name = normalize_key(name, options)
|
160
160
|
cache = local_cache
|
161
161
|
cache.mute do
|
162
162
|
if value
|
163
|
-
cache.write(name, value, options)
|
163
|
+
cache.write(name, value, **options)
|
164
164
|
else
|
165
|
-
cache.delete(name, options)
|
165
|
+
cache.delete(name, **options)
|
166
166
|
end
|
167
167
|
end
|
168
168
|
end
|
@@ -142,7 +142,6 @@ module ActiveSupport
|
|
142
142
|
end
|
143
143
|
|
144
144
|
private
|
145
|
-
|
146
145
|
# A hook invoked every time a before callback is halted.
|
147
146
|
# This can be overridden in ActiveSupport::Callbacks implementors in order
|
148
147
|
# to provide better debugging/logging.
|
@@ -582,7 +581,6 @@ module ActiveSupport
|
|
582
581
|
attr_reader :chain
|
583
582
|
|
584
583
|
private
|
585
|
-
|
586
584
|
def append_one(callback)
|
587
585
|
@callbacks = nil
|
588
586
|
remove_duplicates(callback)
|
@@ -843,7 +841,6 @@ module ActiveSupport
|
|
843
841
|
end
|
844
842
|
|
845
843
|
protected
|
846
|
-
|
847
844
|
def get_callbacks(name) # :nodoc:
|
848
845
|
__callbacks[name.to_sym]
|
849
846
|
end
|
@@ -7,11 +7,29 @@ module ActiveSupport
|
|
7
7
|
# A monitor that will permit dependency loading while blocked waiting for
|
8
8
|
# the lock.
|
9
9
|
class LoadInterlockAwareMonitor < Monitor
|
10
|
+
EXCEPTION_NEVER = { Exception => :never }.freeze
|
11
|
+
EXCEPTION_IMMEDIATE = { Exception => :immediate }.freeze
|
12
|
+
private_constant :EXCEPTION_NEVER, :EXCEPTION_IMMEDIATE
|
13
|
+
|
10
14
|
# Enters an exclusive section, but allows dependency loading while blocked
|
11
15
|
def mon_enter
|
12
16
|
mon_try_enter ||
|
13
17
|
ActiveSupport::Dependencies.interlock.permit_concurrent_loads { super }
|
14
18
|
end
|
19
|
+
|
20
|
+
def synchronize
|
21
|
+
Thread.handle_interrupt(EXCEPTION_NEVER) do
|
22
|
+
mon_enter
|
23
|
+
|
24
|
+
begin
|
25
|
+
Thread.handle_interrupt(EXCEPTION_IMMEDIATE) do
|
26
|
+
yield
|
27
|
+
end
|
28
|
+
ensure
|
29
|
+
mon_exit
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
15
33
|
end
|
16
34
|
end
|
17
35
|
end
|
@@ -74,13 +74,13 @@ class Array
|
|
74
74
|
|
75
75
|
case length
|
76
76
|
when 0
|
77
|
-
""
|
77
|
+
+""
|
78
78
|
when 1
|
79
|
-
"#{self[0]}"
|
79
|
+
+"#{self[0]}"
|
80
80
|
when 2
|
81
|
-
"#{self[0]}#{options[:two_words_connector]}#{self[1]}"
|
81
|
+
+"#{self[0]}#{options[:two_words_connector]}#{self[1]}"
|
82
82
|
else
|
83
|
-
"#{self[0...-1].join(options[:words_connector])}#{options[:last_word_connector]}#{self[-1]}"
|
83
|
+
+"#{self[0...-1].join(options[:words_connector])}#{options[:last_word_connector]}#{self[-1]}"
|
84
84
|
end
|
85
85
|
end
|
86
86
|
|
@@ -181,7 +181,7 @@ class Array
|
|
181
181
|
# </messages>
|
182
182
|
#
|
183
183
|
def to_xml(options = {})
|
184
|
-
require "active_support/builder" unless defined?(Builder)
|
184
|
+
require "active_support/builder" unless defined?(Builder::XmlMarkup)
|
185
185
|
|
186
186
|
options = options.dup
|
187
187
|
options[:indent] ||= 2
|
@@ -73,7 +73,7 @@ class Hash
|
|
73
73
|
# configure your own builder with the <tt>:builder</tt> option. The method also accepts
|
74
74
|
# options like <tt>:dasherize</tt> and friends, they are forwarded to the builder.
|
75
75
|
def to_xml(options = {})
|
76
|
-
require "active_support/builder" unless defined?(Builder)
|
76
|
+
require "active_support/builder" unless defined?(Builder::XmlMarkup)
|
77
77
|
|
78
78
|
options = options.dup
|
79
79
|
options[:indent] ||= 2
|
@@ -193,7 +193,13 @@ class Module
|
|
193
193
|
method_names = methods.map do |method|
|
194
194
|
# Attribute writer methods only accept one argument. Makes sure []=
|
195
195
|
# methods still accept two arguments.
|
196
|
-
definition = /[^\]]=$/.match?(method)
|
196
|
+
definition = if /[^\]]=$/.match?(method)
|
197
|
+
"arg"
|
198
|
+
elsif RUBY_VERSION >= "2.7"
|
199
|
+
"..."
|
200
|
+
else
|
201
|
+
"*args, &block"
|
202
|
+
end
|
197
203
|
|
198
204
|
# The following generated method calls the target exactly once, storing
|
199
205
|
# the returned value in a dummy variable.
|
@@ -308,6 +314,7 @@ class Module
|
|
308
314
|
end
|
309
315
|
end
|
310
316
|
end
|
317
|
+
ruby2_keywords(:method_missing) if respond_to?(:ruby2_keywords, true)
|
311
318
|
RUBY
|
312
319
|
end
|
313
320
|
end
|
@@ -15,6 +15,7 @@ module ActiveSupport
|
|
15
15
|
public_send(method_name, *args, &b)
|
16
16
|
end
|
17
17
|
end
|
18
|
+
ruby2_keywords(:try) if respond_to?(:ruby2_keywords, true)
|
18
19
|
|
19
20
|
def try!(method_name = nil, *args, &b)
|
20
21
|
if method_name.nil? && block_given?
|
@@ -27,6 +28,7 @@ module ActiveSupport
|
|
27
28
|
public_send(method_name, *args, &b)
|
28
29
|
end
|
29
30
|
end
|
31
|
+
ruby2_keywords(:try!) if respond_to?(:ruby2_keywords, true)
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
@@ -11,13 +11,15 @@ module ActiveSupport
|
|
11
11
|
# The native Range#=== behavior is untouched.
|
12
12
|
# ('a'..'f') === ('c') # => true
|
13
13
|
# (5..9) === (11) # => false
|
14
|
+
#
|
15
|
+
# The given range must be fully bounded, with both start and end.
|
14
16
|
def ===(value)
|
15
17
|
if value.is_a?(::Range)
|
16
18
|
# 1...10 includes 1..9 but it does not include 1..10.
|
17
19
|
# 1..10 includes 1...11 but it does not include 1...12.
|
18
20
|
operator = exclude_end? && !value.exclude_end? ? :< : :<=
|
19
21
|
value_max = !exclude_end? && value.exclude_end? ? value.max : value.last
|
20
|
-
super(value.first) && value_max.send(operator, last)
|
22
|
+
super(value.first) && (self.end.nil? || value_max.send(operator, last))
|
21
23
|
else
|
22
24
|
super
|
23
25
|
end
|
@@ -32,13 +34,15 @@ module ActiveSupport
|
|
32
34
|
# The native Range#include? behavior is untouched.
|
33
35
|
# ('a'..'f').include?('c') # => true
|
34
36
|
# (5..9).include?(11) # => false
|
37
|
+
#
|
38
|
+
# The given range must be fully bounded, with both start and end.
|
35
39
|
def include?(value)
|
36
40
|
if value.is_a?(::Range)
|
37
41
|
# 1...10 includes 1..9 but it does not include 1..10.
|
38
42
|
# 1..10 includes 1...11 but it does not include 1...12.
|
39
43
|
operator = exclude_end? && !value.exclude_end? ? :< : :<=
|
40
44
|
value_max = !exclude_end? && value.exclude_end? ? value.max : value.last
|
41
|
-
super(value.first) && value_max.send(operator, last)
|
45
|
+
super(value.first) && (self.end.nil? || value_max.send(operator, last))
|
42
46
|
else
|
43
47
|
super
|
44
48
|
end
|
@@ -53,13 +57,15 @@ module ActiveSupport
|
|
53
57
|
# The native Range#cover? behavior is untouched.
|
54
58
|
# ('a'..'f').cover?('c') # => true
|
55
59
|
# (5..9).cover?(11) # => false
|
60
|
+
#
|
61
|
+
# The given range must be fully bounded, with both start and end.
|
56
62
|
def cover?(value)
|
57
63
|
if value.is_a?(::Range)
|
58
64
|
# 1...10 covers 1..9 but it does not cover 1..10.
|
59
65
|
# 1..10 covers 1...11 but it does not cover 1...12.
|
60
66
|
operator = exclude_end? && !value.exclude_end? ? :< : :<=
|
61
67
|
value_max = !exclude_end? && value.exclude_end? ? value.max : value.last
|
62
|
-
super(value.first) && value_max.send(operator, last)
|
68
|
+
super(value.first) && (self.end.nil? || value_max.send(operator, last))
|
63
69
|
else
|
64
70
|
super
|
65
71
|
end
|
@@ -9,9 +9,9 @@ module ActiveSupport
|
|
9
9
|
# (1.hour.ago..1.hour.from_now).include?(Time.current) # => true
|
10
10
|
#
|
11
11
|
def include?(value)
|
12
|
-
if
|
12
|
+
if self.begin.is_a?(TimeWithZone)
|
13
13
|
cover?(value)
|
14
|
-
elsif
|
14
|
+
elsif self.end.is_a?(TimeWithZone)
|
15
15
|
cover?(value)
|
16
16
|
else
|
17
17
|
super
|
@@ -291,13 +291,14 @@ module ActiveSupport #:nodoc:
|
|
291
291
|
end
|
292
292
|
|
293
293
|
private
|
294
|
-
|
295
294
|
def html_escape_interpolated_argument(arg)
|
296
295
|
(!html_safe? || arg.html_safe?) ? arg : CGI.escapeHTML(arg.to_s)
|
297
296
|
end
|
298
297
|
|
299
298
|
def set_block_back_references(block, match_data)
|
300
299
|
block.binding.eval("proc { |m| $~ = m }").call(match_data)
|
300
|
+
rescue ArgumentError
|
301
|
+
# Can't create binding from C level Proc
|
301
302
|
end
|
302
303
|
end
|
303
304
|
end
|