activesupport 6.0.6.1 → 7.1.3.2

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 (245) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +865 -438
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +6 -6
  5. data/lib/active_support/actionable_error.rb +4 -2
  6. data/lib/active_support/array_inquirer.rb +4 -2
  7. data/lib/active_support/backtrace_cleaner.rb +30 -10
  8. data/lib/active_support/benchmarkable.rb +4 -3
  9. data/lib/active_support/broadcast_logger.rb +250 -0
  10. data/lib/active_support/builder.rb +1 -1
  11. data/lib/active_support/cache/coder.rb +153 -0
  12. data/lib/active_support/cache/entry.rb +134 -0
  13. data/lib/active_support/cache/file_store.rb +53 -20
  14. data/lib/active_support/cache/mem_cache_store.rb +208 -63
  15. data/lib/active_support/cache/memory_store.rb +120 -38
  16. data/lib/active_support/cache/null_store.rb +16 -2
  17. data/lib/active_support/cache/redis_cache_store.rb +201 -208
  18. data/lib/active_support/cache/serializer_with_fallback.rb +175 -0
  19. data/lib/active_support/cache/strategy/local_cache.rb +73 -66
  20. data/lib/active_support/cache.rb +539 -261
  21. data/lib/active_support/callbacks.rb +273 -142
  22. data/lib/active_support/code_generator.rb +65 -0
  23. data/lib/active_support/concern.rb +53 -7
  24. data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +44 -7
  25. data/lib/active_support/concurrency/null_lock.rb +13 -0
  26. data/lib/active_support/concurrency/share_lock.rb +2 -2
  27. data/lib/active_support/configurable.rb +19 -6
  28. data/lib/active_support/configuration_file.rb +51 -0
  29. data/lib/active_support/core_ext/array/access.rb +1 -5
  30. data/lib/active_support/core_ext/array/conversions.rb +15 -13
  31. data/lib/active_support/core_ext/array/grouping.rb +6 -6
  32. data/lib/active_support/core_ext/array/inquiry.rb +2 -2
  33. data/lib/active_support/core_ext/benchmark.rb +2 -2
  34. data/lib/active_support/core_ext/big_decimal/conversions.rb +1 -1
  35. data/lib/active_support/core_ext/class/attribute.rb +34 -44
  36. data/lib/active_support/core_ext/class/subclasses.rb +19 -29
  37. data/lib/active_support/core_ext/date/blank.rb +1 -1
  38. data/lib/active_support/core_ext/date/calculations.rb +24 -9
  39. data/lib/active_support/core_ext/date/conversions.rb +18 -16
  40. data/lib/active_support/core_ext/date_and_time/calculations.rb +27 -4
  41. data/lib/active_support/core_ext/date_and_time/compatibility.rb +15 -0
  42. data/lib/active_support/core_ext/date_time/blank.rb +1 -1
  43. data/lib/active_support/core_ext/date_time/calculations.rb +4 -0
  44. data/lib/active_support/core_ext/date_time/conversions.rb +19 -15
  45. data/lib/active_support/core_ext/digest/uuid.rb +30 -13
  46. data/lib/active_support/core_ext/enumerable.rb +146 -72
  47. data/lib/active_support/core_ext/erb/util.rb +196 -0
  48. data/lib/active_support/core_ext/file/atomic.rb +3 -1
  49. data/lib/active_support/core_ext/hash/conversions.rb +3 -4
  50. data/lib/active_support/core_ext/hash/deep_merge.rb +22 -14
  51. data/lib/active_support/core_ext/hash/deep_transform_values.rb +4 -4
  52. data/lib/active_support/core_ext/hash/indifferent_access.rb +3 -3
  53. data/lib/active_support/core_ext/hash/keys.rb +5 -5
  54. data/lib/active_support/core_ext/hash/slice.rb +3 -2
  55. data/lib/active_support/core_ext/integer/inflections.rb +12 -12
  56. data/lib/active_support/core_ext/kernel/reporting.rb +4 -4
  57. data/lib/active_support/core_ext/kernel/singleton_class.rb +1 -1
  58. data/lib/active_support/core_ext/load_error.rb +1 -1
  59. data/lib/active_support/core_ext/module/attr_internal.rb +2 -2
  60. data/lib/active_support/core_ext/module/attribute_accessors.rb +31 -29
  61. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +51 -20
  62. data/lib/active_support/core_ext/module/concerning.rb +14 -8
  63. data/lib/active_support/core_ext/module/delegation.rb +75 -42
  64. data/lib/active_support/core_ext/module/deprecation.rb +15 -12
  65. data/lib/active_support/core_ext/module/introspection.rb +1 -26
  66. data/lib/active_support/core_ext/name_error.rb +23 -2
  67. data/lib/active_support/core_ext/numeric/bytes.rb +9 -0
  68. data/lib/active_support/core_ext/numeric/conversions.rb +82 -73
  69. data/lib/active_support/core_ext/object/acts_like.rb +29 -5
  70. data/lib/active_support/core_ext/object/blank.rb +2 -2
  71. data/lib/active_support/core_ext/object/deep_dup.rb +17 -1
  72. data/lib/active_support/core_ext/object/duplicable.rb +15 -4
  73. data/lib/active_support/core_ext/object/inclusion.rb +13 -5
  74. data/lib/active_support/core_ext/object/instance_variables.rb +22 -12
  75. data/lib/active_support/core_ext/object/json.rb +52 -28
  76. data/lib/active_support/core_ext/object/to_query.rb +2 -4
  77. data/lib/active_support/core_ext/object/try.rb +20 -20
  78. data/lib/active_support/core_ext/object/with.rb +44 -0
  79. data/lib/active_support/core_ext/object/with_options.rb +25 -6
  80. data/lib/active_support/core_ext/object.rb +1 -0
  81. data/lib/active_support/core_ext/pathname/blank.rb +16 -0
  82. data/lib/active_support/core_ext/pathname/existence.rb +23 -0
  83. data/lib/active_support/core_ext/pathname.rb +4 -0
  84. data/lib/active_support/core_ext/range/compare_range.rb +6 -25
  85. data/lib/active_support/core_ext/range/conversions.rb +34 -13
  86. data/lib/active_support/core_ext/range/each.rb +1 -1
  87. data/lib/active_support/core_ext/range/overlap.rb +40 -0
  88. data/lib/active_support/core_ext/range.rb +1 -2
  89. data/lib/active_support/core_ext/regexp.rb +8 -1
  90. data/lib/active_support/core_ext/securerandom.rb +25 -13
  91. data/lib/active_support/core_ext/string/access.rb +5 -24
  92. data/lib/active_support/core_ext/string/conversions.rb +3 -2
  93. data/lib/active_support/core_ext/string/filters.rb +21 -15
  94. data/lib/active_support/core_ext/string/indent.rb +1 -1
  95. data/lib/active_support/core_ext/string/inflections.rb +51 -10
  96. data/lib/active_support/core_ext/string/inquiry.rb +2 -1
  97. data/lib/active_support/core_ext/string/multibyte.rb +2 -2
  98. data/lib/active_support/core_ext/string/output_safety.rb +85 -194
  99. data/lib/active_support/core_ext/string/starts_ends_with.rb +2 -2
  100. data/lib/active_support/core_ext/symbol/starts_ends_with.rb +6 -0
  101. data/lib/active_support/core_ext/symbol.rb +3 -0
  102. data/lib/active_support/core_ext/thread/backtrace/location.rb +12 -0
  103. data/lib/active_support/core_ext/time/calculations.rb +46 -8
  104. data/lib/active_support/core_ext/time/conversions.rb +16 -13
  105. data/lib/active_support/core_ext/time/zones.rb +12 -28
  106. data/lib/active_support/core_ext.rb +2 -1
  107. data/lib/active_support/current_attributes/test_helper.rb +13 -0
  108. data/lib/active_support/current_attributes.rb +54 -22
  109. data/lib/active_support/deep_mergeable.rb +53 -0
  110. data/lib/active_support/dependencies/autoload.rb +17 -12
  111. data/lib/active_support/dependencies/interlock.rb +10 -18
  112. data/lib/active_support/dependencies/require_dependency.rb +28 -0
  113. data/lib/active_support/dependencies.rb +58 -769
  114. data/lib/active_support/deprecation/behaviors.rb +77 -38
  115. data/lib/active_support/deprecation/constant_accessor.rb +5 -4
  116. data/lib/active_support/deprecation/deprecators.rb +104 -0
  117. data/lib/active_support/deprecation/disallowed.rb +54 -0
  118. data/lib/active_support/deprecation/instance_delegator.rb +31 -5
  119. data/lib/active_support/deprecation/method_wrappers.rb +12 -28
  120. data/lib/active_support/deprecation/proxy_wrappers.rb +40 -25
  121. data/lib/active_support/deprecation/reporting.rb +76 -16
  122. data/lib/active_support/deprecation.rb +36 -4
  123. data/lib/active_support/deprecator.rb +7 -0
  124. data/lib/active_support/descendants_tracker.rb +150 -68
  125. data/lib/active_support/digest.rb +5 -3
  126. data/lib/active_support/duration/iso8601_parser.rb +3 -3
  127. data/lib/active_support/duration/iso8601_serializer.rb +24 -12
  128. data/lib/active_support/duration.rb +136 -56
  129. data/lib/active_support/encrypted_configuration.rb +72 -9
  130. data/lib/active_support/encrypted_file.rb +46 -13
  131. data/lib/active_support/environment_inquirer.rb +40 -0
  132. data/lib/active_support/error_reporter/test_helper.rb +15 -0
  133. data/lib/active_support/error_reporter.rb +203 -0
  134. data/lib/active_support/evented_file_update_checker.rb +86 -137
  135. data/lib/active_support/execution_context/test_helper.rb +13 -0
  136. data/lib/active_support/execution_context.rb +53 -0
  137. data/lib/active_support/execution_wrapper.rb +31 -12
  138. data/lib/active_support/executor/test_helper.rb +7 -0
  139. data/lib/active_support/file_update_checker.rb +4 -2
  140. data/lib/active_support/fork_tracker.rb +79 -0
  141. data/lib/active_support/gem_version.rb +5 -5
  142. data/lib/active_support/gzip.rb +2 -0
  143. data/lib/active_support/hash_with_indifferent_access.rb +86 -42
  144. data/lib/active_support/html_safe_translation.rb +53 -0
  145. data/lib/active_support/i18n.rb +2 -1
  146. data/lib/active_support/i18n_railtie.rb +29 -27
  147. data/lib/active_support/inflector/inflections.rb +26 -9
  148. data/lib/active_support/inflector/methods.rb +54 -64
  149. data/lib/active_support/inflector/transliterate.rb +7 -5
  150. data/lib/active_support/isolated_execution_state.rb +76 -0
  151. data/lib/active_support/json/decoding.rb +6 -5
  152. data/lib/active_support/json/encoding.rb +31 -45
  153. data/lib/active_support/key_generator.rb +32 -7
  154. data/lib/active_support/lazy_load_hooks.rb +33 -7
  155. data/lib/active_support/locale/en.yml +10 -4
  156. data/lib/active_support/log_subscriber/test_helper.rb +2 -2
  157. data/lib/active_support/log_subscriber.rb +101 -32
  158. data/lib/active_support/logger.rb +9 -60
  159. data/lib/active_support/logger_silence.rb +2 -26
  160. data/lib/active_support/logger_thread_safe_level.rb +24 -25
  161. data/lib/active_support/message_encryptor.rb +205 -58
  162. data/lib/active_support/message_encryptors.rb +141 -0
  163. data/lib/active_support/message_pack/cache_serializer.rb +23 -0
  164. data/lib/active_support/message_pack/extensions.rb +292 -0
  165. data/lib/active_support/message_pack/serializer.rb +63 -0
  166. data/lib/active_support/message_pack.rb +50 -0
  167. data/lib/active_support/message_verifier.rb +237 -86
  168. data/lib/active_support/message_verifiers.rb +135 -0
  169. data/lib/active_support/messages/codec.rb +65 -0
  170. data/lib/active_support/messages/metadata.rb +112 -46
  171. data/lib/active_support/messages/rotation_configuration.rb +2 -1
  172. data/lib/active_support/messages/rotation_coordinator.rb +93 -0
  173. data/lib/active_support/messages/rotator.rb +35 -32
  174. data/lib/active_support/messages/serializer_with_fallback.rb +158 -0
  175. data/lib/active_support/multibyte/chars.rb +15 -52
  176. data/lib/active_support/multibyte/unicode.rb +8 -122
  177. data/lib/active_support/multibyte.rb +1 -1
  178. data/lib/active_support/notifications/fanout.rb +310 -105
  179. data/lib/active_support/notifications/instrumenter.rb +113 -48
  180. data/lib/active_support/notifications.rb +56 -29
  181. data/lib/active_support/number_helper/number_converter.rb +15 -8
  182. data/lib/active_support/number_helper/number_to_currency_converter.rb +11 -6
  183. data/lib/active_support/number_helper/number_to_delimited_converter.rb +1 -1
  184. data/lib/active_support/number_helper/number_to_human_converter.rb +1 -1
  185. data/lib/active_support/number_helper/number_to_human_size_converter.rb +5 -5
  186. data/lib/active_support/number_helper/number_to_phone_converter.rb +2 -1
  187. data/lib/active_support/number_helper/number_to_rounded_converter.rb +9 -5
  188. data/lib/active_support/number_helper/rounding_helper.rb +12 -32
  189. data/lib/active_support/number_helper.rb +379 -304
  190. data/lib/active_support/option_merger.rb +11 -18
  191. data/lib/active_support/ordered_hash.rb +4 -4
  192. data/lib/active_support/ordered_options.rb +23 -3
  193. data/lib/active_support/parameter_filter.rb +104 -75
  194. data/lib/active_support/proxy_object.rb +2 -0
  195. data/lib/active_support/rails.rb +1 -4
  196. data/lib/active_support/railtie.rb +90 -6
  197. data/lib/active_support/reloader.rb +12 -4
  198. data/lib/active_support/rescuable.rb +18 -16
  199. data/lib/active_support/ruby_features.rb +7 -0
  200. data/lib/active_support/secure_compare_rotator.rb +58 -0
  201. data/lib/active_support/security_utils.rb +19 -12
  202. data/lib/active_support/string_inquirer.rb +5 -3
  203. data/lib/active_support/subscriber.rb +23 -47
  204. data/lib/active_support/syntax_error_proxy.rb +70 -0
  205. data/lib/active_support/tagged_logging.rb +84 -23
  206. data/lib/active_support/test_case.rb +166 -27
  207. data/lib/active_support/testing/assertions.rb +73 -20
  208. data/lib/active_support/testing/autorun.rb +0 -2
  209. data/lib/active_support/testing/constant_stubbing.rb +32 -0
  210. data/lib/active_support/testing/deprecation.rb +53 -2
  211. data/lib/active_support/testing/error_reporter_assertions.rb +107 -0
  212. data/lib/active_support/testing/isolation.rb +30 -29
  213. data/lib/active_support/testing/method_call_assertions.rb +24 -11
  214. data/lib/active_support/testing/parallelization/server.rb +82 -0
  215. data/lib/active_support/testing/parallelization/worker.rb +103 -0
  216. data/lib/active_support/testing/parallelization.rb +16 -95
  217. data/lib/active_support/testing/parallelize_executor.rb +81 -0
  218. data/lib/active_support/testing/stream.rb +4 -6
  219. data/lib/active_support/testing/strict_warnings.rb +39 -0
  220. data/lib/active_support/testing/tagged_logging.rb +1 -1
  221. data/lib/active_support/testing/time_helpers.rb +89 -19
  222. data/lib/active_support/time_with_zone.rb +105 -70
  223. data/lib/active_support/values/time_zone.rb +59 -26
  224. data/lib/active_support/version.rb +1 -1
  225. data/lib/active_support/xml_mini/jdom.rb +4 -11
  226. data/lib/active_support/xml_mini/libxml.rb +5 -5
  227. data/lib/active_support/xml_mini/libxmlsax.rb +1 -1
  228. data/lib/active_support/xml_mini/nokogiri.rb +5 -5
  229. data/lib/active_support/xml_mini/nokogirisax.rb +2 -2
  230. data/lib/active_support/xml_mini/rexml.rb +9 -2
  231. data/lib/active_support/xml_mini.rb +7 -6
  232. data/lib/active_support.rb +40 -1
  233. metadata +127 -40
  234. data/lib/active_support/core_ext/array/prepend_and_append.rb +0 -5
  235. data/lib/active_support/core_ext/hash/compact.rb +0 -5
  236. data/lib/active_support/core_ext/hash/transform_values.rb +0 -5
  237. data/lib/active_support/core_ext/marshal.rb +0 -24
  238. data/lib/active_support/core_ext/module/reachable.rb +0 -6
  239. data/lib/active_support/core_ext/numeric/inquiry.rb +0 -5
  240. data/lib/active_support/core_ext/range/include_range.rb +0 -9
  241. data/lib/active_support/core_ext/range/include_time_with_zone.rb +0 -23
  242. data/lib/active_support/core_ext/range/overlaps.rb +0 -10
  243. data/lib/active_support/core_ext/uri.rb +0 -25
  244. data/lib/active_support/dependencies/zeitwerk_integration.rb +0 -117
  245. data/lib/active_support/per_thread_registry.rb +0 -60
@@ -4,18 +4,20 @@ require "tzinfo"
4
4
  require "concurrent/map"
5
5
 
6
6
  module ActiveSupport
7
- # The TimeZone class serves as a wrapper around TZInfo::Timezone instances.
7
+ # = Active Support \Time Zone
8
+ #
9
+ # The TimeZone class serves as a wrapper around +TZInfo::Timezone+ instances.
8
10
  # It allows us to do the following:
9
11
  #
10
12
  # * Limit the set of zones provided by TZInfo to a meaningful subset of 134
11
13
  # zones.
12
14
  # * Retrieve and display zones with a friendlier name
13
15
  # (e.g., "Eastern Time (US & Canada)" instead of "America/New_York").
14
- # * Lazily load TZInfo::Timezone instances only when they're needed.
16
+ # * Lazily load +TZInfo::Timezone+ instances only when they're needed.
15
17
  # * Create ActiveSupport::TimeWithZone instances via TimeZone's +local+,
16
- # +parse+, +at+ and +now+ methods.
18
+ # +parse+, +at+, and +now+ methods.
17
19
  #
18
- # If you set <tt>config.time_zone</tt> in the Rails Application, you can
20
+ # If you set <tt>config.time_zone</tt> in the \Rails Application, you can
19
21
  # access this TimeZone object via <tt>Time.zone</tt>:
20
22
  #
21
23
  # # application.rb:
@@ -27,7 +29,7 @@ module ActiveSupport
27
29
  # Time.zone.name # => "Eastern Time (US & Canada)"
28
30
  # Time.zone.now # => Sun, 18 May 2008 14:30:44 EDT -04:00
29
31
  class TimeZone
30
- # Keys are Rails TimeZone names, values are TZInfo identifiers.
32
+ # Keys are \Rails TimeZone names, values are TZInfo identifiers.
31
33
  MAPPING = {
32
34
  "International Date Line West" => "Etc/GMT+12",
33
35
  "Midway Island" => "Pacific/Midway",
@@ -159,7 +161,7 @@ module ActiveSupport
159
161
  "Yakutsk" => "Asia/Yakutsk",
160
162
  "Darwin" => "Australia/Darwin",
161
163
  "Adelaide" => "Australia/Adelaide",
162
- "Canberra" => "Australia/Melbourne",
164
+ "Canberra" => "Australia/Canberra",
163
165
  "Melbourne" => "Australia/Melbourne",
164
166
  "Sydney" => "Australia/Sydney",
165
167
  "Brisbane" => "Australia/Brisbane",
@@ -203,7 +205,7 @@ module ActiveSupport
203
205
  end
204
206
 
205
207
  def find_tzinfo(name)
206
- TZInfo::Timezone.new(MAPPING[name] || name)
208
+ TZInfo::Timezone.get(MAPPING[name] || name)
207
209
  end
208
210
 
209
211
  alias_method :create, :new
@@ -229,12 +231,16 @@ module ActiveSupport
229
231
  # Returns +nil+ if no such time zone is known to the system.
230
232
  def [](arg)
231
233
  case arg
234
+ when self
235
+ arg
232
236
  when String
233
237
  begin
234
238
  @lazy_zones_map[arg] ||= create(arg)
235
239
  rescue TZInfo::InvalidTimezoneIdentifier
236
240
  nil
237
241
  end
242
+ when TZInfo::Timezone
243
+ @lazy_zones_map[arg.name] ||= create(arg.name, nil, arg)
238
244
  when Numeric, ActiveSupport::Duration
239
245
  arg *= 3600 if arg.abs <= 13
240
246
  all.find { |z| z.utc_offset == arg.to_i }
@@ -256,7 +262,7 @@ module ActiveSupport
256
262
  @country_zones[code] ||= load_country_zones(code)
257
263
  end
258
264
 
259
- def clear #:nodoc:
265
+ def clear # :nodoc:
260
266
  @lazy_zones_map = Concurrent::Map.new
261
267
  @country_zones = Concurrent::Map.new
262
268
  @zones = nil
@@ -273,7 +279,7 @@ module ActiveSupport
273
279
  memo
274
280
  end
275
281
  else
276
- create(tz_id, nil, TZInfo::Timezone.new(tz_id))
282
+ create(tz_id, nil, TZInfo::Timezone.get(tz_id))
277
283
  end
278
284
  end.sort!
279
285
  end
@@ -302,11 +308,7 @@ module ActiveSupport
302
308
 
303
309
  # Returns the offset of this time zone from UTC in seconds.
304
310
  def utc_offset
305
- if @utc_offset
306
- @utc_offset
307
- else
308
- tzinfo.current_period.utc_offset if tzinfo && tzinfo.current_period
309
- end
311
+ @utc_offset || tzinfo&.current_period&.base_utc_offset
310
312
  end
311
313
 
312
314
  # Returns a formatted string of the offset from UTC, or an alternative
@@ -334,6 +336,13 @@ module ActiveSupport
334
336
  re === name || re === MAPPING[name]
335
337
  end
336
338
 
339
+ # Compare #name and TZInfo identifier to a supplied regexp, returning +true+
340
+ # if a match is found.
341
+ def match?(re)
342
+ (re == name) || (re == MAPPING[name]) ||
343
+ ((Regexp === re) && (re.match?(name) || re.match?(MAPPING[name])))
344
+ end
345
+
337
346
  # Returns a textual representation of this time zone.
338
347
  def to_s
339
348
  "(GMT#{formatted_offset}) #{name}"
@@ -378,14 +387,28 @@ module ActiveSupport
378
387
  # If the string is invalid then an +ArgumentError+ will be raised unlike +parse+
379
388
  # which usually returns +nil+ when given an invalid date string.
380
389
  def iso8601(str)
390
+ # Historically `Date._iso8601(nil)` returns `{}`, but in the `date` gem versions `3.2.1`, `3.1.2`, `3.0.2`,
391
+ # and `2.0.1`, `Date._iso8601(nil)` raises `TypeError` https://github.com/ruby/date/issues/39
392
+ # Future `date` releases are expected to revert back to the original behavior.
393
+ raise ArgumentError, "invalid date" if str.nil?
394
+
381
395
  parts = Date._iso8601(str)
382
396
 
383
- raise ArgumentError, "invalid date" if parts.empty?
397
+ year = parts.fetch(:year)
398
+
399
+ if parts.key?(:yday)
400
+ ordinal_date = Date.ordinal(year, parts.fetch(:yday))
401
+ month = ordinal_date.month
402
+ day = ordinal_date.day
403
+ else
404
+ month = parts.fetch(:mon)
405
+ day = parts.fetch(:mday)
406
+ end
384
407
 
385
408
  time = Time.new(
386
- parts.fetch(:year),
387
- parts.fetch(:mon),
388
- parts.fetch(:mday),
409
+ year,
410
+ month,
411
+ day,
389
412
  parts.fetch(:hour, 0),
390
413
  parts.fetch(:min, 0),
391
414
  parts.fetch(:sec, 0) + parts.fetch(:sec_fraction, 0),
@@ -397,6 +420,9 @@ module ActiveSupport
397
420
  else
398
421
  TimeWithZone.new(nil, self, time)
399
422
  end
423
+
424
+ rescue Date::Error, KeyError
425
+ raise ArgumentError, "invalid date"
400
426
  end
401
427
 
402
428
  # Method for creating new ActiveSupport::TimeWithZone instance in time zone
@@ -500,10 +526,17 @@ module ActiveSupport
500
526
  end
501
527
 
502
528
  # Adjust the given time to the simultaneous time in the time zone
503
- # represented by +self+. Returns a Time.utc() instance -- if you want an
504
- # ActiveSupport::TimeWithZone instance, use Time#in_time_zone() instead.
529
+ # represented by +self+. Returns a local time with the appropriate offset
530
+ # -- if you want an ActiveSupport::TimeWithZone instance, use
531
+ # Time#in_time_zone() instead.
532
+ #
533
+ # As of tzinfo 2, utc_to_local returns a Time with a non-zero utc_offset.
534
+ # See the +utc_to_local_returns_utc_offset_times+ config for more info.
505
535
  def utc_to_local(time)
506
- tzinfo.utc_to_local(time)
536
+ tzinfo.utc_to_local(time).yield_self do |t|
537
+ ActiveSupport.utc_to_local_returns_utc_offset_times ?
538
+ t : Time.utc(t.year, t.month, t.day, t.hour, t.min, t.sec, t.sec_fraction * 1_000_000)
539
+ end
507
540
  end
508
541
 
509
542
  # Adjust the given time to the simultaneous time in UTC. Returns a
@@ -512,27 +545,27 @@ module ActiveSupport
512
545
  tzinfo.local_to_utc(time, dst)
513
546
  end
514
547
 
515
- # Available so that TimeZone instances respond like TZInfo::Timezone
548
+ # Available so that TimeZone instances respond like +TZInfo::Timezone+
516
549
  # instances.
517
550
  def period_for_utc(time)
518
551
  tzinfo.period_for_utc(time)
519
552
  end
520
553
 
521
- # Available so that TimeZone instances respond like TZInfo::Timezone
554
+ # Available so that TimeZone instances respond like +TZInfo::Timezone+
522
555
  # instances.
523
556
  def period_for_local(time, dst = true)
524
557
  tzinfo.period_for_local(time, dst) { |periods| periods.last }
525
558
  end
526
559
 
527
- def periods_for_local(time) #:nodoc:
560
+ def periods_for_local(time) # :nodoc:
528
561
  tzinfo.periods_for_local(time)
529
562
  end
530
563
 
531
- def init_with(coder) #:nodoc:
564
+ def init_with(coder) # :nodoc:
532
565
  initialize(coder["name"])
533
566
  end
534
567
 
535
- def encode_with(coder) #:nodoc:
568
+ def encode_with(coder) # :nodoc:
536
569
  coder.tag = "!ruby/object:#{self.class}"
537
570
  coder.map = { "name" => tzinfo.name }
538
571
  end
@@ -3,7 +3,7 @@
3
3
  require_relative "gem_version"
4
4
 
5
5
  module ActiveSupport
6
- # Returns the version of the currently loaded ActiveSupport as a <tt>Gem::Version</tt>
6
+ # Returns the currently loaded version of Active Support as a +Gem::Version+.
7
7
  def self.version
8
8
  gem_version
9
9
  end
@@ -15,18 +15,11 @@ java_import org.xml.sax.Attributes unless defined? Attributes
15
15
  java_import org.w3c.dom.Node unless defined? Node
16
16
 
17
17
  module ActiveSupport
18
- module XmlMini_JDOM #:nodoc:
18
+ module XmlMini_JDOM # :nodoc:
19
19
  extend self
20
20
 
21
21
  CONTENT_KEY = "__content__"
22
22
 
23
- NODE_TYPE_NAMES = %w{ATTRIBUTE_NODE CDATA_SECTION_NODE COMMENT_NODE DOCUMENT_FRAGMENT_NODE
24
- DOCUMENT_NODE DOCUMENT_TYPE_NODE ELEMENT_NODE ENTITY_NODE ENTITY_REFERENCE_NODE NOTATION_NODE
25
- PROCESSING_INSTRUCTION_NODE TEXT_NODE}
26
-
27
- node_type_map = {}
28
- NODE_TYPE_NAMES.each { |type| node_type_map[Node.send(type)] = type }
29
-
30
23
  # Parse an XML Document string or IO into a simple hash using Java's jdom.
31
24
  # data::
32
25
  # XML Document string or IO to parse
@@ -80,7 +73,7 @@ module ActiveSupport
80
73
  if child_nodes.length > 0
81
74
  (0...child_nodes.length).each do |i|
82
75
  child = child_nodes.item(i)
83
- merge_element!(hash, child, depth - 1) unless child.node_type == Node.TEXT_NODE
76
+ merge_element!(hash, child, depth - 1) unless child.node_type == Node::TEXT_NODE
84
77
  end
85
78
  merge_texts!(hash, element) unless empty_content?(element)
86
79
  hash
@@ -156,7 +149,7 @@ module ActiveSupport
156
149
  child_nodes = element.child_nodes
157
150
  (0...child_nodes.length).each do |i|
158
151
  item = child_nodes.item(i)
159
- if item.node_type == Node.TEXT_NODE
152
+ if item.node_type == Node::TEXT_NODE
160
153
  texts << item.get_data
161
154
  end
162
155
  end
@@ -172,7 +165,7 @@ module ActiveSupport
172
165
  child_nodes = element.child_nodes
173
166
  (0...child_nodes.length).each do |i|
174
167
  item = child_nodes.item(i)
175
- if item.node_type == Node.TEXT_NODE
168
+ if item.node_type == Node::TEXT_NODE
176
169
  text << item.get_data.strip
177
170
  end
178
171
  end
@@ -5,7 +5,7 @@ require "active_support/core_ext/object/blank"
5
5
  require "stringio"
6
6
 
7
7
  module ActiveSupport
8
- module XmlMini_LibXML #:nodoc:
8
+ module XmlMini_LibXML # :nodoc:
9
9
  extend self
10
10
 
11
11
  # Parse an XML Document string or IO into a simple hash using libxml.
@@ -25,15 +25,15 @@ module ActiveSupport
25
25
  end
26
26
  end
27
27
 
28
- module LibXML #:nodoc:
29
- module Conversions #:nodoc:
30
- module Document #:nodoc:
28
+ module LibXML # :nodoc:
29
+ module Conversions # :nodoc:
30
+ module Document # :nodoc:
31
31
  def to_hash
32
32
  root.to_hash
33
33
  end
34
34
  end
35
35
 
36
- module Node #:nodoc:
36
+ module Node # :nodoc:
37
37
  CONTENT_ROOT = "__content__"
38
38
 
39
39
  # Convert XML document to hash.
@@ -5,7 +5,7 @@ require "active_support/core_ext/object/blank"
5
5
  require "stringio"
6
6
 
7
7
  module ActiveSupport
8
- module XmlMini_LibXMLSAX #:nodoc:
8
+ module XmlMini_LibXMLSAX # :nodoc:
9
9
  extend self
10
10
 
11
11
  # Class that will build the hash while the XML document
@@ -3,14 +3,14 @@
3
3
  begin
4
4
  require "nokogiri"
5
5
  rescue LoadError => e
6
- $stderr.puts "You don't have nokogiri installed in your application. Please add it to your Gemfile and run bundle install"
6
+ warn "You don't have nokogiri installed in your application. Please add it to your Gemfile and run bundle install"
7
7
  raise e
8
8
  end
9
9
  require "active_support/core_ext/object/blank"
10
10
  require "stringio"
11
11
 
12
12
  module ActiveSupport
13
- module XmlMini_Nokogiri #:nodoc:
13
+ module XmlMini_Nokogiri # :nodoc:
14
14
  extend self
15
15
 
16
16
  # Parse an XML Document string or IO into a simple hash using libxml / nokogiri.
@@ -30,14 +30,14 @@ module ActiveSupport
30
30
  end
31
31
  end
32
32
 
33
- module Conversions #:nodoc:
34
- module Document #:nodoc:
33
+ module Conversions # :nodoc:
34
+ module Document # :nodoc:
35
35
  def to_hash
36
36
  root.to_hash
37
37
  end
38
38
  end
39
39
 
40
- module Node #:nodoc:
40
+ module Node # :nodoc:
41
41
  CONTENT_ROOT = "__content__"
42
42
 
43
43
  # Convert XML document to hash.
@@ -3,14 +3,14 @@
3
3
  begin
4
4
  require "nokogiri"
5
5
  rescue LoadError => e
6
- $stderr.puts "You don't have nokogiri installed in your application. Please add it to your Gemfile and run bundle install"
6
+ warn "You don't have nokogiri installed in your application. Please add it to your Gemfile and run bundle install"
7
7
  raise e
8
8
  end
9
9
  require "active_support/core_ext/object/blank"
10
10
  require "stringio"
11
11
 
12
12
  module ActiveSupport
13
- module XmlMini_NokogiriSAX #:nodoc:
13
+ module XmlMini_NokogiriSAX # :nodoc:
14
14
  extend self
15
15
 
16
16
  # Class that will build the hash while the XML document
@@ -5,7 +5,7 @@ require "active_support/core_ext/object/blank"
5
5
  require "stringio"
6
6
 
7
7
  module ActiveSupport
8
- module XmlMini_REXML #:nodoc:
8
+ module XmlMini_REXML # :nodoc:
9
9
  extend self
10
10
 
11
11
  CONTENT_KEY = "__content__"
@@ -25,7 +25,7 @@ module ActiveSupport
25
25
  if data.eof?
26
26
  {}
27
27
  else
28
- silence_warnings { require "rexml/document" } unless defined?(REXML::Document)
28
+ require_rexml unless defined?(REXML::Document)
29
29
  doc = REXML::Document.new(data)
30
30
 
31
31
  if doc.root
@@ -38,6 +38,13 @@ module ActiveSupport
38
38
  end
39
39
 
40
40
  private
41
+ def require_rexml
42
+ silence_warnings { require "rexml/document" }
43
+ rescue LoadError => e
44
+ warn "You don't have rexml installed in your application. Please add it to your Gemfile and run bundle install"
45
+ raise e
46
+ end
47
+
41
48
  # Convert an XML element and merge into the hash
42
49
  #
43
50
  # hash::
@@ -9,17 +9,17 @@ require "active_support/core_ext/string/inflections"
9
9
  require "active_support/core_ext/date_time/calculations"
10
10
 
11
11
  module ActiveSupport
12
- # = XmlMini
12
+ # = \XmlMini
13
13
  #
14
14
  # To use the much faster libxml parser:
15
- # gem 'libxml-ruby', '=0.9.7'
15
+ # gem 'libxml-ruby'
16
16
  # XmlMini.backend = 'LibXML'
17
17
  module XmlMini
18
18
  extend self
19
19
 
20
20
  # This module decorates files deserialized using Hash.from_xml with
21
21
  # the <tt>original_filename</tt> and <tt>content_type</tt> methods.
22
- module FileLike #:nodoc:
22
+ module FileLike # :nodoc:
23
23
  attr_writer :original_filename, :content_type
24
24
 
25
25
  def original_filename
@@ -50,10 +50,11 @@ module ActiveSupport
50
50
  "Hash" => "hash"
51
51
  }
52
52
  end
53
+ TYPE_NAMES["ActiveSupport::TimeWithZone"] = TYPE_NAMES["Time"]
53
54
 
54
55
  FORMATTING = {
55
56
  "symbol" => Proc.new { |symbol| symbol.to_s },
56
- "date" => Proc.new { |date| date.to_s(:db) },
57
+ "date" => Proc.new { |date| date.to_fs(:db) },
57
58
  "dateTime" => Proc.new { |time| time.xmlschema },
58
59
  "binary" => Proc.new { |binary| ::Base64.encode64(binary) },
59
60
  "yaml" => Proc.new { |yaml| yaml.to_yaml }
@@ -180,11 +181,11 @@ module ActiveSupport
180
181
  end
181
182
 
182
183
  def current_thread_backend
183
- Thread.current[:xml_mini_backend]
184
+ IsolatedExecutionState[:xml_mini_backend]
184
185
  end
185
186
 
186
187
  def current_thread_backend=(name)
187
- Thread.current[:xml_mini_backend] = name && cast_backend_name_to_module(name)
188
+ IsolatedExecutionState[:xml_mini_backend] = name && cast_backend_name_to_module(name)
188
189
  end
189
190
 
190
191
  def cast_backend_name_to_module(name)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #--
4
- # Copyright (c) 2005-2019 David Heinemeier Hansson
4
+ # Copyright (c) David Heinemeier Hansson
5
5
  #
6
6
  # Permission is hereby granted, free of charge, to any person obtaining
7
7
  # a copy of this software and associated documentation files (the
@@ -26,25 +26,34 @@
26
26
  require "securerandom"
27
27
  require "active_support/dependencies/autoload"
28
28
  require "active_support/version"
29
+ require "active_support/deprecator"
29
30
  require "active_support/logger"
31
+ require "active_support/broadcast_logger"
30
32
  require "active_support/lazy_load_hooks"
31
33
  require "active_support/core_ext/date_and_time/compatibility"
32
34
 
35
+ # :include: activesupport/README.rdoc
33
36
  module ActiveSupport
34
37
  extend ActiveSupport::Autoload
35
38
 
36
39
  autoload :Concern
40
+ autoload :CodeGenerator
37
41
  autoload :ActionableError
42
+ autoload :ConfigurationFile
38
43
  autoload :CurrentAttributes
39
44
  autoload :Dependencies
40
45
  autoload :DescendantsTracker
41
46
  autoload :ExecutionWrapper
42
47
  autoload :Executor
48
+ autoload :ErrorReporter
43
49
  autoload :FileUpdateChecker
44
50
  autoload :EventedFileUpdateChecker
51
+ autoload :ForkTracker
45
52
  autoload :LogSubscriber
53
+ autoload :IsolatedExecutionState
46
54
  autoload :Notifications
47
55
  autoload :Reloader
56
+ autoload :SecureCompareRotator
48
57
 
49
58
  eager_autoload do
50
59
  autoload :BacktraceCleaner
@@ -55,18 +64,22 @@ module ActiveSupport
55
64
  autoload :Configurable
56
65
  autoload :Deprecation
57
66
  autoload :Digest
67
+ autoload :ExecutionContext
58
68
  autoload :Gzip
59
69
  autoload :Inflector
60
70
  autoload :JSON
61
71
  autoload :KeyGenerator
62
72
  autoload :MessageEncryptor
73
+ autoload :MessageEncryptors
63
74
  autoload :MessageVerifier
75
+ autoload :MessageVerifiers
64
76
  autoload :Multibyte
65
77
  autoload :NumberHelper
66
78
  autoload :OptionMerger
67
79
  autoload :OrderedHash
68
80
  autoload :OrderedOptions
69
81
  autoload :StringInquirer
82
+ autoload :EnvironmentInquirer
70
83
  autoload :TaggedLogging
71
84
  autoload :XmlMini
72
85
  autoload :ArrayInquirer
@@ -83,14 +96,40 @@ module ActiveSupport
83
96
  end
84
97
 
85
98
  cattr_accessor :test_order # :nodoc:
99
+ cattr_accessor :test_parallelization_threshold, default: 50 # :nodoc:
100
+
101
+ @error_reporter = ActiveSupport::ErrorReporter.new
102
+ singleton_class.attr_accessor :error_reporter # :nodoc:
103
+
104
+ def self.cache_format_version
105
+ Cache.format_version
106
+ end
107
+
108
+ def self.cache_format_version=(value)
109
+ Cache.format_version = value
110
+ end
86
111
 
87
112
  def self.to_time_preserves_timezone
88
113
  DateAndTime::Compatibility.preserve_timezone
89
114
  end
90
115
 
91
116
  def self.to_time_preserves_timezone=(value)
117
+ unless value
118
+ ActiveSupport.deprecator.warn(
119
+ "Support for the pre-Ruby 2.4 behavior of to_time has been deprecated and will be removed in Rails 7.2."
120
+ )
121
+ end
122
+
92
123
  DateAndTime::Compatibility.preserve_timezone = value
93
124
  end
125
+
126
+ def self.utc_to_local_returns_utc_offset_times
127
+ DateAndTime::Compatibility.utc_to_local_returns_utc_offset_times
128
+ end
129
+
130
+ def self.utc_to_local_returns_utc_offset_times=(value)
131
+ DateAndTime::Compatibility.utc_to_local_returns_utc_offset_times = value
132
+ end
94
133
  end
95
134
 
96
135
  autoload :I18n, "active_support/i18n"