activesupport 7.2.1 → 8.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +67 -189
  3. data/lib/active_support/backtrace_cleaner.rb +1 -1
  4. data/lib/active_support/benchmark.rb +21 -0
  5. data/lib/active_support/benchmarkable.rb +3 -2
  6. data/lib/active_support/broadcast_logger.rb +14 -14
  7. data/lib/active_support/cache/file_store.rb +12 -2
  8. data/lib/active_support/cache/memory_store.rb +6 -2
  9. data/lib/active_support/cache/redis_cache_store.rb +5 -2
  10. data/lib/active_support/cache.rb +18 -13
  11. data/lib/active_support/callbacks.rb +1 -2
  12. data/lib/active_support/class_attribute.rb +26 -0
  13. data/lib/active_support/code_generator.rb +9 -0
  14. data/lib/active_support/concurrency/share_lock.rb +0 -1
  15. data/lib/active_support/configuration_file.rb +15 -6
  16. data/lib/active_support/core_ext/benchmark.rb +6 -9
  17. data/lib/active_support/core_ext/class/attribute.rb +10 -19
  18. data/lib/active_support/core_ext/date/conversions.rb +2 -0
  19. data/lib/active_support/core_ext/date_and_time/compatibility.rb +2 -2
  20. data/lib/active_support/core_ext/enumerable.rb +8 -3
  21. data/lib/active_support/core_ext/hash/except.rb +0 -12
  22. data/lib/active_support/core_ext/module/attr_internal.rb +3 -4
  23. data/lib/active_support/core_ext/object/json.rb +20 -12
  24. data/lib/active_support/core_ext/string/multibyte.rb +1 -1
  25. data/lib/active_support/core_ext/thread/backtrace/location.rb +2 -7
  26. data/lib/active_support/core_ext/time/calculations.rb +14 -2
  27. data/lib/active_support/core_ext/time/compatibility.rb +9 -1
  28. data/lib/active_support/core_ext/time/conversions.rb +2 -0
  29. data/lib/active_support/core_ext/time/zones.rb +1 -1
  30. data/lib/active_support/current_attributes.rb +7 -3
  31. data/lib/active_support/delegation.rb +0 -2
  32. data/lib/active_support/dependencies.rb +0 -1
  33. data/lib/active_support/deprecation/reporting.rb +2 -21
  34. data/lib/active_support/deprecation.rb +1 -1
  35. data/lib/active_support/duration.rb +14 -10
  36. data/lib/active_support/encrypted_configuration.rb +20 -2
  37. data/lib/active_support/encrypted_file.rb +1 -1
  38. data/lib/active_support/error_reporter.rb +25 -1
  39. data/lib/active_support/evented_file_update_checker.rb +0 -1
  40. data/lib/active_support/gem_version.rb +3 -3
  41. data/lib/active_support/hash_with_indifferent_access.rb +16 -16
  42. data/lib/active_support/i18n_railtie.rb +19 -11
  43. data/lib/active_support/isolated_execution_state.rb +0 -2
  44. data/lib/active_support/json/encoding.rb +2 -2
  45. data/lib/active_support/notifications/fanout.rb +0 -1
  46. data/lib/active_support/number_helper.rb +22 -0
  47. data/lib/active_support/railtie.rb +4 -0
  48. data/lib/active_support/tagged_logging.rb +5 -0
  49. data/lib/active_support/testing/assertions.rb +79 -21
  50. data/lib/active_support/testing/isolation.rb +2 -2
  51. data/lib/active_support/testing/parallelization/server.rb +3 -0
  52. data/lib/active_support/testing/strict_warnings.rb +3 -0
  53. data/lib/active_support/testing/time_helpers.rb +2 -1
  54. data/lib/active_support/time_with_zone.rb +22 -13
  55. data/lib/active_support/values/time_zone.rb +17 -15
  56. data/lib/active_support.rb +10 -3
  57. metadata +40 -11
  58. data/lib/active_support/proxy_object.rb +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f87ceb32cd8ca6e8edc650d3951112271df9849a1a6d03e2637c55f33d9dcde3
4
- data.tar.gz: 17fa74b2c99d9d3b27a28be44da050cf1363c474083bee2be7a8e2330ad4134f
3
+ metadata.gz: 8d43c6938627c736f544a0a9f0af6f8a538e8dd6c147ff51e368946c4d57d7c4
4
+ data.tar.gz: 6e57c37c1735b475cb5a2d96c0af1ed0f6f2f2d41a776743bc97cc0b61e4b778
5
5
  SHA512:
6
- metadata.gz: 325172ee84f0822ac38da2fff3c8c078efb4cc27684e0cb22865197e62f6dbe412a41e59fb6e1b46788772e6f8381e57c5b973f322bcbd66e1cb3ec7970f4a43
7
- data.tar.gz: ce7f3de0f2438f5df87040d5019f4d95625657072065d7f60f05eaf072db9bde8d35b6ce54eddb3f0fc1f715b75065484e2c3cc02bbae401cdbbc4d479e99c26
6
+ metadata.gz: c01d045e73ab8eb2c3a3494180490bb5fa39a082343d5445593bd591333cd95cca84ad0d79668afe6603389ac675c8cbe3f98a0bb5612bfb5a3ec8d77fa26d9b
7
+ data.tar.gz: b5a92add8986b7bb4f73a5e7c4ff82525dfcfb4a1ca0bcedb6364a338f88cb5b411595c1704d508d68ad0ed2df850788132a2270e4f1421d672b1394c49e8306
data/CHANGELOG.md CHANGED
@@ -1,258 +1,136 @@
1
- ## Rails 7.2.1 (August 22, 2024) ##
1
+ ## Rails 8.0.0 (November 07, 2024) ##
2
2
 
3
3
  * No changes.
4
4
 
5
5
 
6
- ## Rails 7.2.0 (August 09, 2024) ##
6
+ ## Rails 8.0.0.rc2 (October 30, 2024) ##
7
7
 
8
- * Fix `delegate_missing_to allow_nil: true` when called with implict self
9
-
10
- ```ruby
11
- class Person
12
- delegate_missing_to :address, allow_nil: true
13
-
14
- def address
15
- nil
16
- end
17
-
18
- def berliner?
19
- city == "Berlin"
20
- end
21
- end
22
-
23
- Person.new.city # => nil
24
- Person.new.berliner? # undefined local variable or method `city' for an instance of Person (NameError)
25
- ```
26
-
27
- *Jean Boussier*
28
-
29
- * Add `logger` as a dependency since it is a bundled gem candidate for Ruby 3.5
30
-
31
- *Earlopain*
32
-
33
- * Define `Digest::UUID.nil_uuid`, which returns the so-called nil UUID.
34
-
35
- *Xavier Noria*
36
-
37
- * Support `duration` type in `ActiveSupport::XmlMini`.
38
-
39
- *heka1024*
40
-
41
- * Remove deprecated `ActiveSupport::Notifications::Event#children` and `ActiveSupport::Notifications::Event#parent_of?`.
42
-
43
- *Rafael Mendonça França*
44
-
45
- * Remove deprecated support to call the following methods without passing a deprecator:
46
-
47
- - `deprecate`
48
- - `deprecate_constant`
49
- - `ActiveSupport::Deprecation::DeprecatedObjectProxy.new`
50
- - `ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new`
51
- - `ActiveSupport::Deprecation::DeprecatedConstantProxy.new`
52
- - `assert_deprecated`
53
- - `assert_not_deprecated`
54
- - `collect_deprecations`
55
-
56
- *Rafael Mendonça França*
57
-
58
- * Remove deprecated `ActiveSupport::Deprecation` delegation to instance.
59
-
60
- *Rafael Mendonça França*
61
-
62
- * Remove deprecated `SafeBuffer#clone_empty`.
63
-
64
- *Rafael Mendonça França*
65
-
66
- * Remove deprecated `#to_default_s` from `Array`, `Date`, `DateTime` and `Time`.
67
-
68
- *Rafael Mendonça França*
69
-
70
- * Remove deprecated support to passing `Dalli::Client` instances to `MemCacheStore`.
71
-
72
- *Rafael Mendonça França*
73
-
74
- * Remove deprecated `config.active_support.use_rfc4122_namespaced_uuids`.
75
-
76
- *Rafael Mendonça França*
77
-
78
- * Remove deprecated `config.active_support.remove_deprecated_time_with_zone_name`.
79
-
80
- *Rafael Mendonça França*
81
-
82
- * Remove deprecated `config.active_support.disable_to_s_conversion`.
83
-
84
- *Rafael Mendonça França*
8
+ * No changes.
85
9
 
86
- * Remove deprecated support to bolding log text with positional boolean in `ActiveSupport::LogSubscriber#color`.
87
10
 
88
- *Rafael Mendonça França*
11
+ ## Rails 8.0.0.rc1 (October 19, 2024) ##
89
12
 
90
- * Remove deprecated constants `ActiveSupport::LogSubscriber::CLEAR` and `ActiveSupport::LogSubscriber::BOLD`.
13
+ * Remove deprecated support to passing an array of strings to `ActiveSupport::Deprecation#warn`.
91
14
 
92
15
  *Rafael Mendonça França*
93
16
 
94
- * Remove deprecated support for `config.active_support.cache_format_version = 6.1`.
17
+ * Remove deprecated support to setting `attr_internal_naming_format` with a `@` prefix.
95
18
 
96
19
  *Rafael Mendonça França*
97
20
 
98
- * Remove deprecated `:pool_size` and `:pool_timeout` options for the cache storage.
21
+ * Remove deprecated `ActiveSupport::ProxyObject`.
99
22
 
100
23
  *Rafael Mendonça França*
101
24
 
102
- * Warn on tests without assertions.
103
-
104
- `ActiveSupport::TestCase` now warns when tests do not run any assertions.
105
- This is helpful in detecting broken tests that do not perform intended assertions.
106
-
107
- *fatkodima*
108
-
109
- * Support `hexBinary` type in `ActiveSupport::XmlMini`.
25
+ * Don't execute i18n watcher on boot. It shouldn't catch any file changes initially,
26
+ and unnecessarily slows down boot of applications with lots of translations.
110
27
 
111
- *heka1024*
28
+ *Gannon McGibbon*, *David Stosik*
112
29
 
113
- * Deprecate `ActiveSupport::ProxyObject` in favor of Ruby's built-in `BasicObject`.
30
+ * Fix `ActiveSupport::HashWithIndifferentAccess#stringify_keys` to stringify all keys not just symbols.
114
31
 
115
- *Earlopain*
116
-
117
- * `stub_const` now accepts a `exists: false` parameter to allow stubbing missing constants.
118
-
119
- *Jean Boussier*
120
-
121
- * Make `ActiveSupport::BacktraceCleaner` copy filters and silencers on dup and clone.
32
+ Previously:
122
33
 
123
- Previously the copy would still share the internal silencers and filters array,
124
- causing state to leak.
125
-
126
- *Jean Boussier*
127
-
128
- * Updating Astana with Western Kazakhstan TZInfo identifier.
129
-
130
- *Damian Nelson*
34
+ ```ruby
35
+ { 1 => 2 }.with_indifferent_access.stringify_keys[1] # => 2
36
+ ```
131
37
 
132
- * Add filename support for `ActiveSupport::Logger.logger_outputs_to?`.
38
+ After this change:
133
39
 
134
40
  ```ruby
135
- logger = Logger.new('/var/log/rails.log')
136
- ActiveSupport::Logger.logger_outputs_to?(logger, '/var/log/rails.log')
41
+ { 1 => 2 }.with_indifferent_access.stringify_keys["1"] # => 2
137
42
  ```
138
43
 
139
- *Christian Schmidt*
44
+ This change can be seen as a bug fix, but since it behaved like this for a very long time, we're deciding
45
+ to not backport the fix and to make the change in a major release.
140
46
 
141
- * Include `IPAddr#prefix` when serializing an `IPAddr` using the
142
- `ActiveSupport::MessagePack` serializer.
47
+ *Jean Boussier*
143
48
 
144
- This change is backward and forward compatible — old payloads can
145
- still be read, and new payloads will be readable by older versions of Rails.
49
+ ## Rails 8.0.0.beta1 (September 26, 2024) ##
146
50
 
147
- *Taiki Komaba*
51
+ * Include options when instrumenting `ActiveSupport::Cache::Store#delete` and `ActiveSupport::Cache::Store#delete_multi`.
148
52
 
149
- * Add `default:` support for `ActiveSupport::CurrentAttributes.attribute`.
53
+ *Adam Renberg Tamm*
150
54
 
151
- ```ruby
152
- class Current < ActiveSupport::CurrentAttributes
153
- attribute :counter, default: 0
154
- end
155
- ```
55
+ * Print test names when running `rails test -v` for parallel tests.
156
56
 
157
- *Sean Doyle*
57
+ *John Hawthorn*, *Abeid Ahmed*
158
58
 
159
- * Yield instance to `Object#with` block.
59
+ * Deprecate `Benchmark.ms` core extension.
160
60
 
161
- ```ruby
162
- client.with(timeout: 5_000) do |c|
163
- c.get("/commits")
164
- end
165
- ```
61
+ The `benchmark` gem will become bundled in Ruby 3.5
166
62
 
167
- *Sean Doyle*
63
+ *Earlopain*
168
64
 
169
- * Use logical core count instead of physical core count to determine the
170
- default number of workers when parallelizing tests.
65
+ * `ActiveSupport::TimeWithZone#inspect` now uses ISO 8601 style time like `Time#inspect`
171
66
 
172
- *Jonathan Hefner*
67
+ *John Hawthorn*
173
68
 
174
- * Fix `Time.now/DateTime.now/Date.today` to return results in a system timezone after `#travel_to`.
69
+ * `ActiveSupport::ErrorReporter#report` now assigns a backtrace to unraised exceptions.
175
70
 
176
- There is a bug in the current implementation of #travel_to:
177
- it remembers a timezone of its argument, and all stubbed methods start
178
- returning results in that remembered timezone. However, the expected
179
- behavior is to return results in a system timezone.
71
+ Previously reporting an un-raised exception would result in an error report without
72
+ a backtrace. Now it automatically generates one.
180
73
 
181
- *Aleksei Chernenkov*
74
+ *Jean Boussier*
182
75
 
183
- * Add `ErrorReported#unexpected` to report precondition violations.
76
+ * Add `escape_html_entities` option to `ActiveSupport::JSON.encode`.
184
77
 
185
- For example:
78
+ This allows for overriding the global configuration found at
79
+ `ActiveSupport.escape_html_entities_in_json` for specific calls to `to_json`.
186
80
 
81
+ This should be usable from controllers in the following manner:
187
82
  ```ruby
188
- def edit
189
- if published?
190
- Rails.error.unexpected("[BUG] Attempting to edit a published article, that shouldn't be possible")
191
- return false
83
+ class MyController < ApplicationController
84
+ def index
85
+ render json: { hello: "world" }, escape_html_entities: false
192
86
  end
193
- # ...
194
87
  end
195
88
  ```
196
89
 
197
- The above will raise an error in development and test, but only report the error in production.
198
-
199
- *Jean Boussier*
200
-
201
- * Make the order of read_multi and write_multi notifications for `Cache::Store#fetch_multi` operations match the order they are executed in.
202
-
203
- *Adam Renberg Tamm*
204
-
205
- * Make return values of `Cache::Store#write` consistent.
206
-
207
- The return value was not specified before. Now it returns `true` on a successful write,
208
- `nil` if there was an error talking to the cache backend, and `false` if the write failed
209
- for another reason (e.g. the key already exists and `unless_exist: true` was passed).
90
+ *Nigel Baillie*
210
91
 
211
- *Sander Verdonschot*
92
+ * Raise when using key which can't respond to `#to_sym` in `EncryptedConfiguration`.
212
93
 
213
- * Fix logged cache keys not always matching actual key used by cache action.
94
+ As is the case when trying to use an Integer or Float as a key, which is unsupported.
214
95
 
215
- *Hartley McGuire*
96
+ *zzak*
216
97
 
217
- * Improve error messages of `assert_changes` and `assert_no_changes`.
98
+ * Deprecate addition and since between two `Time` and `ActiveSupport::TimeWithZone`.
218
99
 
219
- `assert_changes` error messages now display objects with `.inspect` to make it easier
220
- to differentiate nil from empty strings, strings from symbols, etc.
221
- `assert_no_changes` error messages now surface the actual value.
100
+ Previously adding time instances together such as `10.days.ago + 10.days.ago` or `10.days.ago.since(10.days.ago)` produced a nonsensical future date. This behavior is deprecated and will be removed in Rails 8.1.
222
101
 
223
- *pcreux*
102
+ *Nick Schwaderer*
224
103
 
225
- * Fix `#to_fs(:human_size)` to correctly work with negative numbers.
226
-
227
- *Earlopain*
104
+ * Support rfc2822 format for Time#to_fs & Date#to_fs.
228
105
 
229
- * Fix `BroadcastLogger#dup` so that it duplicates the logger's `broadcasts`.
106
+ *Akshay Birajdar*
230
107
 
231
- *Andrew Novoselac*
108
+ * Optimize load time for `Railtie#initialize_i18n`. Filter `I18n.load_path`s passed to the file watcher to only those
109
+ under `Rails.root`. Previously the watcher would grab all available locales, including those in gems
110
+ which do not require a watcher because they won't change.
232
111
 
233
- * Fix issue where `bootstrap.rb` overwrites the `level` of a `BroadcastLogger`'s `broadcasts`.
112
+ *Nick Schwaderer*
234
113
 
235
- *Andrew Novoselac*
114
+ * Add a `filter` option to `in_order_of` to prioritize certain values in the sorting without filtering the results
115
+ by these values.
236
116
 
237
- * Fix compatibility with the `semantic_logger` gem.
117
+ *Igor Depolli*
238
118
 
239
- The `semantic_logger` gem doesn't behave exactly like stdlib logger in that
240
- `SemanticLogger#level` returns a Symbol while stdlib `Logger#level` returns an Integer.
119
+ * Improve error message when using `assert_difference` or `assert_changes` with a
120
+ proc by printing the proc's source code (MRI only).
241
121
 
242
- This caused the various `LogSubscriber` classes in Rails to break when assigned a
243
- `SemanticLogger` instance.
122
+ *Richard Böhme*, *Jean Boussier*
244
123
 
245
- *Jean Boussier*, *ojab*
124
+ * Add a new configuration value `:zone` for `ActiveSupport.to_time_preserves_timezone` and rename the previous `true` value to `:offset`. The new default value is `:zone`.
246
125
 
247
- * Fix MemoryStore to prevent race conditions when incrementing or decrementing.
126
+ *Jason Kim*, *John Hawthorn*
248
127
 
249
- *Pierre Jambet*
128
+ * Align instrumentation `payload[:key]` in ActiveSupport::Cache to follow the same pattern, with namespaced and normalized keys.
250
129
 
251
- * Implement `HashWithIndifferentAccess#to_proc`.
130
+ *Frederik Erbs Spang Thomsen*
252
131
 
253
- Previously, calling `#to_proc` on `HashWithIndifferentAccess` object used inherited `#to_proc`
254
- method from the `Hash` class, which was not able to access values using indifferent keys.
132
+ * Fix `travel_to` to set usec 0 when `with_usec` is `false` and the given argument String or DateTime.
255
133
 
256
- *fatkodima*
134
+ *mopp*
257
135
 
258
- Please check [7-1-stable](https://github.com/rails/rails/blob/7-1-stable/activesupport/CHANGELOG.md) for previous changes.
136
+ Please check [7-2-stable](https://github.com/rails/rails/blob/7-2-stable/activesupport/CHANGELOG.md) for previous changes.
@@ -18,7 +18,7 @@ module ActiveSupport
18
18
  #
19
19
  # bc = ActiveSupport::BacktraceCleaner.new
20
20
  # root = "#{Rails.root}/"
21
- # bc.add_filter { |line| line.start_with?(root) ? line.from(root.size) : line } # strip the Rails.root prefix
21
+ # bc.add_filter { |line| line.delete_prefix(root) } # strip the Rails.root prefix
22
22
  # bc.add_silencer { |line| /puma|rubygems/.match?(line) } # skip any lines from puma or rubygems
23
23
  # bc.clean(exception.backtrace) # perform the cleanup
24
24
  #
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveSupport
4
+ module Benchmark # :nodoc:
5
+ # Benchmark realtime in the specified time unit. By default,
6
+ # the returned unit is in seconds.
7
+ #
8
+ # ActiveSupport::Benchmark.realtime { sleep 0.1 }
9
+ # # => 0.10007
10
+ #
11
+ # ActiveSupport::Benchmark.realtime(:float_millisecond) { sleep 0.1 }
12
+ # # => 100.07
13
+ #
14
+ # `unit` can be any of the values accepted by Ruby's `Process.clock_gettime`.
15
+ def self.realtime(unit = :float_second, &block)
16
+ time_start = Process.clock_gettime(Process::CLOCK_MONOTONIC, unit)
17
+ yield
18
+ Process.clock_gettime(Process::CLOCK_MONOTONIC, unit) - time_start
19
+ end
20
+ end
21
+ end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/core_ext/benchmark"
4
3
  require "active_support/core_ext/hash/keys"
5
4
 
6
5
  module ActiveSupport
@@ -41,7 +40,9 @@ module ActiveSupport
41
40
  options[:level] ||= :info
42
41
 
43
42
  result = nil
44
- ms = Benchmark.ms { result = options[:silence] ? logger.silence(&block) : yield }
43
+ ms = ActiveSupport::Benchmark.realtime(:float_millisecond) do
44
+ result = options[:silence] ? logger.silence(&block) : yield
45
+ end
45
46
  logger.public_send(options[:level], "%s (%.1fms)" % [ message, ms ])
46
47
  result
47
48
  else
@@ -113,33 +113,33 @@ module ActiveSupport
113
113
  dispatch { |logger| logger.<<(message) }
114
114
  end
115
115
 
116
- def add(*args, &block)
117
- dispatch { |logger| logger.add(*args, &block) }
116
+ def add(...)
117
+ dispatch { |logger| logger.add(...) }
118
118
  end
119
119
  alias_method :log, :add
120
120
 
121
- def debug(*args, &block)
122
- dispatch { |logger| logger.debug(*args, &block) }
121
+ def debug(...)
122
+ dispatch { |logger| logger.debug(...) }
123
123
  end
124
124
 
125
- def info(*args, &block)
126
- dispatch { |logger| logger.info(*args, &block) }
125
+ def info(...)
126
+ dispatch { |logger| logger.info(...) }
127
127
  end
128
128
 
129
- def warn(*args, &block)
130
- dispatch { |logger| logger.warn(*args, &block) }
129
+ def warn(...)
130
+ dispatch { |logger| logger.warn(...) }
131
131
  end
132
132
 
133
- def error(*args, &block)
134
- dispatch { |logger| logger.error(*args, &block) }
133
+ def error(...)
134
+ dispatch { |logger| logger.error(...) }
135
135
  end
136
136
 
137
- def fatal(*args, &block)
138
- dispatch { |logger| logger.fatal(*args, &block) }
137
+ def fatal(...)
138
+ dispatch { |logger| logger.fatal(...) }
139
139
  end
140
140
 
141
- def unknown(*args, &block)
142
- dispatch { |logger| logger.unknown(*args, &block) }
141
+ def unknown(...)
142
+ dispatch { |logger| logger.unknown(...) }
143
143
  end
144
144
 
145
145
  def formatter=(formatter)
@@ -58,7 +58,12 @@ module ActiveSupport
58
58
  # cache.increment("baz") # => 6
59
59
  #
60
60
  def increment(name, amount = 1, options = nil)
61
- modify_value(name, amount, options)
61
+ options = merged_options(options)
62
+ key = normalize_key(name, options)
63
+
64
+ instrument(:increment, key, amount: amount) do
65
+ modify_value(name, amount, options)
66
+ end
62
67
  end
63
68
 
64
69
  # Decrement a cached integer value. Returns the updated value.
@@ -73,7 +78,12 @@ module ActiveSupport
73
78
  # cache.decrement("baz") # => 4
74
79
  #
75
80
  def decrement(name, amount = 1, options = nil)
76
- modify_value(name, -amount, options)
81
+ options = merged_options(options)
82
+ key = normalize_key(name, options)
83
+
84
+ instrument(:decrement, key, amount: amount) do
85
+ modify_value(name, -amount, options)
86
+ end
77
87
  end
78
88
 
79
89
  def delete_matched(matcher, options = nil)
@@ -147,7 +147,9 @@ module ActiveSupport
147
147
  # cache.increment("baz") # => 6
148
148
  #
149
149
  def increment(name, amount = 1, options = nil)
150
- modify_value(name, amount, options)
150
+ instrument(:increment, name, amount: amount) do
151
+ modify_value(name, amount, options)
152
+ end
151
153
  end
152
154
 
153
155
  # Decrement a cached integer value. Returns the updated value.
@@ -162,7 +164,9 @@ module ActiveSupport
162
164
  # cache.decrement("baz") # => 4
163
165
  #
164
166
  def decrement(name, amount = 1, options = nil)
165
- modify_value(name, -amount, options)
167
+ instrument(:decrement, name, amount: amount) do
168
+ modify_value(name, -amount, options)
169
+ end
166
170
  end
167
171
 
168
172
  # Deletes cache entries if the cache key matches a given pattern.
@@ -173,9 +173,12 @@ module ActiveSupport
173
173
  return {} if names.empty?
174
174
 
175
175
  options = names.extract_options!
176
- instrument_multi(:read_multi, names, options) do |payload|
176
+ options = merged_options(options)
177
+ keys = names.map { |name| normalize_key(name, options) }
178
+
179
+ instrument_multi(:read_multi, keys, options) do |payload|
177
180
  read_multi_entries(names, **options).tap do |results|
178
- payload[:hits] = results.keys
181
+ payload[:hits] = results.keys.map { |name| normalize_key(name, options) }
179
182
  end
180
183
  end
181
184
  end
@@ -286,7 +286,7 @@ module ActiveSupport
286
286
  # <tt>coder: nil</tt> to avoid the overhead of safeguarding against
287
287
  # mutation.
288
288
  #
289
- # The +:coder+ option is mutally exclusive with the +:serializer+ and
289
+ # The +:coder+ option is mutually exclusive with the +:serializer+ and
290
290
  # +:compressor+ options. Specifying them together will raise an
291
291
  # +ArgumentError+.
292
292
  #
@@ -419,7 +419,7 @@ module ActiveSupport
419
419
  # t1.join
420
420
  #
421
421
  # p val_1 # => "new value 1"
422
- # p val_2 # => "oritinal value"
422
+ # p val_2 # => "original value"
423
423
  # p cache.fetch("foo") # => "new value 1"
424
424
  #
425
425
  # # The entry requires 3 seconds to expire (expires_in + race_condition_ttl)
@@ -538,10 +538,11 @@ module ActiveSupport
538
538
 
539
539
  options = names.extract_options!
540
540
  options = merged_options(options)
541
+ keys = names.map { |name| normalize_key(name, options) }
541
542
 
542
- instrument_multi :read_multi, names, options do |payload|
543
+ instrument_multi :read_multi, keys, options do |payload|
543
544
  read_multi_entries(names, **options, event: payload).tap do |results|
544
- payload[:hits] = results.keys
545
+ payload[:hits] = results.keys.map { |name| normalize_key(name, options) }
545
546
  end
546
547
  end
547
548
  end
@@ -551,8 +552,9 @@ module ActiveSupport
551
552
  return hash if hash.empty?
552
553
 
553
554
  options = merged_options(options)
555
+ normalized_hash = hash.transform_keys { |key| normalize_key(key, options) }
554
556
 
555
- instrument_multi :write_multi, hash, options do |payload|
557
+ instrument_multi :write_multi, normalized_hash, options do |payload|
556
558
  entries = hash.each_with_object({}) do |(name, value), memo|
557
559
  memo[normalize_key(name, options)] = Entry.new(value, **options.merge(version: normalize_version(name, options)))
558
560
  end
@@ -596,9 +598,9 @@ module ActiveSupport
596
598
 
597
599
  options = names.extract_options!
598
600
  options = merged_options(options)
599
-
601
+ keys = names.map { |name| normalize_key(name, options) }
600
602
  writes = {}
601
- ordered = instrument_multi :read_multi, names, options do |payload|
603
+ ordered = instrument_multi :read_multi, keys, options do |payload|
602
604
  if options[:force]
603
605
  reads = {}
604
606
  else
@@ -610,7 +612,7 @@ module ActiveSupport
610
612
  end
611
613
  writes.compact! if options[:skip_nil]
612
614
 
613
- payload[:hits] = reads.keys
615
+ payload[:hits] = reads.keys.map { |name| normalize_key(name, options) }
614
616
  payload[:super_operation] = :fetch_multi
615
617
 
616
618
  ordered
@@ -675,7 +677,7 @@ module ActiveSupport
675
677
  options = merged_options(options)
676
678
  key = normalize_key(name, options)
677
679
 
678
- instrument(:delete, key) do
680
+ instrument(:delete, key, options) do
679
681
  delete_entry(key, **options)
680
682
  end
681
683
  end
@@ -690,7 +692,7 @@ module ActiveSupport
690
692
  options = merged_options(options)
691
693
  names.map! { |key| normalize_key(key, options) }
692
694
 
693
- instrument_multi :delete_multi, names do
695
+ instrument_multi(:delete_multi, names, options) do
694
696
  delete_multi_entries(names, **options)
695
697
  end
696
698
  end
@@ -943,9 +945,12 @@ module ActiveSupport
943
945
  #
944
946
  # namespace_key 'foo', namespace: -> { 'cache' }
945
947
  # # => 'cache:foo'
946
- def namespace_key(key, options = nil)
947
- options = merged_options(options)
948
- namespace = options[:namespace]
948
+ def namespace_key(key, call_options = nil)
949
+ namespace = if call_options&.key?(:namespace)
950
+ call_options[:namespace]
951
+ else
952
+ options[:namespace]
953
+ end
949
954
 
950
955
  if namespace.respond_to?(:call)
951
956
  namespace = namespace.call
@@ -6,7 +6,6 @@ require "active_support/core_ext/array/extract_options"
6
6
  require "active_support/core_ext/class/attribute"
7
7
  require "active_support/core_ext/string/filters"
8
8
  require "active_support/core_ext/object/blank"
9
- require "thread"
10
9
 
11
10
  module ActiveSupport
12
11
  # = Active Support \Callbacks
@@ -67,7 +66,7 @@ module ActiveSupport
67
66
 
68
67
  included do
69
68
  extend ActiveSupport::DescendantsTracker
70
- class_attribute :__callbacks, instance_writer: false, default: {}
69
+ class_attribute :__callbacks, instance_writer: false, instance_predicate: false, default: {}
71
70
  end
72
71
 
73
72
  CALLBACK_FILTER_TYPES = [:before, :after, :around].freeze
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveSupport
4
+ module ClassAttribute # :nodoc:
5
+ class << self
6
+ def redefine(owner, name, value)
7
+ if owner.singleton_class?
8
+ owner.redefine_method(name) { value }
9
+ owner.send(:public, name)
10
+ end
11
+
12
+ owner.redefine_singleton_method(name) { value }
13
+ owner.singleton_class.send(:public, name)
14
+
15
+ owner.redefine_singleton_method("#{name}=") do |new_value|
16
+ if owner.equal?(self)
17
+ value = new_value
18
+ else
19
+ ::ActiveSupport::ClassAttribute.redefine(self, name, new_value)
20
+ end
21
+ end
22
+ owner.singleton_class.send(:public, "#{name}=")
23
+ end
24
+ end
25
+ end
26
+ end