activesupport 7.2.2.1 → 8.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +41 -237
  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/cache/file_store.rb +12 -2
  7. data/lib/active_support/cache/memory_store.rb +6 -2
  8. data/lib/active_support/cache/redis_cache_store.rb +5 -2
  9. data/lib/active_support/cache.rb +14 -9
  10. data/lib/active_support/callbacks.rb +1 -2
  11. data/lib/active_support/class_attribute.rb +26 -0
  12. data/lib/active_support/code_generator.rb +9 -0
  13. data/lib/active_support/concurrency/share_lock.rb +0 -1
  14. data/lib/active_support/configuration_file.rb +15 -6
  15. data/lib/active_support/core_ext/benchmark.rb +6 -9
  16. data/lib/active_support/core_ext/class/attribute.rb +10 -19
  17. data/lib/active_support/core_ext/date/conversions.rb +2 -0
  18. data/lib/active_support/core_ext/date_and_time/compatibility.rb +2 -2
  19. data/lib/active_support/core_ext/enumerable.rb +8 -3
  20. data/lib/active_support/core_ext/hash/except.rb +0 -12
  21. data/lib/active_support/core_ext/object/json.rb +18 -14
  22. data/lib/active_support/core_ext/string/multibyte.rb +1 -1
  23. data/lib/active_support/core_ext/time/calculations.rb +14 -2
  24. data/lib/active_support/core_ext/time/conversions.rb +2 -0
  25. data/lib/active_support/core_ext/time/zones.rb +1 -1
  26. data/lib/active_support/deprecation.rb +1 -1
  27. data/lib/active_support/encrypted_configuration.rb +20 -2
  28. data/lib/active_support/error_reporter.rb +25 -1
  29. data/lib/active_support/gem_version.rb +4 -4
  30. data/lib/active_support/hash_with_indifferent_access.rb +16 -12
  31. data/lib/active_support/i18n_railtie.rb +19 -10
  32. data/lib/active_support/isolated_execution_state.rb +0 -1
  33. data/lib/active_support/json/encoding.rb +2 -2
  34. data/lib/active_support/number_helper.rb +22 -0
  35. data/lib/active_support/railtie.rb +4 -0
  36. data/lib/active_support/tagged_logging.rb +5 -0
  37. data/lib/active_support/testing/assertions.rb +72 -21
  38. data/lib/active_support/testing/isolation.rb +0 -2
  39. data/lib/active_support/testing/time_helpers.rb +2 -1
  40. data/lib/active_support/time_with_zone.rb +22 -13
  41. data/lib/active_support/values/time_zone.rb +17 -15
  42. data/lib/active_support.rb +10 -2
  43. metadata +23 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 293fd0b5b00d65684b3e0e8682c75a361d31fdb569fabc55888c4c11d7205ca0
4
- data.tar.gz: 8b40c8ed09b9a5eaa3173eb5701dde9fe047590b80f8b4e36b732596ff1e4e43
3
+ metadata.gz: 492cd4c9d2ec59d97060d7949b3b68badc089d97ea467a30a0e6614d65e69c21
4
+ data.tar.gz: 98af51f7ec102b694fbd17f636cdf942b965a9a845561f05b1569b07efc56747
5
5
  SHA512:
6
- metadata.gz: 762f738afc162c559a65a55a9134d105ff18b413a548ff5782481dff8cd8232c4ad3bd62c5f31f67d900594b9d61f7f95d650fea11f03bc269261f69a40aa7f9
7
- data.tar.gz: 5df006379973b96c7bb71ff559f2bef45a2c6faee3017536e49d0f5884751efb43451016657244111bfe534320448510d24f9c071aae1f22d218e0ca277ba32a
6
+ metadata.gz: b720480df1c4117bf85c0f9066f7015dc750ca1279bba4c07a66a429effa06101adab40eda21f76c6d14ee1c57d46b6aff5cffd494e0e55d18600fe764c9d0e5
7
+ data.tar.gz: 13d40213e5c9720bda46e71d696a6f011547ca95ade865061df922cc9abd5adfbf6a0daa651e0732314dfb67faf3c9ad3fde39bb3490f4e3fd7577fb24b8221b
data/CHANGELOG.md CHANGED
@@ -1,9 +1,4 @@
1
- ## Rails 7.2.2.1 (December 10, 2024) ##
2
-
3
- * No changes.
4
-
5
-
6
- ## Rails 7.2.2 (October 30, 2024) ##
1
+ ## Rails 8.0.0.beta1 (September 26, 2024) ##
7
2
 
8
3
  * Include options when instrumenting `ActiveSupport::Cache::Store#delete` and `ActiveSupport::Cache::Store#delete_multi`.
9
4
 
@@ -13,272 +8,81 @@
13
8
 
14
9
  *John Hawthorn*, *Abeid Ahmed*
15
10
 
11
+ * Deprecate `Benchmark.ms` core extension.
16
12
 
17
- ## Rails 7.2.1.2 (October 23, 2024) ##
18
-
19
- * No changes.
20
-
21
-
22
- ## Rails 7.2.1.1 (October 15, 2024) ##
23
-
24
- * No changes.
25
-
26
-
27
- ## Rails 7.2.1 (August 22, 2024) ##
28
-
29
- * No changes.
30
-
31
-
32
- ## Rails 7.2.0 (August 09, 2024) ##
33
-
34
- * Fix `delegate_missing_to allow_nil: true` when called with implict self
35
-
36
- ```ruby
37
- class Person
38
- delegate_missing_to :address, allow_nil: true
39
-
40
- def address
41
- nil
42
- end
43
-
44
- def berliner?
45
- city == "Berlin"
46
- end
47
- end
48
-
49
- Person.new.city # => nil
50
- Person.new.berliner? # undefined local variable or method `city' for an instance of Person (NameError)
51
- ```
52
-
53
- *Jean Boussier*
54
-
55
- * Add `logger` as a dependency since it is a bundled gem candidate for Ruby 3.5
13
+ The `benchmark` gem will become bundled in Ruby 3.5
56
14
 
57
15
  *Earlopain*
58
16
 
59
- * Define `Digest::UUID.nil_uuid`, which returns the so-called nil UUID.
60
-
61
- *Xavier Noria*
62
-
63
- * Support `duration` type in `ActiveSupport::XmlMini`.
64
-
65
- *heka1024*
66
-
67
- * Remove deprecated `ActiveSupport::Notifications::Event#children` and `ActiveSupport::Notifications::Event#parent_of?`.
68
-
69
- *Rafael Mendonça França*
70
-
71
- * Remove deprecated support to call the following methods without passing a deprecator:
72
-
73
- - `deprecate`
74
- - `deprecate_constant`
75
- - `ActiveSupport::Deprecation::DeprecatedObjectProxy.new`
76
- - `ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new`
77
- - `ActiveSupport::Deprecation::DeprecatedConstantProxy.new`
78
- - `assert_deprecated`
79
- - `assert_not_deprecated`
80
- - `collect_deprecations`
81
-
82
- *Rafael Mendonça França*
83
-
84
- * Remove deprecated `ActiveSupport::Deprecation` delegation to instance.
85
-
86
- *Rafael Mendonça França*
87
-
88
- * Remove deprecated `SafeBuffer#clone_empty`.
89
-
90
- *Rafael Mendonça França*
91
-
92
- * Remove deprecated `#to_default_s` from `Array`, `Date`, `DateTime` and `Time`.
93
-
94
- *Rafael Mendonça França*
95
-
96
- * Remove deprecated support to passing `Dalli::Client` instances to `MemCacheStore`.
97
-
98
- *Rafael Mendonça França*
99
-
100
- * Remove deprecated `config.active_support.use_rfc4122_namespaced_uuids`.
101
-
102
- *Rafael Mendonça França*
103
-
104
- * Remove deprecated `config.active_support.remove_deprecated_time_with_zone_name`.
105
-
106
- *Rafael Mendonça França*
107
-
108
- * Remove deprecated `config.active_support.disable_to_s_conversion`.
109
-
110
- *Rafael Mendonça França*
111
-
112
- * Remove deprecated support to bolding log text with positional boolean in `ActiveSupport::LogSubscriber#color`.
113
-
114
- *Rafael Mendonça França*
115
-
116
- * Remove deprecated constants `ActiveSupport::LogSubscriber::CLEAR` and `ActiveSupport::LogSubscriber::BOLD`.
117
-
118
- *Rafael Mendonça França*
17
+ * `ActiveSupport::TimeWithZone#inspect` now uses ISO 8601 style time like `Time#inspect`
119
18
 
120
- * Remove deprecated support for `config.active_support.cache_format_version = 6.1`.
19
+ *John Hawthorn*
121
20
 
122
- *Rafael Mendonça França*
21
+ * `ActiveSupport::ErrorReporter#report` now assigns a backtrace to unraised exceptions.
123
22
 
124
- * Remove deprecated `:pool_size` and `:pool_timeout` options for the cache storage.
125
-
126
- *Rafael Mendonça França*
127
-
128
- * Warn on tests without assertions.
129
-
130
- `ActiveSupport::TestCase` now warns when tests do not run any assertions.
131
- This is helpful in detecting broken tests that do not perform intended assertions.
132
-
133
- *fatkodima*
134
-
135
- * Support `hexBinary` type in `ActiveSupport::XmlMini`.
136
-
137
- *heka1024*
138
-
139
- * Deprecate `ActiveSupport::ProxyObject` in favor of Ruby's built-in `BasicObject`.
140
-
141
- *Earlopain*
142
-
143
- * `stub_const` now accepts a `exists: false` parameter to allow stubbing missing constants.
23
+ Previously reporting an un-raised exception would result in an error report without
24
+ a backtrace. Now it automatically generates one.
144
25
 
145
26
  *Jean Boussier*
146
27
 
147
- * Make `ActiveSupport::BacktraceCleaner` copy filters and silencers on dup and clone.
148
-
149
- Previously the copy would still share the internal silencers and filters array,
150
- causing state to leak.
151
-
152
- *Jean Boussier*
153
-
154
- * Updating Astana with Western Kazakhstan TZInfo identifier.
155
-
156
- *Damian Nelson*
157
-
158
- * Add filename support for `ActiveSupport::Logger.logger_outputs_to?`.
159
-
160
- ```ruby
161
- logger = Logger.new('/var/log/rails.log')
162
- ActiveSupport::Logger.logger_outputs_to?(logger, '/var/log/rails.log')
163
- ```
164
-
165
- *Christian Schmidt*
166
-
167
- * Include `IPAddr#prefix` when serializing an `IPAddr` using the
168
- `ActiveSupport::MessagePack` serializer.
169
-
170
- This change is backward and forward compatible — old payloads can
171
- still be read, and new payloads will be readable by older versions of Rails.
172
-
173
- *Taiki Komaba*
174
-
175
- * Add `default:` support for `ActiveSupport::CurrentAttributes.attribute`.
176
-
177
- ```ruby
178
- class Current < ActiveSupport::CurrentAttributes
179
- attribute :counter, default: 0
180
- end
181
- ```
182
-
183
- *Sean Doyle*
28
+ * Add `escape_html_entities` option to `ActiveSupport::JSON.encode`.
184
29
 
185
- * Yield instance to `Object#with` block.
30
+ This allows for overriding the global configuration found at
31
+ `ActiveSupport.escape_html_entities_in_json` for specific calls to `to_json`.
186
32
 
33
+ This should be usable from controllers in the following manner:
187
34
  ```ruby
188
- client.with(timeout: 5_000) do |c|
189
- c.get("/commits")
190
- end
191
- ```
192
-
193
- *Sean Doyle*
194
-
195
- * Use logical core count instead of physical core count to determine the
196
- default number of workers when parallelizing tests.
197
-
198
- *Jonathan Hefner*
199
-
200
- * Fix `Time.now/DateTime.now/Date.today` to return results in a system timezone after `#travel_to`.
201
-
202
- There is a bug in the current implementation of #travel_to:
203
- it remembers a timezone of its argument, and all stubbed methods start
204
- returning results in that remembered timezone. However, the expected
205
- behavior is to return results in a system timezone.
206
-
207
- *Aleksei Chernenkov*
208
-
209
- * Add `ErrorReported#unexpected` to report precondition violations.
210
-
211
- For example:
212
-
213
- ```ruby
214
- def edit
215
- if published?
216
- Rails.error.unexpected("[BUG] Attempting to edit a published article, that shouldn't be possible")
217
- return false
35
+ class MyController < ApplicationController
36
+ def index
37
+ render json: { hello: "world" }, escape_html_entities: false
218
38
  end
219
- # ...
220
39
  end
221
40
  ```
222
41
 
223
- The above will raise an error in development and test, but only report the error in production.
224
-
225
- *Jean Boussier*
226
-
227
- * Make the order of read_multi and write_multi notifications for `Cache::Store#fetch_multi` operations match the order they are executed in.
42
+ *Nigel Baillie*
228
43
 
229
- *Adam Renberg Tamm*
230
-
231
- * Make return values of `Cache::Store#write` consistent.
232
-
233
- The return value was not specified before. Now it returns `true` on a successful write,
234
- `nil` if there was an error talking to the cache backend, and `false` if the write failed
235
- for another reason (e.g. the key already exists and `unless_exist: true` was passed).
44
+ * Raise when using key which can't respond to `#to_sym` in `EncryptedConfiguration`.
236
45
 
237
- *Sander Verdonschot*
46
+ As is the case when trying to use an Integer or Float as a key, which is unsupported.
238
47
 
239
- * Fix logged cache keys not always matching actual key used by cache action.
48
+ *zzak*
240
49
 
241
- *Hartley McGuire*
50
+ * Deprecate addition and since between two `Time` and `ActiveSupport::TimeWithZone`.
242
51
 
243
- * Improve error messages of `assert_changes` and `assert_no_changes`.
52
+ 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.
244
53
 
245
- `assert_changes` error messages now display objects with `.inspect` to make it easier
246
- to differentiate nil from empty strings, strings from symbols, etc.
247
- `assert_no_changes` error messages now surface the actual value.
54
+ *Nick Schwaderer*
248
55
 
249
- *pcreux*
250
-
251
- * Fix `#to_fs(:human_size)` to correctly work with negative numbers.
252
-
253
- *Earlopain*
56
+ * Support rfc2822 format for Time#to_fs & Date#to_fs.
254
57
 
255
- * Fix `BroadcastLogger#dup` so that it duplicates the logger's `broadcasts`.
58
+ *Akshay Birajdar*
256
59
 
257
- *Andrew Novoselac*
60
+ * Optimize load time for `Railtie#initialize_i18n`. Filter `I18n.load_path`s passed to the file watcher to only those
61
+ under `Rails.root`. Previously the watcher would grab all available locales, including those in gems
62
+ which do not require a watcher because they won't change.
258
63
 
259
- * Fix issue where `bootstrap.rb` overwrites the `level` of a `BroadcastLogger`'s `broadcasts`.
64
+ *Nick Schwaderer*
260
65
 
261
- *Andrew Novoselac*
66
+ * Add a `filter` option to `in_order_of` to prioritize certain values in the sorting without filtering the results
67
+ by these values.
262
68
 
263
- * Fix compatibility with the `semantic_logger` gem.
69
+ *Igor Depolli*
264
70
 
265
- The `semantic_logger` gem doesn't behave exactly like stdlib logger in that
266
- `SemanticLogger#level` returns a Symbol while stdlib `Logger#level` returns an Integer.
71
+ * Improve error message when using `assert_difference` or `assert_changes` with a
72
+ proc by printing the proc's source code (MRI only).
267
73
 
268
- This caused the various `LogSubscriber` classes in Rails to break when assigned a
269
- `SemanticLogger` instance.
74
+ *Richard Böhme*, *Jean Boussier*
270
75
 
271
- *Jean Boussier*, *ojab*
76
+ * 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`.
272
77
 
273
- * Fix MemoryStore to prevent race conditions when incrementing or decrementing.
78
+ *Jason Kim*, *John Hawthorn*
274
79
 
275
- *Pierre Jambet*
80
+ * Align instrumentation `payload[:key]` in ActiveSupport::Cache to follow the same pattern, with namespaced and normalized keys.
276
81
 
277
- * Implement `HashWithIndifferentAccess#to_proc`.
82
+ *Frederik Erbs Spang Thomsen*
278
83
 
279
- Previously, calling `#to_proc` on `HashWithIndifferentAccess` object used inherited `#to_proc`
280
- method from the `Hash` class, which was not able to access values using indifferent keys.
84
+ * Fix `travel_to` to set usec 0 when `with_usec` is `false` and the given argument String or DateTime.
281
85
 
282
- *fatkodima*
86
+ *mopp*
283
87
 
284
- Please check [7-1-stable](https://github.com/rails/rails/blob/7-1-stable/activesupport/CHANGELOG.md) for previous changes.
88
+ 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
@@ -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
@@ -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
@@ -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
@@ -55,6 +55,11 @@ module ActiveSupport
55
55
  @path = path
56
56
  @line = line
57
57
  @namespaces = Hash.new { |h, k| h[k] = MethodSet.new(k) }
58
+ @sources = []
59
+ end
60
+
61
+ def class_eval
62
+ yield @sources
58
63
  end
59
64
 
60
65
  def define_cached_method(canonical_name, namespace:, as: nil, &block)
@@ -65,6 +70,10 @@ module ActiveSupport
65
70
  @namespaces.each_value do |method_set|
66
71
  method_set.apply(@owner, @path, @line - 1)
67
72
  end
73
+
74
+ unless @sources.empty?
75
+ @owner.class_eval("# frozen_string_literal: true\n" + @sources.join(";"), @path, @line - 1)
76
+ end
68
77
  end
69
78
  end
70
79
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "thread"
4
3
  require "monitor"
5
4
 
6
5
  module ActiveSupport
@@ -19,11 +19,20 @@ module ActiveSupport
19
19
  end
20
20
 
21
21
  def parse(context: nil, **options)
22
- source = render(context)
23
- if YAML.respond_to?(:unsafe_load)
24
- YAML.unsafe_load(source, **options) || {}
22
+ source = @content.include?("<%") ? render(context) : @content
23
+
24
+ if source == @content
25
+ if YAML.respond_to?(:unsafe_load)
26
+ YAML.unsafe_load_file(@content_path, **options) || {}
27
+ else
28
+ YAML.load_file(@content_path, **options) || {}
29
+ end
25
30
  else
26
- YAML.load(source, **options) || {}
31
+ if YAML.respond_to?(:unsafe_load)
32
+ YAML.unsafe_load(source, **options) || {}
33
+ else
34
+ YAML.load(source, **options) || {}
35
+ end
27
36
  end
28
37
  rescue Psych::SyntaxError => error
29
38
  raise "YAML syntax error occurred while parsing #{@content_path}. " \
@@ -33,8 +42,7 @@ module ActiveSupport
33
42
 
34
43
  private
35
44
  def read(content_path)
36
- require "yaml"
37
- require "erb"
45
+ require "yaml" unless defined?(YAML)
38
46
 
39
47
  File.read(content_path).tap do |content|
40
48
  if content.include?("\u00A0")
@@ -44,6 +52,7 @@ module ActiveSupport
44
52
  end
45
53
 
46
54
  def render(context)
55
+ require "erb" unless defined?(ERB)
47
56
  erb = ERB.new(@content).tap { |e| e.filename = @content_path }
48
57
  context ? erb.result(context) : erb.result
49
58
  end
@@ -3,14 +3,11 @@
3
3
  require "benchmark"
4
4
 
5
5
  class << Benchmark
6
- # Benchmark realtime in milliseconds.
7
- #
8
- # Benchmark.realtime { User.all }
9
- # # => 8.0e-05
10
- #
11
- # Benchmark.ms { User.all }
12
- # # => 0.074
13
- def ms(&block)
14
- 1000 * realtime(&block)
6
+ def ms(&block) # :nodoc
7
+ # NOTE: Please also remove the Active Support `benchmark` dependency when removing this
8
+ ActiveSupport.deprecator.warn <<~TEXT
9
+ `Benchmark.ms` is deprecated and will be removed in Rails 8.1 without replacement.
10
+ TEXT
11
+ ActiveSupport::Benchmark.realtime(:float_millisecond, &block)
15
12
  end
16
13
  end