activesupport 7.1.1 → 7.1.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +124 -0
  3. data/lib/active_support/broadcast_logger.rb +8 -0
  4. data/lib/active_support/cache/entry.rb +7 -1
  5. data/lib/active_support/cache/file_store.rb +1 -1
  6. data/lib/active_support/cache/mem_cache_store.rb +16 -8
  7. data/lib/active_support/cache/memory_store.rb +4 -4
  8. data/lib/active_support/cache/redis_cache_store.rb +21 -14
  9. data/lib/active_support/cache/strategy/local_cache.rb +9 -6
  10. data/lib/active_support/cache.rb +34 -7
  11. data/lib/active_support/core_ext/date/conversions.rb +1 -1
  12. data/lib/active_support/core_ext/module/concerning.rb +6 -6
  13. data/lib/active_support/core_ext/object/with_options.rb +1 -1
  14. data/lib/active_support/core_ext/string/indent.rb +1 -1
  15. data/lib/active_support/deprecation/behaviors.rb +18 -16
  16. data/lib/active_support/deprecation/reporting.rb +7 -4
  17. data/lib/active_support/gem_version.rb +2 -2
  18. data/lib/active_support/html_safe_translation.rb +12 -2
  19. data/lib/active_support/inflector/methods.rb +2 -2
  20. data/lib/active_support/json/encoding.rb +1 -1
  21. data/lib/active_support/log_subscriber.rb +8 -2
  22. data/lib/active_support/messages/metadata.rb +1 -1
  23. data/lib/active_support/notifications/fanout.rb +25 -19
  24. data/lib/active_support/number_helper/number_to_human_size_converter.rb +2 -2
  25. data/lib/active_support/number_helper.rb +379 -318
  26. data/lib/active_support/ordered_options.rb +2 -2
  27. data/lib/active_support/syntax_error_proxy.rb +22 -1
  28. data/lib/active_support/testing/assertions.rb +1 -1
  29. data/lib/active_support/testing/strict_warnings.rb +1 -0
  30. data/lib/active_support/testing/time_helpers.rb +5 -1
  31. metadata +6 -6
@@ -7,8 +7,18 @@ module ActiveSupport
7
7
  def translate(key, **options)
8
8
  if html_safe_translation_key?(key)
9
9
  html_safe_options = html_escape_translation_options(options)
10
- translation = I18n.translate(key, **html_safe_options)
11
- html_safe_translation(translation)
10
+
11
+ exception = false
12
+ exception_handler = ->(*args) do
13
+ exception = true
14
+ I18n.exception_handler.call(*args)
15
+ end
16
+ translation = I18n.translate(key, **html_safe_options, exception_handler: exception_handler)
17
+ if exception
18
+ translation
19
+ else
20
+ html_safe_translation(translation)
21
+ end
12
22
  else
13
23
  I18n.translate(key, **options)
14
24
  end
@@ -164,7 +164,7 @@ module ActiveSupport
164
164
  # upcase_first('w') # => "W"
165
165
  # upcase_first('') # => ""
166
166
  def upcase_first(string)
167
- string.length > 0 ? string[0].upcase.concat(string[1..-1]) : ""
167
+ string.length > 0 ? string[0].upcase.concat(string[1..-1]) : +""
168
168
  end
169
169
 
170
170
  # Converts the first character in the string to lowercase.
@@ -173,7 +173,7 @@ module ActiveSupport
173
173
  # downcase_first('I') # => "i"
174
174
  # downcase_first('') # => ""
175
175
  def downcase_first(string)
176
- string.length > 0 ? string[0].downcase.concat(string[1..-1]) : ""
176
+ string.length > 0 ? string[0].downcase.concat(string[1..-1]) : +""
177
177
  end
178
178
 
179
179
  # Capitalizes all the words and replaces some characters in the string to
@@ -76,7 +76,7 @@ module ActiveSupport
76
76
  when Hash
77
77
  result = {}
78
78
  value.each do |k, v|
79
- k = k.to_s unless Symbol === k || String === k
79
+ k = k.to_s unless String === k
80
80
  result[k] = jsonify(v)
81
81
  end
82
82
  result
@@ -86,6 +86,12 @@ module ActiveSupport
86
86
  mattr_accessor :colorize_logging, default: true
87
87
  class_attribute :log_levels, instance_accessor: false, default: {} # :nodoc:
88
88
 
89
+ LEVEL_CHECKS = {
90
+ debug: -> (logger) { !logger.debug? },
91
+ info: -> (logger) { !logger.info? },
92
+ error: -> (logger) { !logger.error? },
93
+ }
94
+
89
95
  class << self
90
96
  def logger
91
97
  @logger ||= if defined?(Rails) && Rails.respond_to?(:logger)
@@ -122,7 +128,7 @@ module ActiveSupport
122
128
  end
123
129
 
124
130
  def subscribe_log_level(method, level)
125
- self.log_levels = log_levels.merge(method => ::Logger.const_get(level.upcase))
131
+ self.log_levels = log_levels.merge(method => LEVEL_CHECKS.fetch(level))
126
132
  set_event_levels
127
133
  end
128
134
  end
@@ -137,7 +143,7 @@ module ActiveSupport
137
143
  end
138
144
 
139
145
  def silenced?(event)
140
- logger.nil? || logger.level > @event_levels.fetch(event, Float::INFINITY)
146
+ logger.nil? || @event_levels[event]&.call(logger)
141
147
  end
142
148
 
143
149
  def call(event)
@@ -82,7 +82,7 @@ module ActiveSupport
82
82
  throw :invalid_message_content, "expired"
83
83
  end
84
84
 
85
- if hash["pur"] != purpose&.to_s
85
+ if hash["pur"].to_s != purpose.to_s
86
86
  throw :invalid_message_content, "mismatched purpose"
87
87
  end
88
88
 
@@ -18,26 +18,30 @@ module ActiveSupport
18
18
  end
19
19
 
20
20
  module FanoutIteration # :nodoc:
21
- def iterate_guarding_exceptions(listeners)
22
- exceptions = nil
23
-
24
- listeners.each do |s|
25
- yield s
26
- rescue Exception => e
27
- exceptions ||= []
28
- exceptions << e
29
- end
21
+ private
22
+ def iterate_guarding_exceptions(collection)
23
+ exceptions = nil
30
24
 
31
- if exceptions
32
- if exceptions.size == 1
33
- raise exceptions.first
34
- else
35
- raise InstrumentationSubscriberError.new(exceptions), cause: exceptions.first
25
+ collection.each do |s|
26
+ yield s
27
+ rescue Exception => e
28
+ exceptions ||= []
29
+ exceptions << e
36
30
  end
37
- end
38
31
 
39
- listeners
40
- end
32
+ if exceptions
33
+ exceptions = exceptions.flat_map do |exception|
34
+ exception.is_a?(InstrumentationSubscriberError) ? exception.exceptions : [exception]
35
+ end
36
+ if exceptions.size == 1
37
+ raise exceptions.first
38
+ else
39
+ raise InstrumentationSubscriberError.new(exceptions), cause: exceptions.first
40
+ end
41
+ end
42
+
43
+ collection
44
+ end
41
45
  end
42
46
 
43
47
  # This is a default queue implementation that ships with Notifications.
@@ -225,6 +229,8 @@ module ActiveSupport
225
229
  # handle.finish
226
230
  # end
227
231
  class Handle
232
+ include FanoutIteration
233
+
228
234
  def initialize(notifier, name, id, payload) # :nodoc:
229
235
  @name = name
230
236
  @id = id
@@ -239,7 +245,7 @@ module ActiveSupport
239
245
  ensure_state! :initialized
240
246
  @state = :started
241
247
 
242
- @groups.each do |group|
248
+ iterate_guarding_exceptions(@groups) do |group|
243
249
  group.start(@name, @id, @payload)
244
250
  end
245
251
  end
@@ -252,7 +258,7 @@ module ActiveSupport
252
258
  ensure_state! :started
253
259
  @state = :finished
254
260
 
255
- @groups.each do |group|
261
+ iterate_guarding_exceptions(@groups) do |group|
256
262
  group.finish(name, id, payload)
257
263
  end
258
264
  end
@@ -43,13 +43,13 @@ module ActiveSupport
43
43
 
44
44
  def exponent
45
45
  max = STORAGE_UNITS.size - 1
46
- exp = (Math.log(number) / Math.log(base)).to_i
46
+ exp = (Math.log(number.abs) / Math.log(base)).to_i
47
47
  exp = max if exp > max # avoid overflow for the highest unit
48
48
  exp
49
49
  end
50
50
 
51
51
  def smaller_than_base?
52
- number.to_i < base
52
+ number.to_i.abs < base
53
53
  end
54
54
 
55
55
  def base