activesupport 5.1.7 → 7.0.4.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activesupport might be problematic. Click here for more details.

Files changed (279) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +259 -585
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +6 -5
  5. data/lib/active_support/actionable_error.rb +48 -0
  6. data/lib/active_support/all.rb +2 -0
  7. data/lib/active_support/array_inquirer.rb +4 -2
  8. data/lib/active_support/backtrace_cleaner.rb +33 -5
  9. data/lib/active_support/benchmarkable.rb +5 -3
  10. data/lib/active_support/builder.rb +2 -0
  11. data/lib/active_support/cache/file_store.rb +50 -43
  12. data/lib/active_support/cache/mem_cache_store.rb +194 -67
  13. data/lib/active_support/cache/memory_store.rb +70 -34
  14. data/lib/active_support/cache/null_store.rb +18 -3
  15. data/lib/active_support/cache/redis_cache_store.rb +474 -0
  16. data/lib/active_support/cache/strategy/local_cache.rb +73 -50
  17. data/lib/active_support/cache/strategy/local_cache_middleware.rb +2 -0
  18. data/lib/active_support/cache.rb +556 -220
  19. data/lib/active_support/callbacks.rb +264 -159
  20. data/lib/active_support/code_generator.rb +65 -0
  21. data/lib/active_support/concern.rb +81 -8
  22. data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +16 -0
  23. data/lib/active_support/concurrency/share_lock.rb +4 -3
  24. data/lib/active_support/configurable.rb +17 -16
  25. data/lib/active_support/configuration_file.rb +51 -0
  26. data/lib/active_support/core_ext/array/access.rb +18 -8
  27. data/lib/active_support/core_ext/array/conversions.rb +20 -17
  28. data/lib/active_support/core_ext/array/deprecated_conversions.rb +25 -0
  29. data/lib/active_support/core_ext/array/extract.rb +21 -0
  30. data/lib/active_support/core_ext/array/extract_options.rb +2 -0
  31. data/lib/active_support/core_ext/array/grouping.rb +8 -6
  32. data/lib/active_support/core_ext/array/inquiry.rb +4 -2
  33. data/lib/active_support/core_ext/array/wrap.rb +2 -0
  34. data/lib/active_support/core_ext/array.rb +4 -1
  35. data/lib/active_support/core_ext/benchmark.rb +4 -2
  36. data/lib/active_support/core_ext/big_decimal/conversions.rb +3 -1
  37. data/lib/active_support/core_ext/big_decimal.rb +2 -0
  38. data/lib/active_support/core_ext/class/attribute.rb +50 -47
  39. data/lib/active_support/core_ext/class/attribute_accessors.rb +2 -0
  40. data/lib/active_support/core_ext/class/subclasses.rb +10 -24
  41. data/lib/active_support/core_ext/class.rb +2 -0
  42. data/lib/active_support/core_ext/date/acts_like.rb +2 -0
  43. data/lib/active_support/core_ext/date/blank.rb +3 -1
  44. data/lib/active_support/core_ext/date/calculations.rb +17 -14
  45. data/lib/active_support/core_ext/date/conversions.rb +24 -22
  46. data/lib/active_support/core_ext/date/deprecated_conversions.rb +26 -0
  47. data/lib/active_support/core_ext/date/zones.rb +2 -0
  48. data/lib/active_support/core_ext/date.rb +3 -0
  49. data/lib/active_support/core_ext/date_and_time/calculations.rb +65 -41
  50. data/lib/active_support/core_ext/date_and_time/compatibility.rb +18 -1
  51. data/lib/active_support/core_ext/date_and_time/zones.rb +2 -1
  52. data/lib/active_support/core_ext/date_time/acts_like.rb +2 -0
  53. data/lib/active_support/core_ext/date_time/blank.rb +3 -1
  54. data/lib/active_support/core_ext/date_time/calculations.rb +3 -1
  55. data/lib/active_support/core_ext/date_time/compatibility.rb +7 -5
  56. data/lib/active_support/core_ext/date_time/conversions.rb +15 -14
  57. data/lib/active_support/core_ext/date_time/deprecated_conversions.rb +22 -0
  58. data/lib/active_support/core_ext/date_time.rb +3 -0
  59. data/lib/active_support/core_ext/digest/uuid.rb +42 -14
  60. data/lib/active_support/core_ext/digest.rb +3 -0
  61. data/lib/active_support/core_ext/enumerable.rb +244 -72
  62. data/lib/active_support/core_ext/file/atomic.rb +6 -2
  63. data/lib/active_support/core_ext/file.rb +2 -0
  64. data/lib/active_support/core_ext/hash/conversions.rb +7 -6
  65. data/lib/active_support/core_ext/hash/deep_merge.rb +8 -12
  66. data/lib/active_support/core_ext/hash/deep_transform_values.rb +46 -0
  67. data/lib/active_support/core_ext/hash/except.rb +4 -2
  68. data/lib/active_support/core_ext/hash/indifferent_access.rb +5 -3
  69. data/lib/active_support/core_ext/hash/keys.rb +4 -31
  70. data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
  71. data/lib/active_support/core_ext/hash/slice.rb +8 -29
  72. data/lib/active_support/core_ext/hash.rb +3 -2
  73. data/lib/active_support/core_ext/integer/inflections.rb +2 -0
  74. data/lib/active_support/core_ext/integer/multiple.rb +3 -1
  75. data/lib/active_support/core_ext/integer/time.rb +7 -14
  76. data/lib/active_support/core_ext/integer.rb +2 -0
  77. data/lib/active_support/core_ext/kernel/concern.rb +2 -0
  78. data/lib/active_support/core_ext/kernel/reporting.rb +6 -4
  79. data/lib/active_support/core_ext/kernel/singleton_class.rb +3 -1
  80. data/lib/active_support/core_ext/kernel.rb +2 -1
  81. data/lib/active_support/core_ext/load_error.rb +3 -8
  82. data/lib/active_support/core_ext/module/aliasing.rb +2 -0
  83. data/lib/active_support/core_ext/module/anonymous.rb +2 -0
  84. data/lib/active_support/core_ext/module/attr_internal.rb +4 -2
  85. data/lib/active_support/core_ext/module/attribute_accessors.rb +46 -56
  86. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +36 -27
  87. data/lib/active_support/core_ext/module/concerning.rb +15 -10
  88. data/lib/active_support/core_ext/module/delegation.rb +97 -58
  89. data/lib/active_support/core_ext/module/deprecation.rb +2 -0
  90. data/lib/active_support/core_ext/module/introspection.rb +18 -15
  91. data/lib/active_support/core_ext/module/redefine_method.rb +40 -0
  92. data/lib/active_support/core_ext/module/remove_method.rb +5 -23
  93. data/lib/active_support/core_ext/module.rb +3 -1
  94. data/lib/active_support/core_ext/name_error.rb +30 -2
  95. data/lib/active_support/core_ext/numeric/bytes.rb +2 -0
  96. data/lib/active_support/core_ext/numeric/conversions.rb +134 -129
  97. data/lib/active_support/core_ext/numeric/deprecated_conversions.rb +60 -0
  98. data/lib/active_support/core_ext/numeric/time.rb +7 -15
  99. data/lib/active_support/core_ext/numeric.rb +3 -1
  100. data/lib/active_support/core_ext/object/acts_like.rb +41 -6
  101. data/lib/active_support/core_ext/object/blank.rb +15 -5
  102. data/lib/active_support/core_ext/object/conversions.rb +2 -0
  103. data/lib/active_support/core_ext/object/deep_dup.rb +3 -1
  104. data/lib/active_support/core_ext/object/duplicable.rb +16 -110
  105. data/lib/active_support/core_ext/object/inclusion.rb +2 -0
  106. data/lib/active_support/core_ext/object/instance_variables.rb +2 -0
  107. data/lib/active_support/core_ext/object/json.rb +51 -26
  108. data/lib/active_support/core_ext/object/to_param.rb +2 -0
  109. data/lib/active_support/core_ext/object/to_query.rb +4 -2
  110. data/lib/active_support/core_ext/object/try.rb +26 -14
  111. data/lib/active_support/core_ext/object/with_options.rb +24 -3
  112. data/lib/active_support/core_ext/object.rb +2 -0
  113. data/lib/active_support/core_ext/pathname/existence.rb +21 -0
  114. data/lib/active_support/core_ext/pathname.rb +3 -0
  115. data/lib/active_support/core_ext/range/compare_range.rb +57 -0
  116. data/lib/active_support/core_ext/range/conversions.rb +35 -25
  117. data/lib/active_support/core_ext/range/deprecated_conversions.rb +26 -0
  118. data/lib/active_support/core_ext/range/each.rb +6 -3
  119. data/lib/active_support/core_ext/range/include_time_with_zone.rb +7 -0
  120. data/lib/active_support/core_ext/range/overlaps.rb +3 -1
  121. data/lib/active_support/core_ext/range.rb +4 -1
  122. data/lib/active_support/core_ext/regexp.rb +10 -5
  123. data/lib/active_support/core_ext/securerandom.rb +25 -3
  124. data/lib/active_support/core_ext/string/access.rb +7 -16
  125. data/lib/active_support/core_ext/string/behavior.rb +2 -0
  126. data/lib/active_support/core_ext/string/conversions.rb +5 -2
  127. data/lib/active_support/core_ext/string/exclude.rb +2 -0
  128. data/lib/active_support/core_ext/string/filters.rb +44 -1
  129. data/lib/active_support/core_ext/string/indent.rb +2 -0
  130. data/lib/active_support/core_ext/string/inflections.rb +69 -16
  131. data/lib/active_support/core_ext/string/inquiry.rb +4 -1
  132. data/lib/active_support/core_ext/string/multibyte.rb +9 -4
  133. data/lib/active_support/core_ext/string/output_safety.rb +135 -27
  134. data/lib/active_support/core_ext/string/starts_ends_with.rb +4 -2
  135. data/lib/active_support/core_ext/string/strip.rb +5 -1
  136. data/lib/active_support/core_ext/string/zones.rb +2 -0
  137. data/lib/active_support/core_ext/string.rb +2 -0
  138. data/lib/active_support/core_ext/symbol/starts_ends_with.rb +6 -0
  139. data/lib/active_support/core_ext/symbol.rb +3 -0
  140. data/lib/active_support/core_ext/time/acts_like.rb +2 -0
  141. data/lib/active_support/core_ext/time/calculations.rb +81 -24
  142. data/lib/active_support/core_ext/time/compatibility.rb +4 -2
  143. data/lib/active_support/core_ext/time/conversions.rb +17 -12
  144. data/lib/active_support/core_ext/time/deprecated_conversions.rb +22 -0
  145. data/lib/active_support/core_ext/time/zones.rb +12 -25
  146. data/lib/active_support/core_ext/time.rb +3 -0
  147. data/lib/active_support/core_ext/uri.rb +4 -23
  148. data/lib/active_support/core_ext.rb +4 -1
  149. data/lib/active_support/current_attributes/test_helper.rb +13 -0
  150. data/lib/active_support/current_attributes.rb +226 -0
  151. data/lib/active_support/dependencies/autoload.rb +2 -0
  152. data/lib/active_support/dependencies/interlock.rb +12 -18
  153. data/lib/active_support/dependencies/require_dependency.rb +28 -0
  154. data/lib/active_support/dependencies.rb +59 -715
  155. data/lib/active_support/deprecation/behaviors.rb +48 -13
  156. data/lib/active_support/deprecation/constant_accessor.rb +4 -2
  157. data/lib/active_support/deprecation/disallowed.rb +56 -0
  158. data/lib/active_support/deprecation/instance_delegator.rb +2 -1
  159. data/lib/active_support/deprecation/method_wrappers.rb +29 -21
  160. data/lib/active_support/deprecation/proxy_wrappers.rb +34 -8
  161. data/lib/active_support/deprecation/reporting.rb +54 -9
  162. data/lib/active_support/deprecation.rb +10 -3
  163. data/lib/active_support/descendants_tracker.rb +192 -34
  164. data/lib/active_support/digest.rb +22 -0
  165. data/lib/active_support/duration/iso8601_parser.rb +9 -9
  166. data/lib/active_support/duration/iso8601_serializer.rb +29 -15
  167. data/lib/active_support/duration.rb +158 -72
  168. data/lib/active_support/encrypted_configuration.rb +56 -0
  169. data/lib/active_support/encrypted_file.rb +129 -0
  170. data/lib/active_support/environment_inquirer.rb +20 -0
  171. data/lib/active_support/error_reporter.rb +117 -0
  172. data/lib/active_support/evented_file_update_checker.rb +87 -122
  173. data/lib/active_support/execution_context/test_helper.rb +13 -0
  174. data/lib/active_support/execution_context.rb +53 -0
  175. data/lib/active_support/execution_wrapper.rb +46 -21
  176. data/lib/active_support/executor/test_helper.rb +7 -0
  177. data/lib/active_support/executor.rb +2 -0
  178. data/lib/active_support/file_update_checker.rb +2 -1
  179. data/lib/active_support/fork_tracker.rb +71 -0
  180. data/lib/active_support/gem_version.rb +7 -5
  181. data/lib/active_support/gzip.rb +2 -0
  182. data/lib/active_support/hash_with_indifferent_access.rb +126 -42
  183. data/lib/active_support/html_safe_translation.rb +43 -0
  184. data/lib/active_support/i18n.rb +5 -1
  185. data/lib/active_support/i18n_railtie.rb +19 -14
  186. data/lib/active_support/inflections.rb +2 -0
  187. data/lib/active_support/inflector/inflections.rb +41 -14
  188. data/lib/active_support/inflector/methods.rb +73 -87
  189. data/lib/active_support/inflector/transliterate.rb +56 -18
  190. data/lib/active_support/inflector.rb +2 -0
  191. data/lib/active_support/isolated_execution_state.rb +72 -0
  192. data/lib/active_support/json/decoding.rb +27 -26
  193. data/lib/active_support/json/encoding.rb +16 -6
  194. data/lib/active_support/json.rb +2 -0
  195. data/lib/active_support/key_generator.rb +25 -38
  196. data/lib/active_support/lazy_load_hooks.rb +35 -6
  197. data/lib/active_support/locale/en.rb +33 -0
  198. data/lib/active_support/locale/en.yml +8 -4
  199. data/lib/active_support/log_subscriber/test_helper.rb +4 -2
  200. data/lib/active_support/log_subscriber.rb +54 -13
  201. data/lib/active_support/logger.rb +4 -17
  202. data/lib/active_support/logger_silence.rb +13 -20
  203. data/lib/active_support/logger_thread_safe_level.rb +48 -10
  204. data/lib/active_support/message_encryptor.rb +111 -37
  205. data/lib/active_support/message_verifier.rb +124 -21
  206. data/lib/active_support/messages/metadata.rb +80 -0
  207. data/lib/active_support/messages/rotation_configuration.rb +23 -0
  208. data/lib/active_support/messages/rotator.rb +57 -0
  209. data/lib/active_support/multibyte/chars.rb +19 -76
  210. data/lib/active_support/multibyte/unicode.rb +9 -331
  211. data/lib/active_support/multibyte.rb +3 -1
  212. data/lib/active_support/notifications/fanout.rb +165 -37
  213. data/lib/active_support/notifications/instrumenter.rb +92 -11
  214. data/lib/active_support/notifications.rb +96 -30
  215. data/lib/active_support/number_helper/number_converter.rb +8 -9
  216. data/lib/active_support/number_helper/number_to_currency_converter.rb +14 -12
  217. data/lib/active_support/number_helper/number_to_delimited_converter.rb +6 -3
  218. data/lib/active_support/number_helper/number_to_human_converter.rb +6 -3
  219. data/lib/active_support/number_helper/number_to_human_size_converter.rb +7 -4
  220. data/lib/active_support/number_helper/number_to_percentage_converter.rb +5 -1
  221. data/lib/active_support/number_helper/number_to_phone_converter.rb +6 -3
  222. data/lib/active_support/number_helper/number_to_rounded_converter.rb +14 -27
  223. data/lib/active_support/number_helper/rounding_helper.rb +16 -34
  224. data/lib/active_support/number_helper.rb +38 -12
  225. data/lib/active_support/option_merger.rb +19 -6
  226. data/lib/active_support/ordered_hash.rb +4 -2
  227. data/lib/active_support/ordered_options.rb +18 -6
  228. data/lib/active_support/parameter_filter.rb +138 -0
  229. data/lib/active_support/per_thread_registry.rb +8 -1
  230. data/lib/active_support/proxy_object.rb +2 -0
  231. data/lib/active_support/rails.rb +3 -10
  232. data/lib/active_support/railtie.rb +112 -11
  233. data/lib/active_support/reloader.rb +12 -11
  234. data/lib/active_support/rescuable.rb +19 -18
  235. data/lib/active_support/ruby_features.rb +7 -0
  236. data/lib/active_support/secure_compare_rotator.rb +51 -0
  237. data/lib/active_support/security_utils.rb +26 -15
  238. data/lib/active_support/string_inquirer.rb +4 -3
  239. data/lib/active_support/subscriber.rb +81 -42
  240. data/lib/active_support/tagged_logging.rb +45 -9
  241. data/lib/active_support/test_case.rb +86 -2
  242. data/lib/active_support/testing/assertions.rb +89 -21
  243. data/lib/active_support/testing/autorun.rb +2 -0
  244. data/lib/active_support/testing/constant_lookup.rb +2 -0
  245. data/lib/active_support/testing/declarative.rb +2 -0
  246. data/lib/active_support/testing/deprecation.rb +54 -2
  247. data/lib/active_support/testing/file_fixtures.rb +4 -0
  248. data/lib/active_support/testing/isolation.rb +6 -4
  249. data/lib/active_support/testing/method_call_assertions.rb +34 -5
  250. data/lib/active_support/testing/parallelization/server.rb +82 -0
  251. data/lib/active_support/testing/parallelization/worker.rb +103 -0
  252. data/lib/active_support/testing/parallelization.rb +55 -0
  253. data/lib/active_support/testing/parallelize_executor.rb +76 -0
  254. data/lib/active_support/testing/setup_and_teardown.rb +12 -7
  255. data/lib/active_support/testing/stream.rb +6 -7
  256. data/lib/active_support/testing/tagged_logging.rb +3 -1
  257. data/lib/active_support/testing/time_helpers.rb +91 -15
  258. data/lib/active_support/time.rb +2 -0
  259. data/lib/active_support/time_with_zone.rb +168 -56
  260. data/lib/active_support/values/time_zone.rb +85 -37
  261. data/lib/active_support/version.rb +3 -1
  262. data/lib/active_support/xml_mini/jdom.rb +6 -5
  263. data/lib/active_support/xml_mini/libxml.rb +9 -7
  264. data/lib/active_support/xml_mini/libxmlsax.rb +7 -5
  265. data/lib/active_support/xml_mini/nokogiri.rb +8 -6
  266. data/lib/active_support/xml_mini/nokogirisax.rb +6 -4
  267. data/lib/active_support/xml_mini/rexml.rb +13 -4
  268. data/lib/active_support/xml_mini.rb +10 -15
  269. data/lib/active_support.rb +30 -9
  270. metadata +76 -35
  271. data/lib/active_support/core_ext/array/prepend_and_append.rb +0 -7
  272. data/lib/active_support/core_ext/hash/compact.rb +0 -27
  273. data/lib/active_support/core_ext/hash/transform_values.rb +0 -30
  274. data/lib/active_support/core_ext/kernel/agnostics.rb +0 -11
  275. data/lib/active_support/core_ext/marshal.rb +0 -22
  276. data/lib/active_support/core_ext/module/reachable.rb +0 -8
  277. data/lib/active_support/core_ext/numeric/inquiry.rb +0 -26
  278. data/lib/active_support/core_ext/range/include_range.rb +0 -23
  279. data/lib/active_support/values/unicode_tables.dat +0 -0
@@ -1,18 +1,19 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "tzinfo"
2
4
  require "concurrent/map"
3
- require "active_support/core_ext/object/blank"
4
5
 
5
6
  module ActiveSupport
6
- # The TimeZone class serves as a wrapper around TZInfo::Timezone instances.
7
+ # The TimeZone class serves as a wrapper around <tt>TZInfo::Timezone</tt> instances.
7
8
  # It allows us to do the following:
8
9
  #
9
- # * Limit the set of zones provided by TZInfo to a meaningful subset of 146
10
+ # * Limit the set of zones provided by TZInfo to a meaningful subset of 134
10
11
  # zones.
11
12
  # * Retrieve and display zones with a friendlier name
12
13
  # (e.g., "Eastern Time (US & Canada)" instead of "America/New_York").
13
- # * Lazily load TZInfo::Timezone instances only when they're needed.
14
+ # * Lazily load <tt>TZInfo::Timezone</tt> instances only when they're needed.
14
15
  # * Create ActiveSupport::TimeWithZone instances via TimeZone's +local+,
15
- # +parse+, +at+ and +now+ methods.
16
+ # +parse+, +at+, and +now+ methods.
16
17
  #
17
18
  # If you set <tt>config.time_zone</tt> in the Rails Application, you can
18
19
  # access this TimeZone object via <tt>Time.zone</tt>:
@@ -28,7 +29,7 @@ module ActiveSupport
28
29
  class TimeZone
29
30
  # Keys are Rails TimeZone names, values are TZInfo identifiers.
30
31
  MAPPING = {
31
- "International Date Line West" => "Pacific/Midway",
32
+ "International Date Line West" => "Etc/GMT+12",
32
33
  "Midway Island" => "Pacific/Midway",
33
34
  "American Samoa" => "Pacific/Pago_Pago",
34
35
  "Hawaii" => "Pacific/Honolulu",
@@ -59,6 +60,7 @@ module ActiveSupport
59
60
  "Buenos Aires" => "America/Argentina/Buenos_Aires",
60
61
  "Montevideo" => "America/Montevideo",
61
62
  "Georgetown" => "America/Guyana",
63
+ "Puerto Rico" => "America/Puerto_Rico",
62
64
  "Greenland" => "America/Godthab",
63
65
  "Mid-Atlantic" => "Atlantic/South_Georgia",
64
66
  "Azores" => "Atlantic/Azores",
@@ -180,8 +182,9 @@ module ActiveSupport
180
182
  "Samoa" => "Pacific/Apia"
181
183
  }
182
184
 
183
- UTC_OFFSET_WITH_COLON = "%s%02d:%02d"
184
- UTC_OFFSET_WITHOUT_COLON = UTC_OFFSET_WITH_COLON.tr(":", "")
185
+ UTC_OFFSET_WITH_COLON = "%s%02d:%02d" # :nodoc:
186
+ UTC_OFFSET_WITHOUT_COLON = UTC_OFFSET_WITH_COLON.tr(":", "") # :nodoc:
187
+ private_constant :UTC_OFFSET_WITH_COLON, :UTC_OFFSET_WITHOUT_COLON
185
188
 
186
189
  @lazy_zones_map = Concurrent::Map.new
187
190
  @country_zones = Concurrent::Map.new
@@ -200,7 +203,7 @@ module ActiveSupport
200
203
  end
201
204
 
202
205
  def find_tzinfo(name)
203
- TZInfo::Timezone.new(MAPPING[name] || name)
206
+ TZInfo::Timezone.get(MAPPING[name] || name)
204
207
  end
205
208
 
206
209
  alias_method :create, :new
@@ -226,16 +229,20 @@ module ActiveSupport
226
229
  # Returns +nil+ if no such time zone is known to the system.
227
230
  def [](arg)
228
231
  case arg
232
+ when self
233
+ arg
229
234
  when String
230
235
  begin
231
236
  @lazy_zones_map[arg] ||= create(arg)
232
237
  rescue TZInfo::InvalidTimezoneIdentifier
233
238
  nil
234
239
  end
240
+ when TZInfo::Timezone
241
+ @lazy_zones_map[arg.name] ||= create(arg.name, nil, arg)
235
242
  when Numeric, ActiveSupport::Duration
236
243
  arg *= 3600 if arg.abs <= 13
237
244
  all.find { |z| z.utc_offset == arg.to_i }
238
- else
245
+ else
239
246
  raise ArgumentError, "invalid argument to TimeZone[]: #{arg.inspect}"
240
247
  end
241
248
  end
@@ -253,25 +260,32 @@ module ActiveSupport
253
260
  @country_zones[code] ||= load_country_zones(code)
254
261
  end
255
262
 
263
+ def clear # :nodoc:
264
+ @lazy_zones_map = Concurrent::Map.new
265
+ @country_zones = Concurrent::Map.new
266
+ @zones = nil
267
+ @zones_map = nil
268
+ end
269
+
256
270
  private
257
271
  def load_country_zones(code)
258
272
  country = TZInfo::Country.get(code)
259
- country.zone_identifiers.map do |tz_id|
273
+ country.zone_identifiers.flat_map do |tz_id|
260
274
  if MAPPING.value?(tz_id)
261
275
  MAPPING.inject([]) do |memo, (key, value)|
262
276
  memo << self[key] if value == tz_id
263
277
  memo
264
278
  end
265
279
  else
266
- create(tz_id, nil, TZInfo::Timezone.new(tz_id))
280
+ create(tz_id, nil, TZInfo::Timezone.get(tz_id))
267
281
  end
268
- end.flatten(1).sort!
282
+ end.sort!
269
283
  end
270
284
 
271
285
  def zones_map
272
- @zones_map ||= begin
273
- MAPPING.each_key { |place| self[place] } # load all the zones
274
- @lazy_zones_map
286
+ @zones_map ||= MAPPING.each_with_object({}) do |(name, _), zones|
287
+ timezone = self[name]
288
+ zones[name] = timezone if timezone
275
289
  end
276
290
  end
277
291
  end
@@ -292,11 +306,7 @@ module ActiveSupport
292
306
 
293
307
  # Returns the offset of this time zone from UTC in seconds.
294
308
  def utc_offset
295
- if @utc_offset
296
- @utc_offset
297
- else
298
- tzinfo.current_period.utc_offset if tzinfo && tzinfo.current_period
299
- end
309
+ @utc_offset || tzinfo&.current_period&.base_utc_offset
300
310
  end
301
311
 
302
312
  # Returns a formatted string of the offset from UTC, or an alternative
@@ -324,6 +334,13 @@ module ActiveSupport
324
334
  re === name || re === MAPPING[name]
325
335
  end
326
336
 
337
+ # Compare #name and TZInfo identifier to a supplied regexp, returning +true+
338
+ # if a match is found.
339
+ def match?(re)
340
+ (re == name) || (re == MAPPING[name]) ||
341
+ ((Regexp === re) && (re.match?(name) || re.match?(MAPPING[name])))
342
+ end
343
+
327
344
  # Returns a textual representation of this time zone.
328
345
  def to_s
329
346
  "(GMT#{formatted_offset}) #{name}"
@@ -345,8 +362,13 @@ module ActiveSupport
345
362
  # Time.zone = 'Hawaii' # => "Hawaii"
346
363
  # Time.utc(2000).to_f # => 946684800.0
347
364
  # Time.zone.at(946684800.0) # => Fri, 31 Dec 1999 14:00:00 HST -10:00
348
- def at(secs)
349
- Time.at(secs).utc.in_time_zone(self)
365
+ #
366
+ # A second argument can be supplied to specify sub-second precision.
367
+ #
368
+ # Time.zone = 'Hawaii' # => "Hawaii"
369
+ # Time.at(946684800, 123456.789).nsec # => 123456789
370
+ def at(*args)
371
+ Time.at(*args).utc.in_time_zone(self)
350
372
  end
351
373
 
352
374
  # Method for creating new ActiveSupport::TimeWithZone instance in time zone
@@ -361,16 +383,30 @@ module ActiveSupport
361
383
  # Time.zone.iso8601('1999-12-31') # => Fri, 31 Dec 1999 00:00:00 HST -10:00
362
384
  #
363
385
  # If the string is invalid then an +ArgumentError+ will be raised unlike +parse+
364
- # which returns +nil+ when given an invalid date string.
386
+ # which usually returns +nil+ when given an invalid date string.
365
387
  def iso8601(str)
388
+ # Historically `Date._iso8601(nil)` returns `{}`, but in the `date` gem versions `3.2.1`, `3.1.2`, `3.0.2`,
389
+ # and `2.0.1`, `Date._iso8601(nil)` raises `TypeError` https://github.com/ruby/date/issues/39
390
+ # Future `date` releases are expected to revert back to the original behavior.
391
+ raise ArgumentError, "invalid date" if str.nil?
392
+
366
393
  parts = Date._iso8601(str)
367
394
 
368
- raise ArgumentError, "invalid date" if parts.empty?
395
+ year = parts.fetch(:year)
396
+
397
+ if parts.key?(:yday)
398
+ ordinal_date = Date.ordinal(year, parts.fetch(:yday))
399
+ month = ordinal_date.month
400
+ day = ordinal_date.day
401
+ else
402
+ month = parts.fetch(:mon)
403
+ day = parts.fetch(:mday)
404
+ end
369
405
 
370
406
  time = Time.new(
371
- parts.fetch(:year),
372
- parts.fetch(:mon),
373
- parts.fetch(:mday),
407
+ year,
408
+ month,
409
+ day,
374
410
  parts.fetch(:hour, 0),
375
411
  parts.fetch(:min, 0),
376
412
  parts.fetch(:sec, 0) + parts.fetch(:sec_fraction, 0),
@@ -382,6 +418,9 @@ module ActiveSupport
382
418
  else
383
419
  TimeWithZone.new(nil, self, time)
384
420
  end
421
+
422
+ rescue Date::Error, KeyError
423
+ raise ArgumentError, "invalid date"
385
424
  end
386
425
 
387
426
  # Method for creating new ActiveSupport::TimeWithZone instance in time zone
@@ -400,6 +439,8 @@ module ActiveSupport
400
439
  # components are supplied, then the day of the month defaults to 1:
401
440
  #
402
441
  # Time.zone.parse('Mar 2000') # => Wed, 01 Mar 2000 00:00:00 HST -10:00
442
+ #
443
+ # If the string is invalid then an +ArgumentError+ could be raised.
403
444
  def parse(str, now = now())
404
445
  parts_to_time(Date._parse(str, false), now)
405
446
  end
@@ -483,10 +524,17 @@ module ActiveSupport
483
524
  end
484
525
 
485
526
  # Adjust the given time to the simultaneous time in the time zone
486
- # represented by +self+. Returns a Time.utc() instance -- if you want an
487
- # ActiveSupport::TimeWithZone instance, use Time#in_time_zone() instead.
527
+ # represented by +self+. Returns a local time with the appropriate offset
528
+ # -- if you want an ActiveSupport::TimeWithZone instance, use
529
+ # Time#in_time_zone() instead.
530
+ #
531
+ # As of tzinfo 2, utc_to_local returns a Time with a non-zero utc_offset.
532
+ # See the +utc_to_local_returns_utc_offset_times+ config for more info.
488
533
  def utc_to_local(time)
489
- tzinfo.utc_to_local(time)
534
+ tzinfo.utc_to_local(time).yield_self do |t|
535
+ ActiveSupport.utc_to_local_returns_utc_offset_times ?
536
+ t : Time.utc(t.year, t.month, t.day, t.hour, t.min, t.sec, t.sec_fraction * 1_000_000)
537
+ end
490
538
  end
491
539
 
492
540
  # Adjust the given time to the simultaneous time in UTC. Returns a
@@ -495,27 +543,27 @@ module ActiveSupport
495
543
  tzinfo.local_to_utc(time, dst)
496
544
  end
497
545
 
498
- # Available so that TimeZone instances respond like TZInfo::Timezone
546
+ # Available so that TimeZone instances respond like <tt>TZInfo::Timezone</tt>
499
547
  # instances.
500
548
  def period_for_utc(time)
501
549
  tzinfo.period_for_utc(time)
502
550
  end
503
551
 
504
- # Available so that TimeZone instances respond like TZInfo::Timezone
552
+ # Available so that TimeZone instances respond like <tt>TZInfo::Timezone</tt>
505
553
  # instances.
506
554
  def period_for_local(time, dst = true)
507
- tzinfo.period_for_local(time, dst)
555
+ tzinfo.period_for_local(time, dst) { |periods| periods.last }
508
556
  end
509
557
 
510
- def periods_for_local(time) #:nodoc:
558
+ def periods_for_local(time) # :nodoc:
511
559
  tzinfo.periods_for_local(time)
512
560
  end
513
561
 
514
- def init_with(coder) #:nodoc:
562
+ def init_with(coder) # :nodoc:
515
563
  initialize(coder["name"])
516
564
  end
517
565
 
518
- def encode_with(coder) #:nodoc:
566
+ def encode_with(coder) # :nodoc:
519
567
  coder.tag = "!ruby/object:#{self.class}"
520
568
  coder.map = { "name" => tzinfo.name }
521
569
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "gem_version"
2
4
 
3
5
  module ActiveSupport
4
- # 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 <tt>Gem::Version</tt>.
5
7
  def self.version
6
8
  gem_version
7
9
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  raise "JRuby is required to use the JDOM backend for XmlMini" unless RUBY_PLATFORM.include?("java")
2
4
 
3
5
  require "jruby"
@@ -13,10 +15,10 @@ java_import org.xml.sax.Attributes unless defined? Attributes
13
15
  java_import org.w3c.dom.Node unless defined? Node
14
16
 
15
17
  module ActiveSupport
16
- module XmlMini_JDOM #:nodoc:
18
+ module XmlMini_JDOM # :nodoc:
17
19
  extend self
18
20
 
19
- CONTENT_KEY = "__content__".freeze
21
+ CONTENT_KEY = "__content__"
20
22
 
21
23
  NODE_TYPE_NAMES = %w{ATTRIBUTE_NODE CDATA_SECTION_NODE COMMENT_NODE DOCUMENT_FRAGMENT_NODE
22
24
  DOCUMENT_NODE DOCUMENT_TYPE_NODE ELEMENT_NODE ENTITY_NODE ENTITY_REFERENCE_NODE NOTATION_NODE
@@ -38,7 +40,7 @@ module ActiveSupport
38
40
  else
39
41
  @dbf = DocumentBuilderFactory.new_instance
40
42
  # secure processing of java xml
41
- # http://www.ibm.com/developerworks/xml/library/x-tipcfsx/index.html
43
+ # https://archive.is/9xcQQ
42
44
  @dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)
43
45
  @dbf.setFeature("http://xml.org/sax/features/external-general-entities", false)
44
46
  @dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false)
@@ -51,7 +53,6 @@ module ActiveSupport
51
53
  end
52
54
 
53
55
  private
54
-
55
56
  # Convert an XML element and merge into the hash
56
57
  #
57
58
  # hash::
@@ -167,7 +168,7 @@ module ActiveSupport
167
168
  # element::
168
169
  # XML element to be checked.
169
170
  def empty_content?(element)
170
- text = ""
171
+ text = +""
171
172
  child_nodes = element.child_nodes
172
173
  (0...child_nodes.length).each do |i|
173
174
  item = child_nodes.item(i)
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "libxml"
2
4
  require "active_support/core_ext/object/blank"
3
5
  require "stringio"
4
6
 
5
7
  module ActiveSupport
6
- module XmlMini_LibXML #:nodoc:
8
+ module XmlMini_LibXML # :nodoc:
7
9
  extend self
8
10
 
9
11
  # Parse an XML Document string or IO into a simple hash using libxml.
@@ -23,16 +25,16 @@ module ActiveSupport
23
25
  end
24
26
  end
25
27
 
26
- module LibXML #:nodoc:
27
- module Conversions #:nodoc:
28
- module Document #:nodoc:
28
+ module LibXML # :nodoc:
29
+ module Conversions # :nodoc:
30
+ module Document # :nodoc:
29
31
  def to_hash
30
32
  root.to_hash
31
33
  end
32
34
  end
33
35
 
34
- module Node #:nodoc:
35
- CONTENT_ROOT = "__content__".freeze
36
+ module Node # :nodoc:
37
+ CONTENT_ROOT = "__content__"
36
38
 
37
39
  # Convert XML document to hash.
38
40
  #
@@ -53,7 +55,7 @@ module LibXML #:nodoc:
53
55
  if c.element?
54
56
  c.to_hash(node_hash)
55
57
  elsif c.text? || c.cdata?
56
- node_hash[CONTENT_ROOT] ||= ""
58
+ node_hash[CONTENT_ROOT] ||= +""
57
59
  node_hash[CONTENT_ROOT] << c.content
58
60
  end
59
61
  end
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "libxml"
2
4
  require "active_support/core_ext/object/blank"
3
5
  require "stringio"
4
6
 
5
7
  module ActiveSupport
6
- module XmlMini_LibXMLSAX #:nodoc:
8
+ module XmlMini_LibXMLSAX # :nodoc:
7
9
  extend self
8
10
 
9
11
  # Class that will build the hash while the XML document
@@ -11,8 +13,8 @@ module ActiveSupport
11
13
  class HashBuilder
12
14
  include LibXML::XML::SaxParser::Callbacks
13
15
 
14
- CONTENT_KEY = "__content__".freeze
15
- HASH_SIZE_KEY = "__hash_size__".freeze
16
+ CONTENT_KEY = "__content__"
17
+ HASH_SIZE_KEY = "__hash_size__"
16
18
 
17
19
  attr_reader :hash
18
20
 
@@ -21,7 +23,7 @@ module ActiveSupport
21
23
  end
22
24
 
23
25
  def on_start_document
24
- @hash = { CONTENT_KEY => "" }
26
+ @hash = { CONTENT_KEY => +"" }
25
27
  @hash_stack = [@hash]
26
28
  end
27
29
 
@@ -31,7 +33,7 @@ module ActiveSupport
31
33
  end
32
34
 
33
35
  def on_start_element(name, attrs = {})
34
- new_hash = { CONTENT_KEY => "" }.merge!(attrs)
36
+ new_hash = { CONTENT_KEY => +"" }.merge!(attrs)
35
37
  new_hash[HASH_SIZE_KEY] = new_hash.size + 1
36
38
 
37
39
  case current_hash[name]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require "nokogiri"
3
5
  rescue LoadError => e
@@ -8,7 +10,7 @@ require "active_support/core_ext/object/blank"
8
10
  require "stringio"
9
11
 
10
12
  module ActiveSupport
11
- module XmlMini_Nokogiri #:nodoc:
13
+ module XmlMini_Nokogiri # :nodoc:
12
14
  extend self
13
15
 
14
16
  # Parse an XML Document string or IO into a simple hash using libxml / nokogiri.
@@ -28,15 +30,15 @@ module ActiveSupport
28
30
  end
29
31
  end
30
32
 
31
- module Conversions #:nodoc:
32
- module Document #:nodoc:
33
+ module Conversions # :nodoc:
34
+ module Document # :nodoc:
33
35
  def to_hash
34
36
  root.to_hash
35
37
  end
36
38
  end
37
39
 
38
- module Node #:nodoc:
39
- CONTENT_ROOT = "__content__".freeze
40
+ module Node # :nodoc:
41
+ CONTENT_ROOT = "__content__"
40
42
 
41
43
  # Convert XML document to hash.
42
44
  #
@@ -57,7 +59,7 @@ module ActiveSupport
57
59
  if c.element?
58
60
  c.to_hash(node_hash)
59
61
  elsif c.text? || c.cdata?
60
- node_hash[CONTENT_ROOT] ||= ""
62
+ node_hash[CONTENT_ROOT] ||= +""
61
63
  node_hash[CONTENT_ROOT] << c.content
62
64
  end
63
65
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require "nokogiri"
3
5
  rescue LoadError => e
@@ -8,14 +10,14 @@ require "active_support/core_ext/object/blank"
8
10
  require "stringio"
9
11
 
10
12
  module ActiveSupport
11
- module XmlMini_NokogiriSAX #:nodoc:
13
+ module XmlMini_NokogiriSAX # :nodoc:
12
14
  extend self
13
15
 
14
16
  # Class that will build the hash while the XML document
15
17
  # is being parsed using SAX events.
16
18
  class HashBuilder < Nokogiri::XML::SAX::Document
17
- CONTENT_KEY = "__content__".freeze
18
- HASH_SIZE_KEY = "__hash_size__".freeze
19
+ CONTENT_KEY = "__content__"
20
+ HASH_SIZE_KEY = "__hash_size__"
19
21
 
20
22
  attr_reader :hash
21
23
 
@@ -37,7 +39,7 @@ module ActiveSupport
37
39
  end
38
40
 
39
41
  def start_element(name, attrs = [])
40
- new_hash = { CONTENT_KEY => "" }.merge!(Hash[attrs])
42
+ new_hash = { CONTENT_KEY => +"" }.merge!(Hash[attrs])
41
43
  new_hash[HASH_SIZE_KEY] = new_hash.size + 1
42
44
 
43
45
  case current_hash[name]
@@ -1,12 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/core_ext/kernel/reporting"
2
4
  require "active_support/core_ext/object/blank"
3
5
  require "stringio"
4
6
 
5
7
  module ActiveSupport
6
- module XmlMini_REXML #:nodoc:
8
+ module XmlMini_REXML # :nodoc:
7
9
  extend self
8
10
 
9
- CONTENT_KEY = "__content__".freeze
11
+ CONTENT_KEY = "__content__"
10
12
 
11
13
  # Parse an XML Document string or IO into a simple hash.
12
14
  #
@@ -23,7 +25,7 @@ module ActiveSupport
23
25
  if data.eof?
24
26
  {}
25
27
  else
26
- silence_warnings { require "rexml/document" } unless defined?(REXML::Document)
28
+ require_rexml unless defined?(REXML::Document)
27
29
  doc = REXML::Document.new(data)
28
30
 
29
31
  if doc.root
@@ -36,6 +38,13 @@ module ActiveSupport
36
38
  end
37
39
 
38
40
  private
41
+ def require_rexml
42
+ silence_warnings { require "rexml/document" }
43
+ rescue LoadError => e
44
+ $stderr.puts "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
+
39
48
  # Convert an XML element and merge into the hash
40
49
  #
41
50
  # hash::
@@ -74,7 +83,7 @@ module ActiveSupport
74
83
  hash
75
84
  else
76
85
  # must use value to prevent double-escaping
77
- texts = ""
86
+ texts = +""
78
87
  element.texts.each { |t| texts << t.value }
79
88
  merge!(hash, CONTENT_KEY, texts)
80
89
  end
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "time"
2
4
  require "base64"
3
5
  require "bigdecimal"
6
+ require "bigdecimal/util"
4
7
  require "active_support/core_ext/module/delegation"
5
8
  require "active_support/core_ext/string/inflections"
6
9
  require "active_support/core_ext/date_time/calculations"
@@ -16,7 +19,7 @@ module ActiveSupport
16
19
 
17
20
  # This module decorates files deserialized using Hash.from_xml with
18
21
  # the <tt>original_filename</tt> and <tt>content_type</tt> methods.
19
- module FileLike #:nodoc:
22
+ module FileLike # :nodoc:
20
23
  attr_writer :original_filename, :content_type
21
24
 
22
25
  def original_filename
@@ -46,15 +49,12 @@ module ActiveSupport
46
49
  "Array" => "array",
47
50
  "Hash" => "hash"
48
51
  }
49
-
50
- # No need to map these on Ruby 2.4+
51
- TYPE_NAMES["Fixnum"] = "integer" unless 0.class == Integer
52
- TYPE_NAMES["Bignum"] = "integer" unless 0.class == Integer
53
52
  end
53
+ TYPE_NAMES["ActiveSupport::TimeWithZone"] = TYPE_NAMES["Time"]
54
54
 
55
55
  FORMATTING = {
56
56
  "symbol" => Proc.new { |symbol| symbol.to_s },
57
- "date" => Proc.new { |date| date.to_s(:db) },
57
+ "date" => Proc.new { |date| date.to_fs(:db) },
58
58
  "dateTime" => Proc.new { |time| time.xmlschema },
59
59
  "binary" => Proc.new { |binary| ::Base64.encode64(binary) },
60
60
  "yaml" => Proc.new { |yaml| yaml.to_yaml }
@@ -70,18 +70,14 @@ module ActiveSupport
70
70
  "float" => Proc.new { |float| float.to_f },
71
71
  "decimal" => Proc.new do |number|
72
72
  if String === number
73
- begin
74
- BigDecimal(number)
75
- rescue ArgumentError
76
- BigDecimal("0")
77
- end
73
+ number.to_d
78
74
  else
79
75
  BigDecimal(number)
80
76
  end
81
77
  end,
82
78
  "boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.to_s.strip) },
83
79
  "string" => Proc.new { |string| string.to_s },
84
- "yaml" => Proc.new { |yaml| YAML::load(yaml) rescue yaml },
80
+ "yaml" => Proc.new { |yaml| YAML.load(yaml) rescue yaml },
85
81
  "base64Binary" => Proc.new { |bin| ::Base64.decode64(bin) },
86
82
  "binary" => Proc.new { |bin, entity| _parse_binary(bin, entity) },
87
83
  "file" => Proc.new { |file, entity| _parse_file(file, entity) }
@@ -160,7 +156,6 @@ module ActiveSupport
160
156
  end
161
157
 
162
158
  private
163
-
164
159
  def _dasherize(key)
165
160
  # $2 must be a non-greedy regex for this to work
166
161
  left, middle, right = /\A(_*)(.*?)(_*)\Z/.match(key.strip)[1, 3]
@@ -186,11 +181,11 @@ module ActiveSupport
186
181
  end
187
182
 
188
183
  def current_thread_backend
189
- Thread.current[:xml_mini_backend]
184
+ IsolatedExecutionState[:xml_mini_backend]
190
185
  end
191
186
 
192
187
  def current_thread_backend=(name)
193
- Thread.current[:xml_mini_backend] = name && cast_backend_name_to_module(name)
188
+ IsolatedExecutionState[:xml_mini_backend] = name && cast_backend_name_to_module(name)
194
189
  end
195
190
 
196
191
  def cast_backend_name_to_module(name)