activesupport 4.2.11.1 → 6.1.7.3

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 (272) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +464 -391
  3. data/MIT-LICENSE +2 -2
  4. data/README.rdoc +7 -7
  5. data/lib/active_support/actionable_error.rb +48 -0
  6. data/lib/active_support/all.rb +5 -3
  7. data/lib/active_support/array_inquirer.rb +50 -0
  8. data/lib/active_support/backtrace_cleaner.rb +34 -6
  9. data/lib/active_support/benchmarkable.rb +6 -4
  10. data/lib/active_support/builder.rb +3 -1
  11. data/lib/active_support/cache/file_store.rb +61 -55
  12. data/lib/active_support/cache/mem_cache_store.rb +115 -100
  13. data/lib/active_support/cache/memory_store.rb +81 -58
  14. data/lib/active_support/cache/null_store.rb +11 -7
  15. data/lib/active_support/cache/redis_cache_store.rb +493 -0
  16. data/lib/active_support/cache/strategy/local_cache.rb +90 -42
  17. data/lib/active_support/cache/strategy/local_cache_middleware.rb +10 -9
  18. data/lib/active_support/cache.rb +386 -225
  19. data/lib/active_support/callbacks.rb +661 -594
  20. data/lib/active_support/concern.rb +80 -7
  21. data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +35 -0
  22. data/lib/active_support/concurrency/share_lock.rb +226 -0
  23. data/lib/active_support/configurable.rb +16 -17
  24. data/lib/active_support/configuration_file.rb +51 -0
  25. data/lib/active_support/core_ext/array/access.rb +41 -1
  26. data/lib/active_support/core_ext/array/conversions.rb +24 -20
  27. data/lib/active_support/core_ext/array/extract.rb +21 -0
  28. data/lib/active_support/core_ext/array/extract_options.rb +2 -0
  29. data/lib/active_support/core_ext/array/grouping.rb +11 -18
  30. data/lib/active_support/core_ext/array/inquiry.rb +19 -0
  31. data/lib/active_support/core_ext/array/wrap.rb +7 -4
  32. data/lib/active_support/core_ext/array.rb +9 -6
  33. data/lib/active_support/core_ext/benchmark.rb +5 -3
  34. data/lib/active_support/core_ext/big_decimal/conversions.rb +10 -12
  35. data/lib/active_support/core_ext/big_decimal.rb +3 -1
  36. data/lib/active_support/core_ext/class/attribute.rb +52 -48
  37. data/lib/active_support/core_ext/class/attribute_accessors.rb +3 -1
  38. data/lib/active_support/core_ext/class/subclasses.rb +18 -25
  39. data/lib/active_support/core_ext/class.rb +4 -3
  40. data/lib/active_support/core_ext/date/acts_like.rb +3 -1
  41. data/lib/active_support/core_ext/date/blank.rb +14 -0
  42. data/lib/active_support/core_ext/date/calculations.rb +17 -14
  43. data/lib/active_support/core_ext/date/conversions.rb +27 -24
  44. data/lib/active_support/core_ext/date/zones.rb +4 -2
  45. data/lib/active_support/core_ext/date.rb +6 -4
  46. data/lib/active_support/core_ext/date_and_time/calculations.rb +167 -65
  47. data/lib/active_support/core_ext/date_and_time/compatibility.rb +19 -3
  48. data/lib/active_support/core_ext/date_and_time/zones.rb +12 -13
  49. data/lib/active_support/core_ext/date_time/acts_like.rb +4 -2
  50. data/lib/active_support/core_ext/date_time/blank.rb +14 -0
  51. data/lib/active_support/core_ext/date_time/calculations.rb +37 -19
  52. data/lib/active_support/core_ext/date_time/compatibility.rb +8 -6
  53. data/lib/active_support/core_ext/date_time/conversions.rb +16 -13
  54. data/lib/active_support/core_ext/date_time.rb +7 -5
  55. data/lib/active_support/core_ext/digest/uuid.rb +8 -5
  56. data/lib/active_support/core_ext/digest.rb +3 -0
  57. data/lib/active_support/core_ext/enumerable.rb +186 -22
  58. data/lib/active_support/core_ext/file/atomic.rb +38 -31
  59. data/lib/active_support/core_ext/file.rb +3 -1
  60. data/lib/active_support/core_ext/hash/conversions.rb +62 -41
  61. data/lib/active_support/core_ext/hash/deep_merge.rb +9 -13
  62. data/lib/active_support/core_ext/hash/deep_transform_values.rb +46 -0
  63. data/lib/active_support/core_ext/hash/except.rb +13 -10
  64. data/lib/active_support/core_ext/hash/indifferent_access.rb +4 -3
  65. data/lib/active_support/core_ext/hash/keys.rb +20 -43
  66. data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
  67. data/lib/active_support/core_ext/hash/slice.rb +8 -29
  68. data/lib/active_support/core_ext/hash.rb +10 -9
  69. data/lib/active_support/core_ext/integer/inflections.rb +3 -1
  70. data/lib/active_support/core_ext/integer/multiple.rb +3 -1
  71. data/lib/active_support/core_ext/integer/time.rb +11 -18
  72. data/lib/active_support/core_ext/integer.rb +5 -3
  73. data/lib/active_support/core_ext/kernel/concern.rb +5 -1
  74. data/lib/active_support/core_ext/kernel/reporting.rb +4 -84
  75. data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
  76. data/lib/active_support/core_ext/kernel.rb +5 -5
  77. data/lib/active_support/core_ext/load_error.rb +3 -22
  78. data/lib/active_support/core_ext/marshal.rb +10 -8
  79. data/lib/active_support/core_ext/module/aliasing.rb +6 -44
  80. data/lib/active_support/core_ext/module/anonymous.rb +12 -1
  81. data/lib/active_support/core_ext/module/attr_internal.rb +8 -9
  82. data/lib/active_support/core_ext/module/attribute_accessors.rb +63 -69
  83. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +148 -0
  84. data/lib/active_support/core_ext/module/concerning.rb +19 -14
  85. data/lib/active_support/core_ext/module/delegation.rb +164 -51
  86. data/lib/active_support/core_ext/module/deprecation.rb +4 -2
  87. data/lib/active_support/core_ext/module/introspection.rb +23 -22
  88. data/lib/active_support/core_ext/module/redefine_method.rb +40 -0
  89. data/lib/active_support/core_ext/module/remove_method.rb +8 -3
  90. data/lib/active_support/core_ext/module.rb +13 -11
  91. data/lib/active_support/core_ext/name_error.rb +51 -4
  92. data/lib/active_support/core_ext/numeric/bytes.rb +22 -0
  93. data/lib/active_support/core_ext/numeric/conversions.rb +133 -136
  94. data/lib/active_support/core_ext/numeric/time.rb +35 -23
  95. data/lib/active_support/core_ext/numeric.rb +5 -3
  96. data/lib/active_support/core_ext/object/acts_like.rb +12 -1
  97. data/lib/active_support/core_ext/object/blank.rb +27 -3
  98. data/lib/active_support/core_ext/object/conversions.rb +6 -4
  99. data/lib/active_support/core_ext/object/deep_dup.rb +13 -4
  100. data/lib/active_support/core_ext/object/duplicable.rb +13 -93
  101. data/lib/active_support/core_ext/object/inclusion.rb +5 -3
  102. data/lib/active_support/core_ext/object/instance_variables.rb +3 -1
  103. data/lib/active_support/core_ext/object/json.rb +63 -21
  104. data/lib/active_support/core_ext/object/to_param.rb +3 -1
  105. data/lib/active_support/core_ext/object/to_query.rb +10 -5
  106. data/lib/active_support/core_ext/object/try.rb +81 -23
  107. data/lib/active_support/core_ext/object/with_options.rb +16 -3
  108. data/lib/active_support/core_ext/object.rb +14 -13
  109. data/lib/active_support/core_ext/range/compare_range.rb +82 -0
  110. data/lib/active_support/core_ext/range/conversions.rb +37 -15
  111. data/lib/active_support/core_ext/range/each.rb +18 -17
  112. data/lib/active_support/core_ext/range/include_time_with_zone.rb +28 -0
  113. data/lib/active_support/core_ext/range/overlaps.rb +2 -0
  114. data/lib/active_support/core_ext/range.rb +7 -4
  115. data/lib/active_support/core_ext/regexp.rb +10 -1
  116. data/lib/active_support/core_ext/securerandom.rb +45 -0
  117. data/lib/active_support/core_ext/string/access.rb +9 -18
  118. data/lib/active_support/core_ext/string/behavior.rb +3 -1
  119. data/lib/active_support/core_ext/string/conversions.rb +8 -4
  120. data/lib/active_support/core_ext/string/exclude.rb +2 -0
  121. data/lib/active_support/core_ext/string/filters.rb +48 -6
  122. data/lib/active_support/core_ext/string/indent.rb +6 -4
  123. data/lib/active_support/core_ext/string/inflections.rb +102 -26
  124. data/lib/active_support/core_ext/string/inquiry.rb +4 -1
  125. data/lib/active_support/core_ext/string/multibyte.rb +18 -9
  126. data/lib/active_support/core_ext/string/output_safety.rb +125 -40
  127. data/lib/active_support/core_ext/string/starts_ends_with.rb +4 -2
  128. data/lib/active_support/core_ext/string/strip.rb +6 -5
  129. data/lib/active_support/core_ext/string/zones.rb +4 -2
  130. data/lib/active_support/core_ext/string.rb +15 -13
  131. data/lib/active_support/core_ext/symbol/starts_ends_with.rb +14 -0
  132. data/lib/active_support/core_ext/symbol.rb +3 -0
  133. data/lib/active_support/core_ext/time/acts_like.rb +3 -1
  134. data/lib/active_support/core_ext/time/calculations.rb +137 -53
  135. data/lib/active_support/core_ext/time/compatibility.rb +4 -2
  136. data/lib/active_support/core_ext/time/conversions.rb +22 -13
  137. data/lib/active_support/core_ext/time/zones.rb +41 -7
  138. data/lib/active_support/core_ext/time.rb +7 -6
  139. data/lib/active_support/core_ext/uri.rb +11 -8
  140. data/lib/active_support/core_ext.rb +3 -1
  141. data/lib/active_support/current_attributes/test_helper.rb +13 -0
  142. data/lib/active_support/current_attributes.rb +210 -0
  143. data/lib/active_support/dependencies/autoload.rb +2 -0
  144. data/lib/active_support/dependencies/interlock.rb +57 -0
  145. data/lib/active_support/dependencies/zeitwerk_integration.rb +120 -0
  146. data/lib/active_support/dependencies.rb +241 -175
  147. data/lib/active_support/deprecation/behaviors.rb +58 -12
  148. data/lib/active_support/deprecation/constant_accessor.rb +52 -0
  149. data/lib/active_support/deprecation/disallowed.rb +56 -0
  150. data/lib/active_support/deprecation/instance_delegator.rb +16 -2
  151. data/lib/active_support/deprecation/method_wrappers.rb +62 -21
  152. data/lib/active_support/deprecation/proxy_wrappers.rb +81 -30
  153. data/lib/active_support/deprecation/reporting.rb +81 -18
  154. data/lib/active_support/deprecation.rb +17 -9
  155. data/lib/active_support/descendants_tracker.rb +61 -9
  156. data/lib/active_support/digest.rb +22 -0
  157. data/lib/active_support/duration/iso8601_parser.rb +123 -0
  158. data/lib/active_support/duration/iso8601_serializer.rb +59 -0
  159. data/lib/active_support/duration.rb +364 -39
  160. data/lib/active_support/encrypted_configuration.rb +45 -0
  161. data/lib/active_support/encrypted_file.rb +117 -0
  162. data/lib/active_support/environment_inquirer.rb +20 -0
  163. data/lib/active_support/evented_file_update_checker.rb +170 -0
  164. data/lib/active_support/execution_wrapper.rb +132 -0
  165. data/lib/active_support/executor.rb +8 -0
  166. data/lib/active_support/file_update_checker.rb +62 -37
  167. data/lib/active_support/fork_tracker.rb +64 -0
  168. data/lib/active_support/gem_version.rb +7 -5
  169. data/lib/active_support/gzip.rb +7 -5
  170. data/lib/active_support/hash_with_indifferent_access.rb +171 -48
  171. data/lib/active_support/i18n.rb +9 -6
  172. data/lib/active_support/i18n_railtie.rb +47 -16
  173. data/lib/active_support/inflections.rb +13 -11
  174. data/lib/active_support/inflector/inflections.rb +58 -14
  175. data/lib/active_support/inflector/methods.rb +186 -169
  176. data/lib/active_support/inflector/transliterate.rb +83 -33
  177. data/lib/active_support/inflector.rb +7 -5
  178. data/lib/active_support/json/decoding.rb +32 -30
  179. data/lib/active_support/json/encoding.rb +22 -61
  180. data/lib/active_support/json.rb +4 -2
  181. data/lib/active_support/key_generator.rb +11 -43
  182. data/lib/active_support/lazy_load_hooks.rb +53 -20
  183. data/lib/active_support/locale/en.rb +33 -0
  184. data/lib/active_support/locale/en.yml +9 -3
  185. data/lib/active_support/log_subscriber/test_helper.rb +14 -12
  186. data/lib/active_support/log_subscriber.rb +52 -19
  187. data/lib/active_support/logger.rb +10 -24
  188. data/lib/active_support/logger_silence.rb +14 -20
  189. data/lib/active_support/logger_thread_safe_level.rb +56 -10
  190. data/lib/active_support/message_encryptor.rb +167 -57
  191. data/lib/active_support/message_verifier.rb +151 -18
  192. data/lib/active_support/messages/metadata.rb +80 -0
  193. data/lib/active_support/messages/rotation_configuration.rb +23 -0
  194. data/lib/active_support/messages/rotator.rb +57 -0
  195. data/lib/active_support/multibyte/chars.rb +35 -80
  196. data/lib/active_support/multibyte/unicode.rb +22 -330
  197. data/lib/active_support/multibyte.rb +4 -2
  198. data/lib/active_support/notifications/fanout.rb +125 -23
  199. data/lib/active_support/notifications/instrumenter.rb +98 -16
  200. data/lib/active_support/notifications.rb +82 -14
  201. data/lib/active_support/number_helper/number_converter.rb +17 -16
  202. data/lib/active_support/number_helper/number_to_currency_converter.rb +9 -14
  203. data/lib/active_support/number_helper/number_to_delimited_converter.rb +11 -4
  204. data/lib/active_support/number_helper/number_to_human_converter.rb +14 -11
  205. data/lib/active_support/number_helper/number_to_human_size_converter.rb +12 -10
  206. data/lib/active_support/number_helper/number_to_percentage_converter.rb +5 -1
  207. data/lib/active_support/number_helper/number_to_phone_converter.rb +15 -5
  208. data/lib/active_support/number_helper/number_to_rounded_converter.rb +29 -57
  209. data/lib/active_support/number_helper/rounding_helper.rb +50 -0
  210. data/lib/active_support/number_helper.rb +123 -71
  211. data/lib/active_support/option_merger.rb +25 -4
  212. data/lib/active_support/ordered_hash.rb +7 -5
  213. data/lib/active_support/ordered_options.rb +35 -7
  214. data/lib/active_support/parameter_filter.rb +133 -0
  215. data/lib/active_support/per_thread_registry.rb +10 -4
  216. data/lib/active_support/proxy_object.rb +2 -0
  217. data/lib/active_support/rails.rb +10 -11
  218. data/lib/active_support/railtie.rb +66 -10
  219. data/lib/active_support/reloader.rb +130 -0
  220. data/lib/active_support/rescuable.rb +112 -57
  221. data/lib/active_support/secure_compare_rotator.rb +51 -0
  222. data/lib/active_support/security_utils.rb +26 -15
  223. data/lib/active_support/string_inquirer.rb +13 -4
  224. data/lib/active_support/subscriber.rb +80 -31
  225. data/lib/active_support/tagged_logging.rb +54 -17
  226. data/lib/active_support/test_case.rb +107 -44
  227. data/lib/active_support/testing/assertions.rb +158 -20
  228. data/lib/active_support/testing/autorun.rb +4 -2
  229. data/lib/active_support/testing/constant_lookup.rb +2 -1
  230. data/lib/active_support/testing/declarative.rb +3 -1
  231. data/lib/active_support/testing/deprecation.rb +13 -10
  232. data/lib/active_support/testing/file_fixtures.rb +38 -0
  233. data/lib/active_support/testing/isolation.rb +35 -26
  234. data/lib/active_support/testing/method_call_assertions.rb +70 -0
  235. data/lib/active_support/testing/parallelization/server.rb +78 -0
  236. data/lib/active_support/testing/parallelization/worker.rb +100 -0
  237. data/lib/active_support/testing/parallelization.rb +51 -0
  238. data/lib/active_support/testing/setup_and_teardown.rb +13 -8
  239. data/lib/active_support/testing/stream.rb +43 -0
  240. data/lib/active_support/testing/tagged_logging.rb +3 -1
  241. data/lib/active_support/testing/time_helpers.rb +121 -20
  242. data/lib/active_support/time.rb +14 -12
  243. data/lib/active_support/time_with_zone.rb +215 -51
  244. data/lib/active_support/values/time_zone.rb +223 -71
  245. data/lib/active_support/version.rb +3 -1
  246. data/lib/active_support/xml_mini/jdom.rb +116 -115
  247. data/lib/active_support/xml_mini/libxml.rb +16 -13
  248. data/lib/active_support/xml_mini/libxmlsax.rb +15 -14
  249. data/lib/active_support/xml_mini/nokogiri.rb +14 -12
  250. data/lib/active_support/xml_mini/nokogirisax.rb +14 -13
  251. data/lib/active_support/xml_mini/rexml.rb +18 -9
  252. data/lib/active_support/xml_mini.rb +38 -46
  253. data/lib/active_support.rb +25 -11
  254. metadata +100 -43
  255. data/lib/active_support/concurrency/latch.rb +0 -27
  256. data/lib/active_support/core_ext/array/prepend_and_append.rb +0 -7
  257. data/lib/active_support/core_ext/big_decimal/yaml_conversions.rb +0 -16
  258. data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -45
  259. data/lib/active_support/core_ext/date_time/zones.rb +0 -6
  260. data/lib/active_support/core_ext/hash/compact.rb +0 -24
  261. data/lib/active_support/core_ext/hash/transform_values.rb +0 -23
  262. data/lib/active_support/core_ext/kernel/agnostics.rb +0 -11
  263. data/lib/active_support/core_ext/kernel/debugger.rb +0 -10
  264. data/lib/active_support/core_ext/module/method_transplanting.rb +0 -13
  265. data/lib/active_support/core_ext/module/qualified_const.rb +0 -52
  266. data/lib/active_support/core_ext/module/reachable.rb +0 -8
  267. data/lib/active_support/core_ext/object/itself.rb +0 -15
  268. data/lib/active_support/core_ext/range/include_range.rb +0 -23
  269. data/lib/active_support/core_ext/struct.rb +0 -6
  270. data/lib/active_support/core_ext/thread.rb +0 -86
  271. data/lib/active_support/core_ext/time/marshal.rb +0 -30
  272. data/lib/active_support/values/unicode_tables.dat +0 -0
@@ -1,8 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rbconfig"
4
+
1
5
  module ActiveSupport
2
6
  class Deprecation
3
7
  module Reporting
4
8
  # Whether to print a message (silent mode)
5
- attr_accessor :silenced
9
+ attr_writer :silenced
6
10
  # Name of gem where method is deprecated
7
11
  attr_accessor :gem_name
8
12
 
@@ -14,9 +18,13 @@ module ActiveSupport
14
18
  def warn(message = nil, callstack = nil)
15
19
  return if silenced
16
20
 
17
- callstack ||= caller(2)
21
+ callstack ||= caller_locations(2)
18
22
  deprecation_message(callstack, message).tap do |m|
19
- behavior.each { |b| b.call(m, callstack) }
23
+ if deprecation_disallowed?(message)
24
+ disallowed_behavior.each { |b| b.call(m, callstack, deprecation_horizon, gem_name) }
25
+ else
26
+ behavior.each { |b| b.call(m, callstack, deprecation_horizon, gem_name) }
27
+ end
20
28
  end
21
29
  end
22
30
 
@@ -29,15 +37,54 @@ module ActiveSupport
29
37
  # ActiveSupport::Deprecation.warn('something broke!')
30
38
  # end
31
39
  # # => nil
32
- def silence
33
- old_silenced, @silenced = @silenced, true
34
- yield
35
- ensure
36
- @silenced = old_silenced
40
+ def silence(&block)
41
+ @silenced_thread.bind(true, &block)
42
+ end
43
+
44
+ # Allow previously disallowed deprecation warnings within the block.
45
+ # <tt>allowed_warnings</tt> can be an array containing strings, symbols, or regular
46
+ # expressions. (Symbols are treated as strings). These are compared against
47
+ # the text of deprecation warning messages generated within the block.
48
+ # Matching warnings will be exempt from the rules set by
49
+ # +ActiveSupport::Deprecation.disallowed_warnings+
50
+ #
51
+ # The optional <tt>if:</tt> argument accepts a truthy/falsy value or an object that
52
+ # responds to <tt>.call</tt>. If truthy, then matching warnings will be allowed.
53
+ # If falsey then the method yields to the block without allowing the warning.
54
+ #
55
+ # ActiveSupport::Deprecation.disallowed_behavior = :raise
56
+ # ActiveSupport::Deprecation.disallowed_warnings = [
57
+ # "something broke"
58
+ # ]
59
+ #
60
+ # ActiveSupport::Deprecation.warn('something broke!')
61
+ # # => ActiveSupport::DeprecationException
62
+ #
63
+ # ActiveSupport::Deprecation.allow ['something broke'] do
64
+ # ActiveSupport::Deprecation.warn('something broke!')
65
+ # end
66
+ # # => nil
67
+ #
68
+ # ActiveSupport::Deprecation.allow ['something broke'], if: Rails.env.production? do
69
+ # ActiveSupport::Deprecation.warn('something broke!')
70
+ # end
71
+ # # => ActiveSupport::DeprecationException for dev/test, nil for production
72
+ def allow(allowed_warnings = :all, if: true, &block)
73
+ conditional = binding.local_variable_get(:if)
74
+ conditional = conditional.call if conditional.respond_to?(:call)
75
+ if conditional
76
+ @explicitly_allowed_warnings.bind(allowed_warnings, &block)
77
+ else
78
+ yield
79
+ end
80
+ end
81
+
82
+ def silenced
83
+ @silenced || @silenced_thread.value
37
84
  end
38
85
 
39
86
  def deprecation_warning(deprecated_method_name, message = nil, caller_backtrace = nil)
40
- caller_backtrace ||= caller(2)
87
+ caller_backtrace ||= caller_locations(2)
41
88
  deprecated_method_warning(deprecated_method_name, message).tap do |msg|
42
89
  warn(msg, caller_backtrace)
43
90
  end
@@ -46,24 +93,23 @@ module ActiveSupport
46
93
  private
47
94
  # Outputs a deprecation warning message
48
95
  #
49
- # ActiveSupport::Deprecation.deprecated_method_warning(:method_name)
96
+ # deprecated_method_warning(:method_name)
50
97
  # # => "method_name is deprecated and will be removed from Rails #{deprecation_horizon}"
51
- # ActiveSupport::Deprecation.deprecated_method_warning(:method_name, :another_method)
98
+ # deprecated_method_warning(:method_name, :another_method)
52
99
  # # => "method_name is deprecated and will be removed from Rails #{deprecation_horizon} (use another_method instead)"
53
- # ActiveSupport::Deprecation.deprecated_method_warning(:method_name, "Optional message")
100
+ # deprecated_method_warning(:method_name, "Optional message")
54
101
  # # => "method_name is deprecated and will be removed from Rails #{deprecation_horizon} (Optional message)"
55
102
  def deprecated_method_warning(method_name, message = nil)
56
103
  warning = "#{method_name} is deprecated and will be removed from #{gem_name} #{deprecation_horizon}"
57
104
  case message
58
- when Symbol then "#{warning} (use #{message} instead)"
59
- when String then "#{warning} (#{message})"
60
- else warning
105
+ when Symbol then "#{warning} (use #{message} instead)"
106
+ when String then "#{warning} (#{message})"
107
+ else warning
61
108
  end
62
109
  end
63
110
 
64
111
  def deprecation_message(callstack, message = nil)
65
112
  message ||= "You are using deprecated behavior which will be removed from the next major or minor release."
66
- message += '.' unless message =~ /\.$/
67
113
  "DEPRECATION WARNING: #{message} #{deprecation_caller_message(callstack)}"
68
114
  end
69
115
 
@@ -79,8 +125,19 @@ module ActiveSupport
79
125
  end
80
126
 
81
127
  def extract_callstack(callstack)
82
- rails_gem_root = File.expand_path("../../../../..", __FILE__) + "/"
83
- offending_line = callstack.find { |line| !line.start_with?(rails_gem_root) } || callstack.first
128
+ return _extract_callstack(callstack) if callstack.first.is_a? String
129
+
130
+ offending_line = callstack.find { |frame|
131
+ frame.absolute_path && !ignored_callstack(frame.absolute_path)
132
+ } || callstack.first
133
+
134
+ [offending_line.path, offending_line.lineno, offending_line.label]
135
+ end
136
+
137
+ def _extract_callstack(callstack)
138
+ warn "Please pass `caller_locations` to the deprecation API" if $VERBOSE
139
+ offending_line = callstack.find { |line| !ignored_callstack(line) } || callstack.first
140
+
84
141
  if offending_line
85
142
  if md = offending_line.match(/^(.+?):(\d+)(?::in `(.*?)')?/)
86
143
  md.captures
@@ -89,6 +146,12 @@ module ActiveSupport
89
146
  end
90
147
  end
91
148
  end
149
+
150
+ RAILS_GEM_ROOT = File.expand_path("../../../..", __dir__) + "/"
151
+
152
+ def ignored_callstack(path)
153
+ path.start_with?(RAILS_GEM_ROOT) || path.start_with?(RbConfig::CONFIG["rubylibdir"])
154
+ end
92
155
  end
93
156
  end
94
157
  end
@@ -1,4 +1,6 @@
1
- require 'singleton'
1
+ # frozen_string_literal: true
2
+
3
+ require "singleton"
2
4
 
3
5
  module ActiveSupport
4
6
  # \Deprecation specifies the API used by Rails to deprecate methods, instance
@@ -12,32 +14,38 @@ module ActiveSupport
12
14
  # a circular require warning for active_support/deprecation.rb.
13
15
  #
14
16
  # So, we define the constant first, and load dependencies later.
15
- require 'active_support/deprecation/instance_delegator'
16
- require 'active_support/deprecation/behaviors'
17
- require 'active_support/deprecation/reporting'
18
- require 'active_support/deprecation/method_wrappers'
19
- require 'active_support/deprecation/proxy_wrappers'
20
- require 'active_support/core_ext/module/deprecation'
17
+ require "active_support/deprecation/instance_delegator"
18
+ require "active_support/deprecation/behaviors"
19
+ require "active_support/deprecation/reporting"
20
+ require "active_support/deprecation/disallowed"
21
+ require "active_support/deprecation/constant_accessor"
22
+ require "active_support/deprecation/method_wrappers"
23
+ require "active_support/deprecation/proxy_wrappers"
24
+ require "active_support/core_ext/module/deprecation"
25
+ require "concurrent/atomic/thread_local_var"
21
26
 
22
27
  include Singleton
23
28
  include InstanceDelegator
24
29
  include Behavior
25
30
  include Reporting
31
+ include Disallowed
26
32
  include MethodWrapper
27
33
 
28
34
  # The version number in which the deprecated behavior will be removed, by default.
29
35
  attr_accessor :deprecation_horizon
30
36
 
31
37
  # It accepts two parameters on initialization. The first is a version of library
32
- # and the second is a library name
38
+ # and the second is a library name.
33
39
  #
34
40
  # ActiveSupport::Deprecation.new('2.0', 'MyLibrary')
35
- def initialize(deprecation_horizon = '5.0', gem_name = 'Rails')
41
+ def initialize(deprecation_horizon = "7.0", gem_name = "Rails")
36
42
  self.gem_name = gem_name
37
43
  self.deprecation_horizon = deprecation_horizon
38
44
  # By default, warnings are not silenced and debugging is off.
39
45
  self.silenced = false
40
46
  self.debug = false
47
+ @silenced_thread = Concurrent::ThreadLocalVar.new(false)
48
+ @explicitly_allowed_warnings = Concurrent::ThreadLocalVar.new(nil)
41
49
  end
42
50
  end
43
51
  end
@@ -1,3 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "weakref"
4
+
1
5
  module ActiveSupport
2
6
  # This module provides an internal implementation to track descendants
3
7
  # which is faster than iterating through ObjectSpace.
@@ -6,8 +10,10 @@ module ActiveSupport
6
10
 
7
11
  class << self
8
12
  def direct_descendants(klass)
9
- @@direct_descendants[klass] || []
13
+ descendants = @@direct_descendants[klass]
14
+ descendants ? descendants.to_a : []
10
15
  end
16
+ alias_method :subclasses, :direct_descendants
11
17
 
12
18
  def descendants(klass)
13
19
  arr = []
@@ -18,10 +24,10 @@ module ActiveSupport
18
24
  def clear
19
25
  if defined? ActiveSupport::Dependencies
20
26
  @@direct_descendants.each do |klass, descendants|
21
- if ActiveSupport::Dependencies.autoloaded?(klass)
27
+ if Dependencies.autoloaded?(klass)
22
28
  @@direct_descendants.delete(klass)
23
29
  else
24
- descendants.reject! { |v| ActiveSupport::Dependencies.autoloaded?(v) }
30
+ descendants.reject! { |v| Dependencies.autoloaded?(v) }
25
31
  end
26
32
  end
27
33
  else
@@ -32,16 +38,18 @@ module ActiveSupport
32
38
  # This is the only method that is not thread safe, but is only ever called
33
39
  # during the eager loading phase.
34
40
  def store_inherited(klass, descendant)
35
- (@@direct_descendants[klass] ||= []) << descendant
41
+ (@@direct_descendants[klass] ||= DescendantsArray.new) << descendant
36
42
  end
37
43
 
38
44
  private
39
- def accumulate_descendants(klass, acc)
40
- if direct_descendants = @@direct_descendants[klass]
41
- acc.concat(direct_descendants)
42
- direct_descendants.each { |direct_descendant| accumulate_descendants(direct_descendant, acc) }
45
+ def accumulate_descendants(klass, acc)
46
+ if direct_descendants = @@direct_descendants[klass]
47
+ direct_descendants.each do |direct_descendant|
48
+ acc << direct_descendant
49
+ accumulate_descendants(direct_descendant, acc)
50
+ end
51
+ end
43
52
  end
44
- end
45
53
  end
46
54
 
47
55
  def inherited(base)
@@ -52,9 +60,53 @@ module ActiveSupport
52
60
  def direct_descendants
53
61
  DescendantsTracker.direct_descendants(self)
54
62
  end
63
+ alias_method :subclasses, :direct_descendants
55
64
 
56
65
  def descendants
57
66
  DescendantsTracker.descendants(self)
58
67
  end
68
+
69
+ # DescendantsArray is an array that contains weak references to classes.
70
+ class DescendantsArray # :nodoc:
71
+ include Enumerable
72
+
73
+ def initialize
74
+ @refs = []
75
+ end
76
+
77
+ def initialize_copy(orig)
78
+ @refs = @refs.dup
79
+ end
80
+
81
+ def <<(klass)
82
+ @refs << WeakRef.new(klass)
83
+ end
84
+
85
+ def each
86
+ @refs.reject! do |ref|
87
+ yield ref.__getobj__
88
+ false
89
+ rescue WeakRef::RefError
90
+ true
91
+ end
92
+ self
93
+ end
94
+
95
+ def refs_size
96
+ @refs.size
97
+ end
98
+
99
+ def cleanup!
100
+ @refs.delete_if { |ref| !ref.weakref_alive? }
101
+ end
102
+
103
+ def reject!
104
+ @refs.reject! do |ref|
105
+ yield ref.__getobj__
106
+ rescue WeakRef::RefError
107
+ true
108
+ end
109
+ end
110
+ end
59
111
  end
60
112
  end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "digest"
4
+
5
+ module ActiveSupport
6
+ class Digest #:nodoc:
7
+ class <<self
8
+ def hash_digest_class
9
+ @hash_digest_class ||= ::Digest::MD5
10
+ end
11
+
12
+ def hash_digest_class=(klass)
13
+ raise ArgumentError, "#{klass} is expected to implement hexdigest class method" unless klass.respond_to?(:hexdigest)
14
+ @hash_digest_class = klass
15
+ end
16
+
17
+ def hexdigest(arg)
18
+ hash_digest_class.hexdigest(arg)[0...32]
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,123 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "strscan"
4
+
5
+ module ActiveSupport
6
+ class Duration
7
+ # Parses a string formatted according to ISO 8601 Duration into the hash.
8
+ #
9
+ # See {ISO 8601}[https://en.wikipedia.org/wiki/ISO_8601#Durations] for more information.
10
+ #
11
+ # This parser allows negative parts to be present in pattern.
12
+ class ISO8601Parser # :nodoc:
13
+ class ParsingError < ::ArgumentError; end
14
+
15
+ PERIOD_OR_COMMA = /\.|,/
16
+ PERIOD = "."
17
+ COMMA = ","
18
+
19
+ SIGN_MARKER = /\A\-|\+|/
20
+ DATE_MARKER = /P/
21
+ TIME_MARKER = /T/
22
+ DATE_COMPONENT = /(\-?\d+(?:[.,]\d+)?)(Y|M|D|W)/
23
+ TIME_COMPONENT = /(\-?\d+(?:[.,]\d+)?)(H|M|S)/
24
+
25
+ DATE_TO_PART = { "Y" => :years, "M" => :months, "W" => :weeks, "D" => :days }
26
+ TIME_TO_PART = { "H" => :hours, "M" => :minutes, "S" => :seconds }
27
+
28
+ DATE_COMPONENTS = [:years, :months, :days]
29
+ TIME_COMPONENTS = [:hours, :minutes, :seconds]
30
+
31
+ attr_reader :parts, :scanner
32
+ attr_accessor :mode, :sign
33
+
34
+ def initialize(string)
35
+ @scanner = StringScanner.new(string)
36
+ @parts = {}
37
+ @mode = :start
38
+ @sign = 1
39
+ end
40
+
41
+ def parse!
42
+ while !finished?
43
+ case mode
44
+ when :start
45
+ if scan(SIGN_MARKER)
46
+ self.sign = (scanner.matched == "-") ? -1 : 1
47
+ self.mode = :sign
48
+ else
49
+ raise_parsing_error
50
+ end
51
+
52
+ when :sign
53
+ if scan(DATE_MARKER)
54
+ self.mode = :date
55
+ else
56
+ raise_parsing_error
57
+ end
58
+
59
+ when :date
60
+ if scan(TIME_MARKER)
61
+ self.mode = :time
62
+ elsif scan(DATE_COMPONENT)
63
+ parts[DATE_TO_PART[scanner[2]]] = number * sign
64
+ else
65
+ raise_parsing_error
66
+ end
67
+
68
+ when :time
69
+ if scan(TIME_COMPONENT)
70
+ parts[TIME_TO_PART[scanner[2]]] = number * sign
71
+ else
72
+ raise_parsing_error
73
+ end
74
+
75
+ end
76
+ end
77
+
78
+ validate!
79
+ parts
80
+ end
81
+
82
+ private
83
+ def finished?
84
+ scanner.eos?
85
+ end
86
+
87
+ # Parses number which can be a float with either comma or period.
88
+ def number
89
+ PERIOD_OR_COMMA.match?(scanner[1]) ? scanner[1].tr(COMMA, PERIOD).to_f : scanner[1].to_i
90
+ end
91
+
92
+ def scan(pattern)
93
+ scanner.scan(pattern)
94
+ end
95
+
96
+ def raise_parsing_error(reason = nil)
97
+ raise ParsingError, "Invalid ISO 8601 duration: #{scanner.string.inspect} #{reason}".strip
98
+ end
99
+
100
+ # Checks for various semantic errors as stated in ISO 8601 standard.
101
+ def validate!
102
+ raise_parsing_error("is empty duration") if parts.empty?
103
+
104
+ # Mixing any of Y, M, D with W is invalid.
105
+ if parts.key?(:weeks) && (parts.keys & DATE_COMPONENTS).any?
106
+ raise_parsing_error("mixing weeks with other date parts not allowed")
107
+ end
108
+
109
+ # Specifying an empty T part is invalid.
110
+ if mode == :time && (parts.keys & TIME_COMPONENTS).empty?
111
+ raise_parsing_error("time part marker is present but time part is empty")
112
+ end
113
+
114
+ fractions = parts.values.reject(&:zero?).select { |a| (a % 1) != 0 }
115
+ unless fractions.empty? || (fractions.size == 1 && fractions.last == @parts.values.reject(&:zero?).last)
116
+ raise_parsing_error "(only last part can be fractional)"
117
+ end
118
+
119
+ true
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/object/blank"
4
+
5
+ module ActiveSupport
6
+ class Duration
7
+ # Serializes duration to string according to ISO 8601 Duration format.
8
+ class ISO8601Serializer # :nodoc:
9
+ DATE_COMPONENTS = %i(years months days)
10
+
11
+ def initialize(duration, precision: nil)
12
+ @duration = duration
13
+ @precision = precision
14
+ end
15
+
16
+ # Builds and returns output string.
17
+ def serialize
18
+ parts = normalize
19
+ return "PT0S" if parts.empty?
20
+
21
+ output = +"P"
22
+ output << "#{parts[:years]}Y" if parts.key?(:years)
23
+ output << "#{parts[:months]}M" if parts.key?(:months)
24
+ output << "#{parts[:days]}D" if parts.key?(:days)
25
+ output << "#{parts[:weeks]}W" if parts.key?(:weeks)
26
+ time = +""
27
+ time << "#{parts[:hours]}H" if parts.key?(:hours)
28
+ time << "#{parts[:minutes]}M" if parts.key?(:minutes)
29
+ if parts.key?(:seconds)
30
+ time << "#{sprintf(@precision ? "%0.0#{@precision}f" : '%g', parts[:seconds])}S"
31
+ end
32
+ output << "T#{time}" unless time.empty?
33
+ output
34
+ end
35
+
36
+ private
37
+ # Return pair of duration's parts and whole duration sign.
38
+ # Parts are summarized (as they can become repetitive due to addition, etc).
39
+ # Zero parts are removed as not significant.
40
+ # If all parts are negative it will negate all of them and return minus as a sign.
41
+ def normalize
42
+ parts = @duration.parts.each_with_object(Hash.new(0)) do |(k, v), p|
43
+ p[k] += v unless v.zero?
44
+ end
45
+
46
+ # Convert weeks to days and remove weeks if mixed with date parts
47
+ if week_mixed_with_date?(parts)
48
+ parts[:days] += parts.delete(:weeks) * SECONDS_PER_WEEK / SECONDS_PER_DAY
49
+ end
50
+
51
+ parts
52
+ end
53
+
54
+ def week_mixed_with_date?(parts)
55
+ parts.key?(:weeks) && (parts.keys & DATE_COMPONENTS).any?
56
+ end
57
+ end
58
+ end
59
+ end