activesupport 7.1.2 → 7.1.5

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 (32) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +134 -0
  3. data/lib/active_support/backtrace_cleaner.rb +5 -0
  4. data/lib/active_support/broadcast_logger.rb +15 -14
  5. data/lib/active_support/cache/mem_cache_store.rb +6 -6
  6. data/lib/active_support/cache/memory_store.rb +4 -4
  7. data/lib/active_support/cache/redis_cache_store.rb +16 -12
  8. data/lib/active_support/cache/strategy/local_cache.rb +9 -6
  9. data/lib/active_support/cache.rb +17 -6
  10. data/lib/active_support/code_generator.rb +15 -10
  11. data/lib/active_support/core_ext/module/delegation.rb +41 -26
  12. data/lib/active_support/core_ext/object/duplicable.rb +24 -15
  13. data/lib/active_support/core_ext/object/json.rb +5 -3
  14. data/lib/active_support/core_ext/object/with_options.rb +1 -1
  15. data/lib/active_support/core_ext/string/indent.rb +1 -1
  16. data/lib/active_support/deprecation/behaviors.rb +18 -16
  17. data/lib/active_support/deprecation/reporting.rb +8 -5
  18. data/lib/active_support/gem_version.rb +1 -1
  19. data/lib/active_support/html_safe_translation.rb +16 -6
  20. data/lib/active_support/log_subscriber.rb +1 -0
  21. data/lib/active_support/messages/codec.rb +1 -1
  22. data/lib/active_support/notifications/instrumenter.rb +11 -3
  23. data/lib/active_support/number_helper.rb +379 -318
  24. data/lib/active_support/railtie.rb +3 -3
  25. data/lib/active_support/syntax_error_proxy.rb +12 -1
  26. data/lib/active_support/tagged_logging.rb +4 -0
  27. data/lib/active_support/testing/assertions.rb +1 -1
  28. data/lib/active_support/testing/setup_and_teardown.rb +2 -0
  29. data/lib/active_support/testing/time_helpers.rb +4 -0
  30. data/lib/active_support/values/time_zone.rb +9 -0
  31. data/lib/active_support.rb +1 -1
  32. metadata +51 -9
@@ -57,15 +57,15 @@ module ActiveSupport
57
57
  # You can create a custom behavior or set any from the +DEFAULT_BEHAVIORS+
58
58
  # constant. Available behaviors are:
59
59
  #
60
- # [+raise+] Raise ActiveSupport::DeprecationException.
61
- # [+stderr+] Log all deprecation warnings to <tt>$stderr</tt>.
62
- # [+log+] Log all deprecation warnings to +Rails.logger+.
63
- # [+notify+] Use ActiveSupport::Notifications to notify +deprecation.rails+.
64
- # [+report+] Use ActiveSupport::ErrorReporter to report deprecations.
65
- # [+silence+] Do nothing. On \Rails, set <tt>config.active_support.report_deprecations = false</tt> to disable all behaviors.
60
+ # [+:raise+] Raise ActiveSupport::DeprecationException.
61
+ # [+:stderr+] Log all deprecation warnings to <tt>$stderr</tt>.
62
+ # [+:log+] Log all deprecation warnings to +Rails.logger+.
63
+ # [+:notify+] Use ActiveSupport::Notifications to notify +deprecation.rails+.
64
+ # [+:report+] Use ActiveSupport::ErrorReporter to report deprecations.
65
+ # [+:silence+] Do nothing. On \Rails, set <tt>config.active_support.report_deprecations = false</tt> to disable all behaviors.
66
66
  #
67
67
  # Setting behaviors only affects deprecations that happen after boot time.
68
- # For more information you can read the documentation of the +behavior=+ method.
68
+ # For more information you can read the documentation of the #behavior= method.
69
69
  module Behavior
70
70
  # Whether to print a backtrace along with the warning.
71
71
  attr_accessor :debug
@@ -85,12 +85,12 @@ module ActiveSupport
85
85
  #
86
86
  # Available behaviors:
87
87
  #
88
- # [+raise+] Raise ActiveSupport::DeprecationException.
89
- # [+stderr+] Log all deprecation warnings to <tt>$stderr</tt>.
90
- # [+log+] Log all deprecation warnings to +Rails.logger+.
91
- # [+notify+] Use ActiveSupport::Notifications to notify +deprecation.rails+.
92
- # [+report+] Use ActiveSupport::ErrorReporter to report deprecations.
93
- # [+silence+] Do nothing.
88
+ # [+:raise+] Raise ActiveSupport::DeprecationException.
89
+ # [+:stderr+] Log all deprecation warnings to <tt>$stderr</tt>.
90
+ # [+:log+] Log all deprecation warnings to +Rails.logger+.
91
+ # [+:notify+] Use ActiveSupport::Notifications to notify +deprecation.rails+.
92
+ # [+:report+] Use ActiveSupport::ErrorReporter to report deprecations.
93
+ # [+:silence+] Do nothing.
94
94
  #
95
95
  # Setting behaviors only affects deprecations that happen after boot time.
96
96
  # Deprecation warnings raised by gems are not affected by this setting
@@ -104,15 +104,17 @@ module ActiveSupport
104
104
  # # custom stuff
105
105
  # }
106
106
  #
107
- # If you are using \Rails, you can set <tt>config.active_support.report_deprecations = false</tt> to disable
108
- # all deprecation behaviors. This is similar to the +silence+ option but more performant.
107
+ # If you are using \Rails, you can set
108
+ # <tt>config.active_support.report_deprecations = false</tt> to disable
109
+ # all deprecation behaviors. This is similar to the +:silence+ option but
110
+ # more performant.
109
111
  def behavior=(behavior)
110
112
  @behavior = Array(behavior).map { |b| DEFAULT_BEHAVIORS[b] || arity_coerce(b) }
111
113
  end
112
114
 
113
115
  # Sets the behavior for disallowed deprecations (those configured by
114
116
  # ActiveSupport::Deprecation#disallowed_warnings=) to the specified
115
- # value. As with +behavior=+, this can be a single value, array, or an
117
+ # value. As with #behavior=, this can be a single value, array, or an
116
118
  # object that responds to +call+.
117
119
  def disallowed_behavior=(behavior)
118
120
  @disallowed_behavior = Array(behavior).map { |b| DEFAULT_BEHAVIORS[b] || arity_coerce(b) }
@@ -142,7 +142,9 @@ module ActiveSupport
142
142
  return _extract_callstack(callstack) if callstack.first.is_a? String
143
143
 
144
144
  offending_line = callstack.find { |frame|
145
- frame.absolute_path && !ignored_callstack(frame.absolute_path)
145
+ # Code generated with `eval` doesn't have an `absolute_path`, e.g. templates.
146
+ path = frame.absolute_path || frame.path
147
+ path && !ignored_callstack?(path)
146
148
  } || callstack.first
147
149
 
148
150
  [offending_line.path, offending_line.lineno, offending_line.label]
@@ -150,7 +152,7 @@ module ActiveSupport
150
152
 
151
153
  def _extract_callstack(callstack)
152
154
  warn "Please pass `caller_locations` to the deprecation API" if $VERBOSE
153
- offending_line = callstack.find { |line| !ignored_callstack(line) } || callstack.first
155
+ offending_line = callstack.find { |line| !ignored_callstack?(line) } || callstack.first
154
156
 
155
157
  if offending_line
156
158
  if md = offending_line.match(/^(.+?):(\d+)(?::in `(.*?)')?/)
@@ -161,10 +163,11 @@ module ActiveSupport
161
163
  end
162
164
  end
163
165
 
164
- RAILS_GEM_ROOT = File.expand_path("../../../..", __dir__) + "/"
166
+ RAILS_GEM_ROOT = File.expand_path("../../../..", __dir__) + "/" # :nodoc:
167
+ LIB_DIR = RbConfig::CONFIG["libdir"] # :nodoc:
165
168
 
166
- def ignored_callstack(path)
167
- path.start_with?(RAILS_GEM_ROOT) || path.start_with?(RbConfig::CONFIG["rubylibdir"])
169
+ def ignored_callstack?(path)
170
+ path.start_with?(RAILS_GEM_ROOT, LIB_DIR)
168
171
  end
169
172
  end
170
173
  end
@@ -9,7 +9,7 @@ module ActiveSupport
9
9
  module VERSION
10
10
  MAJOR = 7
11
11
  MINOR = 1
12
- TINY = 2
12
+ TINY = 5
13
13
  PRE = nil
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
@@ -7,18 +7,28 @@ 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
15
25
  end
16
26
 
17
- private
18
- def html_safe_translation_key?(key)
19
- /(?:_|\b)html\z/.match?(key)
20
- end
27
+ def html_safe_translation_key?(key)
28
+ /(?:_|\b)html\z/.match?(key)
29
+ end
21
30
 
31
+ private
22
32
  def html_escape_translation_options(options)
23
33
  options.each do |name, value|
24
34
  unless i18n_option?(name) || (name == :count && value.is_a?(Numeric))
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "active_support/core_ext/module/attribute_accessors"
4
4
  require "active_support/core_ext/class/attribute"
5
+ require "active_support/core_ext/enumerable"
5
6
  require "active_support/subscriber"
6
7
  require "active_support/deprecation/proxy_wrappers"
7
8
 
@@ -28,7 +28,7 @@ module ActiveSupport
28
28
 
29
29
  def decode(encoded, url_safe: @url_safe)
30
30
  url_safe ? ::Base64.urlsafe_decode64(encoded) : ::Base64.strict_decode64(encoded)
31
- rescue ArgumentError => error
31
+ rescue StandardError => error
32
32
  throw :invalid_message_format, error
33
33
  end
34
34
 
@@ -104,7 +104,7 @@ module ActiveSupport
104
104
  end
105
105
 
106
106
  class Event
107
- attr_reader :name, :time, :end, :transaction_id
107
+ attr_reader :name, :transaction_id
108
108
  attr_accessor :payload
109
109
 
110
110
  def initialize(name, start, ending, transaction_id, payload)
@@ -119,7 +119,15 @@ module ActiveSupport
119
119
  @allocation_count_finish = 0
120
120
  end
121
121
 
122
- def record
122
+ def time
123
+ @time / 1000.0 if @time
124
+ end
125
+
126
+ def end
127
+ @end / 1000.0 if @end
128
+ end
129
+
130
+ def record # :nodoc:
123
131
  start!
124
132
  begin
125
133
  yield payload if block_given?
@@ -195,7 +203,7 @@ module ActiveSupport
195
203
  #
196
204
  # @event.duration # => 1000.138
197
205
  def duration
198
- self.end - time
206
+ @end - @time
199
207
  end
200
208
 
201
209
  private