activesupport 6.0.0

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 (250) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +572 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +40 -0
  5. data/lib/active_support.rb +96 -0
  6. data/lib/active_support/actionable_error.rb +48 -0
  7. data/lib/active_support/all.rb +5 -0
  8. data/lib/active_support/array_inquirer.rb +48 -0
  9. data/lib/active_support/backtrace_cleaner.rb +132 -0
  10. data/lib/active_support/benchmarkable.rb +51 -0
  11. data/lib/active_support/builder.rb +8 -0
  12. data/lib/active_support/cache.rb +830 -0
  13. data/lib/active_support/cache/file_store.rb +196 -0
  14. data/lib/active_support/cache/mem_cache_store.rb +212 -0
  15. data/lib/active_support/cache/memory_store.rb +174 -0
  16. data/lib/active_support/cache/null_store.rb +48 -0
  17. data/lib/active_support/cache/redis_cache_store.rb +488 -0
  18. data/lib/active_support/cache/strategy/local_cache.rb +194 -0
  19. data/lib/active_support/cache/strategy/local_cache_middleware.rb +45 -0
  20. data/lib/active_support/callbacks.rb +856 -0
  21. data/lib/active_support/concern.rb +171 -0
  22. data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +17 -0
  23. data/lib/active_support/concurrency/share_lock.rb +227 -0
  24. data/lib/active_support/configurable.rb +146 -0
  25. data/lib/active_support/core_ext.rb +5 -0
  26. data/lib/active_support/core_ext/array.rb +9 -0
  27. data/lib/active_support/core_ext/array/access.rb +104 -0
  28. data/lib/active_support/core_ext/array/conversions.rb +213 -0
  29. data/lib/active_support/core_ext/array/extract.rb +21 -0
  30. data/lib/active_support/core_ext/array/extract_options.rb +31 -0
  31. data/lib/active_support/core_ext/array/grouping.rb +109 -0
  32. data/lib/active_support/core_ext/array/inquiry.rb +19 -0
  33. data/lib/active_support/core_ext/array/prepend_and_append.rb +5 -0
  34. data/lib/active_support/core_ext/array/wrap.rb +48 -0
  35. data/lib/active_support/core_ext/benchmark.rb +16 -0
  36. data/lib/active_support/core_ext/big_decimal.rb +3 -0
  37. data/lib/active_support/core_ext/big_decimal/conversions.rb +14 -0
  38. data/lib/active_support/core_ext/class.rb +4 -0
  39. data/lib/active_support/core_ext/class/attribute.rb +141 -0
  40. data/lib/active_support/core_ext/class/attribute_accessors.rb +6 -0
  41. data/lib/active_support/core_ext/class/subclasses.rb +54 -0
  42. data/lib/active_support/core_ext/date.rb +7 -0
  43. data/lib/active_support/core_ext/date/acts_like.rb +10 -0
  44. data/lib/active_support/core_ext/date/blank.rb +14 -0
  45. data/lib/active_support/core_ext/date/calculations.rb +146 -0
  46. data/lib/active_support/core_ext/date/conversions.rb +96 -0
  47. data/lib/active_support/core_ext/date/zones.rb +8 -0
  48. data/lib/active_support/core_ext/date_and_time/calculations.rb +351 -0
  49. data/lib/active_support/core_ext/date_and_time/compatibility.rb +16 -0
  50. data/lib/active_support/core_ext/date_and_time/zones.rb +41 -0
  51. data/lib/active_support/core_ext/date_time.rb +7 -0
  52. data/lib/active_support/core_ext/date_time/acts_like.rb +16 -0
  53. data/lib/active_support/core_ext/date_time/blank.rb +14 -0
  54. data/lib/active_support/core_ext/date_time/calculations.rb +211 -0
  55. data/lib/active_support/core_ext/date_time/compatibility.rb +18 -0
  56. data/lib/active_support/core_ext/date_time/conversions.rb +107 -0
  57. data/lib/active_support/core_ext/digest.rb +3 -0
  58. data/lib/active_support/core_ext/digest/uuid.rb +53 -0
  59. data/lib/active_support/core_ext/enumerable.rb +188 -0
  60. data/lib/active_support/core_ext/file.rb +3 -0
  61. data/lib/active_support/core_ext/file/atomic.rb +70 -0
  62. data/lib/active_support/core_ext/hash.rb +10 -0
  63. data/lib/active_support/core_ext/hash/compact.rb +5 -0
  64. data/lib/active_support/core_ext/hash/conversions.rb +263 -0
  65. data/lib/active_support/core_ext/hash/deep_merge.rb +34 -0
  66. data/lib/active_support/core_ext/hash/deep_transform_values.rb +46 -0
  67. data/lib/active_support/core_ext/hash/except.rb +24 -0
  68. data/lib/active_support/core_ext/hash/indifferent_access.rb +24 -0
  69. data/lib/active_support/core_ext/hash/keys.rb +143 -0
  70. data/lib/active_support/core_ext/hash/reverse_merge.rb +25 -0
  71. data/lib/active_support/core_ext/hash/slice.rb +26 -0
  72. data/lib/active_support/core_ext/hash/transform_values.rb +5 -0
  73. data/lib/active_support/core_ext/integer.rb +5 -0
  74. data/lib/active_support/core_ext/integer/inflections.rb +31 -0
  75. data/lib/active_support/core_ext/integer/multiple.rb +12 -0
  76. data/lib/active_support/core_ext/integer/time.rb +22 -0
  77. data/lib/active_support/core_ext/kernel.rb +5 -0
  78. data/lib/active_support/core_ext/kernel/concern.rb +14 -0
  79. data/lib/active_support/core_ext/kernel/reporting.rb +45 -0
  80. data/lib/active_support/core_ext/kernel/singleton_class.rb +8 -0
  81. data/lib/active_support/core_ext/load_error.rb +9 -0
  82. data/lib/active_support/core_ext/marshal.rb +24 -0
  83. data/lib/active_support/core_ext/module.rb +13 -0
  84. data/lib/active_support/core_ext/module/aliasing.rb +31 -0
  85. data/lib/active_support/core_ext/module/anonymous.rb +30 -0
  86. data/lib/active_support/core_ext/module/attr_internal.rb +38 -0
  87. data/lib/active_support/core_ext/module/attribute_accessors.rb +212 -0
  88. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +144 -0
  89. data/lib/active_support/core_ext/module/concerning.rb +134 -0
  90. data/lib/active_support/core_ext/module/delegation.rb +313 -0
  91. data/lib/active_support/core_ext/module/deprecation.rb +25 -0
  92. data/lib/active_support/core_ext/module/introspection.rb +86 -0
  93. data/lib/active_support/core_ext/module/reachable.rb +6 -0
  94. data/lib/active_support/core_ext/module/redefine_method.rb +40 -0
  95. data/lib/active_support/core_ext/module/remove_method.rb +17 -0
  96. data/lib/active_support/core_ext/name_error.rb +38 -0
  97. data/lib/active_support/core_ext/numeric.rb +5 -0
  98. data/lib/active_support/core_ext/numeric/bytes.rb +66 -0
  99. data/lib/active_support/core_ext/numeric/conversions.rb +136 -0
  100. data/lib/active_support/core_ext/numeric/inquiry.rb +5 -0
  101. data/lib/active_support/core_ext/numeric/time.rb +66 -0
  102. data/lib/active_support/core_ext/object.rb +16 -0
  103. data/lib/active_support/core_ext/object/acts_like.rb +21 -0
  104. data/lib/active_support/core_ext/object/blank.rb +155 -0
  105. data/lib/active_support/core_ext/object/conversions.rb +6 -0
  106. data/lib/active_support/core_ext/object/deep_dup.rb +55 -0
  107. data/lib/active_support/core_ext/object/duplicable.rb +49 -0
  108. data/lib/active_support/core_ext/object/inclusion.rb +29 -0
  109. data/lib/active_support/core_ext/object/instance_variables.rb +30 -0
  110. data/lib/active_support/core_ext/object/json.rb +228 -0
  111. data/lib/active_support/core_ext/object/to_param.rb +3 -0
  112. data/lib/active_support/core_ext/object/to_query.rb +89 -0
  113. data/lib/active_support/core_ext/object/try.rb +156 -0
  114. data/lib/active_support/core_ext/object/with_options.rb +82 -0
  115. data/lib/active_support/core_ext/range.rb +7 -0
  116. data/lib/active_support/core_ext/range/compare_range.rb +70 -0
  117. data/lib/active_support/core_ext/range/conversions.rb +41 -0
  118. data/lib/active_support/core_ext/range/each.rb +25 -0
  119. data/lib/active_support/core_ext/range/include_range.rb +9 -0
  120. data/lib/active_support/core_ext/range/include_time_with_zone.rb +23 -0
  121. data/lib/active_support/core_ext/range/overlaps.rb +10 -0
  122. data/lib/active_support/core_ext/regexp.rb +7 -0
  123. data/lib/active_support/core_ext/securerandom.rb +45 -0
  124. data/lib/active_support/core_ext/string.rb +15 -0
  125. data/lib/active_support/core_ext/string/access.rb +114 -0
  126. data/lib/active_support/core_ext/string/behavior.rb +8 -0
  127. data/lib/active_support/core_ext/string/conversions.rb +59 -0
  128. data/lib/active_support/core_ext/string/exclude.rb +13 -0
  129. data/lib/active_support/core_ext/string/filters.rb +145 -0
  130. data/lib/active_support/core_ext/string/indent.rb +45 -0
  131. data/lib/active_support/core_ext/string/inflections.rb +259 -0
  132. data/lib/active_support/core_ext/string/inquiry.rb +15 -0
  133. data/lib/active_support/core_ext/string/multibyte.rb +58 -0
  134. data/lib/active_support/core_ext/string/output_safety.rb +314 -0
  135. data/lib/active_support/core_ext/string/starts_ends_with.rb +6 -0
  136. data/lib/active_support/core_ext/string/strip.rb +27 -0
  137. data/lib/active_support/core_ext/string/zones.rb +16 -0
  138. data/lib/active_support/core_ext/time.rb +7 -0
  139. data/lib/active_support/core_ext/time/acts_like.rb +10 -0
  140. data/lib/active_support/core_ext/time/calculations.rb +344 -0
  141. data/lib/active_support/core_ext/time/compatibility.rb +16 -0
  142. data/lib/active_support/core_ext/time/conversions.rb +72 -0
  143. data/lib/active_support/core_ext/time/zones.rb +113 -0
  144. data/lib/active_support/core_ext/uri.rb +25 -0
  145. data/lib/active_support/current_attributes.rb +203 -0
  146. data/lib/active_support/dependencies.rb +806 -0
  147. data/lib/active_support/dependencies/autoload.rb +79 -0
  148. data/lib/active_support/dependencies/interlock.rb +57 -0
  149. data/lib/active_support/dependencies/zeitwerk_integration.rb +110 -0
  150. data/lib/active_support/deprecation.rb +46 -0
  151. data/lib/active_support/deprecation/behaviors.rb +109 -0
  152. data/lib/active_support/deprecation/constant_accessor.rb +52 -0
  153. data/lib/active_support/deprecation/instance_delegator.rb +39 -0
  154. data/lib/active_support/deprecation/method_wrappers.rb +78 -0
  155. data/lib/active_support/deprecation/proxy_wrappers.rb +173 -0
  156. data/lib/active_support/deprecation/reporting.rb +114 -0
  157. data/lib/active_support/descendants_tracker.rb +109 -0
  158. data/lib/active_support/digest.rb +20 -0
  159. data/lib/active_support/duration.rb +433 -0
  160. data/lib/active_support/duration/iso8601_parser.rb +124 -0
  161. data/lib/active_support/duration/iso8601_serializer.rb +54 -0
  162. data/lib/active_support/encrypted_configuration.rb +45 -0
  163. data/lib/active_support/encrypted_file.rb +100 -0
  164. data/lib/active_support/evented_file_update_checker.rb +235 -0
  165. data/lib/active_support/execution_wrapper.rb +129 -0
  166. data/lib/active_support/executor.rb +8 -0
  167. data/lib/active_support/file_update_checker.rb +163 -0
  168. data/lib/active_support/gem_version.rb +17 -0
  169. data/lib/active_support/gzip.rb +38 -0
  170. data/lib/active_support/hash_with_indifferent_access.rb +399 -0
  171. data/lib/active_support/i18n.rb +16 -0
  172. data/lib/active_support/i18n_railtie.rb +126 -0
  173. data/lib/active_support/inflections.rb +72 -0
  174. data/lib/active_support/inflector.rb +9 -0
  175. data/lib/active_support/inflector/inflections.rb +257 -0
  176. data/lib/active_support/inflector/methods.rb +398 -0
  177. data/lib/active_support/inflector/transliterate.rb +147 -0
  178. data/lib/active_support/json.rb +4 -0
  179. data/lib/active_support/json/decoding.rb +76 -0
  180. data/lib/active_support/json/encoding.rb +134 -0
  181. data/lib/active_support/key_generator.rb +41 -0
  182. data/lib/active_support/lazy_load_hooks.rb +82 -0
  183. data/lib/active_support/locale/en.rb +31 -0
  184. data/lib/active_support/locale/en.yml +135 -0
  185. data/lib/active_support/log_subscriber.rb +135 -0
  186. data/lib/active_support/log_subscriber/test_helper.rb +106 -0
  187. data/lib/active_support/logger.rb +93 -0
  188. data/lib/active_support/logger_silence.rb +45 -0
  189. data/lib/active_support/logger_thread_safe_level.rb +56 -0
  190. data/lib/active_support/message_encryptor.rb +227 -0
  191. data/lib/active_support/message_verifier.rb +205 -0
  192. data/lib/active_support/messages/metadata.rb +71 -0
  193. data/lib/active_support/messages/rotation_configuration.rb +22 -0
  194. data/lib/active_support/messages/rotator.rb +56 -0
  195. data/lib/active_support/multibyte.rb +23 -0
  196. data/lib/active_support/multibyte/chars.rb +216 -0
  197. data/lib/active_support/multibyte/unicode.rb +157 -0
  198. data/lib/active_support/notifications.rb +253 -0
  199. data/lib/active_support/notifications/fanout.rb +244 -0
  200. data/lib/active_support/notifications/instrumenter.rb +164 -0
  201. data/lib/active_support/number_helper.rb +378 -0
  202. data/lib/active_support/number_helper/number_converter.rb +184 -0
  203. data/lib/active_support/number_helper/number_to_currency_converter.rb +46 -0
  204. data/lib/active_support/number_helper/number_to_delimited_converter.rb +31 -0
  205. data/lib/active_support/number_helper/number_to_human_converter.rb +70 -0
  206. data/lib/active_support/number_helper/number_to_human_size_converter.rb +61 -0
  207. data/lib/active_support/number_helper/number_to_percentage_converter.rb +16 -0
  208. data/lib/active_support/number_helper/number_to_phone_converter.rb +60 -0
  209. data/lib/active_support/number_helper/number_to_rounded_converter.rb +56 -0
  210. data/lib/active_support/number_helper/rounding_helper.rb +66 -0
  211. data/lib/active_support/option_merger.rb +27 -0
  212. data/lib/active_support/ordered_hash.rb +50 -0
  213. data/lib/active_support/ordered_options.rb +85 -0
  214. data/lib/active_support/parameter_filter.rb +129 -0
  215. data/lib/active_support/per_thread_registry.rb +60 -0
  216. data/lib/active_support/proxy_object.rb +15 -0
  217. data/lib/active_support/rails.rb +29 -0
  218. data/lib/active_support/railtie.rb +80 -0
  219. data/lib/active_support/reloader.rb +130 -0
  220. data/lib/active_support/rescuable.rb +174 -0
  221. data/lib/active_support/security_utils.rb +31 -0
  222. data/lib/active_support/string_inquirer.rb +34 -0
  223. data/lib/active_support/subscriber.rb +169 -0
  224. data/lib/active_support/tagged_logging.rb +88 -0
  225. data/lib/active_support/test_case.rb +163 -0
  226. data/lib/active_support/testing/assertions.rb +228 -0
  227. data/lib/active_support/testing/autorun.rb +7 -0
  228. data/lib/active_support/testing/constant_lookup.rb +51 -0
  229. data/lib/active_support/testing/declarative.rb +28 -0
  230. data/lib/active_support/testing/deprecation.rb +38 -0
  231. data/lib/active_support/testing/file_fixtures.rb +38 -0
  232. data/lib/active_support/testing/isolation.rb +110 -0
  233. data/lib/active_support/testing/method_call_assertions.rb +70 -0
  234. data/lib/active_support/testing/parallelization.rb +128 -0
  235. data/lib/active_support/testing/setup_and_teardown.rb +55 -0
  236. data/lib/active_support/testing/stream.rb +44 -0
  237. data/lib/active_support/testing/tagged_logging.rb +27 -0
  238. data/lib/active_support/testing/time_helpers.rb +200 -0
  239. data/lib/active_support/time.rb +20 -0
  240. data/lib/active_support/time_with_zone.rb +561 -0
  241. data/lib/active_support/values/time_zone.rb +570 -0
  242. data/lib/active_support/version.rb +10 -0
  243. data/lib/active_support/xml_mini.rb +202 -0
  244. data/lib/active_support/xml_mini/jdom.rb +183 -0
  245. data/lib/active_support/xml_mini/libxml.rb +80 -0
  246. data/lib/active_support/xml_mini/libxmlsax.rb +83 -0
  247. data/lib/active_support/xml_mini/nokogiri.rb +83 -0
  248. data/lib/active_support/xml_mini/nokogirisax.rb +86 -0
  249. data/lib/active_support/xml_mini/rexml.rb +130 -0
  250. metadata +385 -0
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/inflector/methods"
4
+
5
+ module ActiveSupport
6
+ # Autoload and eager load conveniences for your library.
7
+ #
8
+ # This module allows you to define autoloads based on
9
+ # Rails conventions (i.e. no need to define the path
10
+ # it is automatically guessed based on the filename)
11
+ # and also define a set of constants that needs to be
12
+ # eager loaded:
13
+ #
14
+ # module MyLib
15
+ # extend ActiveSupport::Autoload
16
+ #
17
+ # autoload :Model
18
+ #
19
+ # eager_autoload do
20
+ # autoload :Cache
21
+ # end
22
+ # end
23
+ #
24
+ # Then your library can be eager loaded by simply calling:
25
+ #
26
+ # MyLib.eager_load!
27
+ module Autoload
28
+ def self.extended(base) # :nodoc:
29
+ base.class_eval do
30
+ @_autoloads = {}
31
+ @_under_path = nil
32
+ @_at_path = nil
33
+ @_eager_autoload = false
34
+ end
35
+ end
36
+
37
+ def autoload(const_name, path = @_at_path)
38
+ unless path
39
+ full = [name, @_under_path, const_name.to_s].compact.join("::")
40
+ path = Inflector.underscore(full)
41
+ end
42
+
43
+ if @_eager_autoload
44
+ @_autoloads[const_name] = path
45
+ end
46
+
47
+ super const_name, path
48
+ end
49
+
50
+ def autoload_under(path)
51
+ @_under_path, old_path = path, @_under_path
52
+ yield
53
+ ensure
54
+ @_under_path = old_path
55
+ end
56
+
57
+ def autoload_at(path)
58
+ @_at_path, old_path = path, @_at_path
59
+ yield
60
+ ensure
61
+ @_at_path = old_path
62
+ end
63
+
64
+ def eager_autoload
65
+ old_eager, @_eager_autoload = @_eager_autoload, true
66
+ yield
67
+ ensure
68
+ @_eager_autoload = old_eager
69
+ end
70
+
71
+ def eager_load!
72
+ @_autoloads.each_value { |file| require file }
73
+ end
74
+
75
+ def autoloads
76
+ @_autoloads
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concurrency/share_lock"
4
+
5
+ module ActiveSupport #:nodoc:
6
+ module Dependencies #:nodoc:
7
+ class Interlock
8
+ def initialize # :nodoc:
9
+ @lock = ActiveSupport::Concurrency::ShareLock.new
10
+ end
11
+
12
+ def loading
13
+ @lock.exclusive(purpose: :load, compatible: [:load], after_compatible: [:load]) do
14
+ yield
15
+ end
16
+ end
17
+
18
+ def unloading
19
+ @lock.exclusive(purpose: :unload, compatible: [:load, :unload], after_compatible: [:load, :unload]) do
20
+ yield
21
+ end
22
+ end
23
+
24
+ def start_unloading
25
+ @lock.start_exclusive(purpose: :unload, compatible: [:load, :unload])
26
+ end
27
+
28
+ def done_unloading
29
+ @lock.stop_exclusive(compatible: [:load, :unload])
30
+ end
31
+
32
+ def start_running
33
+ @lock.start_sharing
34
+ end
35
+
36
+ def done_running
37
+ @lock.stop_sharing
38
+ end
39
+
40
+ def running
41
+ @lock.sharing do
42
+ yield
43
+ end
44
+ end
45
+
46
+ def permit_concurrent_loads
47
+ @lock.yield_shares(compatible: [:load]) do
48
+ yield
49
+ end
50
+ end
51
+
52
+ def raw_state(&block) # :nodoc:
53
+ @lock.raw_state(&block)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "set"
4
+ require "active_support/core_ext/string/inflections"
5
+
6
+ module ActiveSupport
7
+ module Dependencies
8
+ module ZeitwerkIntegration # :nodoc: all
9
+ module Decorations
10
+ def clear
11
+ Dependencies.unload_interlock do
12
+ Rails.autoloaders.main.reload
13
+ rescue Zeitwerk::ReloadingDisabledError
14
+ raise "reloading is disabled because config.cache_classes is true"
15
+ end
16
+ end
17
+
18
+ def constantize(cpath)
19
+ ActiveSupport::Inflector.constantize(cpath)
20
+ end
21
+
22
+ def safe_constantize(cpath)
23
+ ActiveSupport::Inflector.safe_constantize(cpath)
24
+ end
25
+
26
+ def autoloaded_constants
27
+ Rails.autoloaders.main.unloadable_cpaths
28
+ end
29
+
30
+ def autoloaded?(object)
31
+ cpath = object.is_a?(Module) ? real_mod_name(object) : object.to_s
32
+ Rails.autoloaders.main.unloadable_cpath?(cpath)
33
+ end
34
+
35
+ def verbose=(verbose)
36
+ l = verbose ? logger || Rails.logger : nil
37
+ Rails.autoloaders.each { |autoloader| autoloader.logger = l }
38
+ end
39
+
40
+ def unhook!
41
+ :no_op
42
+ end
43
+ end
44
+
45
+ module RequireDependency
46
+ def require_dependency(filename)
47
+ filename = filename.to_path if filename.respond_to?(:to_path)
48
+ if abspath = ActiveSupport::Dependencies.search_for_file(filename)
49
+ require abspath
50
+ else
51
+ require filename
52
+ end
53
+ end
54
+ end
55
+
56
+ module Inflector
57
+ def self.camelize(basename, _abspath)
58
+ basename.camelize
59
+ end
60
+ end
61
+
62
+ class << self
63
+ def take_over(enable_reloading:)
64
+ setup_autoloaders(enable_reloading)
65
+ freeze_paths
66
+ decorate_dependencies
67
+ end
68
+
69
+ private
70
+
71
+ def setup_autoloaders(enable_reloading)
72
+ Dependencies.autoload_paths.each do |autoload_path|
73
+ # Zeitwerk only accepts existing directories in `push_dir` to
74
+ # prevent misconfigurations.
75
+ next unless File.directory?(autoload_path)
76
+
77
+ autoloader = \
78
+ autoload_once?(autoload_path) ? Rails.autoloaders.once : Rails.autoloaders.main
79
+
80
+ autoloader.push_dir(autoload_path)
81
+ autoloader.do_not_eager_load(autoload_path) unless eager_load?(autoload_path)
82
+ end
83
+
84
+ Rails.autoloaders.main.enable_reloading if enable_reloading
85
+ Rails.autoloaders.each(&:setup)
86
+ end
87
+
88
+ def autoload_once?(autoload_path)
89
+ Dependencies.autoload_once_paths.include?(autoload_path)
90
+ end
91
+
92
+ def eager_load?(autoload_path)
93
+ Dependencies._eager_load_paths.member?(autoload_path)
94
+ end
95
+
96
+ def freeze_paths
97
+ Dependencies.autoload_paths.freeze
98
+ Dependencies.autoload_once_paths.freeze
99
+ Dependencies._eager_load_paths.freeze
100
+ end
101
+
102
+ def decorate_dependencies
103
+ Dependencies.unhook!
104
+ Dependencies.singleton_class.prepend(Decorations)
105
+ Object.prepend(RequireDependency)
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "singleton"
4
+
5
+ module ActiveSupport
6
+ # \Deprecation specifies the API used by Rails to deprecate methods, instance
7
+ # variables, objects and constants.
8
+ class Deprecation
9
+ # active_support.rb sets an autoload for ActiveSupport::Deprecation.
10
+ #
11
+ # If these requires were at the top of the file the constant would not be
12
+ # defined by the time their files were loaded. Since some of them reopen
13
+ # ActiveSupport::Deprecation its autoload would be triggered, resulting in
14
+ # a circular require warning for active_support/deprecation.rb.
15
+ #
16
+ # So, we define the constant first, and load dependencies later.
17
+ require "active_support/deprecation/instance_delegator"
18
+ require "active_support/deprecation/behaviors"
19
+ require "active_support/deprecation/reporting"
20
+ require "active_support/deprecation/constant_accessor"
21
+ require "active_support/deprecation/method_wrappers"
22
+ require "active_support/deprecation/proxy_wrappers"
23
+ require "active_support/core_ext/module/deprecation"
24
+
25
+ include Singleton
26
+ include InstanceDelegator
27
+ include Behavior
28
+ include Reporting
29
+ include MethodWrapper
30
+
31
+ # The version number in which the deprecated behavior will be removed, by default.
32
+ attr_accessor :deprecation_horizon
33
+
34
+ # It accepts two parameters on initialization. The first is a version of library
35
+ # and the second is a library name.
36
+ #
37
+ # ActiveSupport::Deprecation.new('2.0', 'MyLibrary')
38
+ def initialize(deprecation_horizon = "6.1", gem_name = "Rails")
39
+ self.gem_name = gem_name
40
+ self.deprecation_horizon = deprecation_horizon
41
+ # By default, warnings are not silenced and debugging is off.
42
+ self.silenced = false
43
+ self.debug = false
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/notifications"
4
+
5
+ module ActiveSupport
6
+ # Raised when <tt>ActiveSupport::Deprecation::Behavior#behavior</tt> is set with <tt>:raise</tt>.
7
+ # You would set <tt>:raise</tt>, as a behavior to raise errors and proactively report exceptions from deprecations.
8
+ class DeprecationException < StandardError
9
+ end
10
+
11
+ class Deprecation
12
+ # Default warning behaviors per Rails.env.
13
+ DEFAULT_BEHAVIORS = {
14
+ raise: ->(message, callstack, deprecation_horizon, gem_name) {
15
+ e = DeprecationException.new(message)
16
+ e.set_backtrace(callstack.map(&:to_s))
17
+ raise e
18
+ },
19
+
20
+ stderr: ->(message, callstack, deprecation_horizon, gem_name) {
21
+ $stderr.puts(message)
22
+ $stderr.puts callstack.join("\n ") if debug
23
+ },
24
+
25
+ log: ->(message, callstack, deprecation_horizon, gem_name) {
26
+ logger =
27
+ if defined?(Rails.logger) && Rails.logger
28
+ Rails.logger
29
+ else
30
+ require "active_support/logger"
31
+ ActiveSupport::Logger.new($stderr)
32
+ end
33
+ logger.warn message
34
+ logger.debug callstack.join("\n ") if debug
35
+ },
36
+
37
+ notify: ->(message, callstack, deprecation_horizon, gem_name) {
38
+ notification_name = "deprecation.#{gem_name.underscore.tr('/', '_')}"
39
+ ActiveSupport::Notifications.instrument(notification_name,
40
+ message: message,
41
+ callstack: callstack,
42
+ gem_name: gem_name,
43
+ deprecation_horizon: deprecation_horizon)
44
+ },
45
+
46
+ silence: ->(message, callstack, deprecation_horizon, gem_name) { },
47
+ }
48
+
49
+ # Behavior module allows to determine how to display deprecation messages.
50
+ # You can create a custom behavior or set any from the +DEFAULT_BEHAVIORS+
51
+ # constant. Available behaviors are:
52
+ #
53
+ # [+raise+] Raise <tt>ActiveSupport::DeprecationException</tt>.
54
+ # [+stderr+] Log all deprecation warnings to +$stderr+.
55
+ # [+log+] Log all deprecation warnings to +Rails.logger+.
56
+ # [+notify+] Use +ActiveSupport::Notifications+ to notify +deprecation.rails+.
57
+ # [+silence+] Do nothing.
58
+ #
59
+ # Setting behaviors only affects deprecations that happen after boot time.
60
+ # For more information you can read the documentation of the +behavior=+ method.
61
+ module Behavior
62
+ # Whether to print a backtrace along with the warning.
63
+ attr_accessor :debug
64
+
65
+ # Returns the current behavior or if one isn't set, defaults to +:stderr+.
66
+ def behavior
67
+ @behavior ||= [DEFAULT_BEHAVIORS[:stderr]]
68
+ end
69
+
70
+ # Sets the behavior to the specified value. Can be a single value, array,
71
+ # or an object that responds to +call+.
72
+ #
73
+ # Available behaviors:
74
+ #
75
+ # [+raise+] Raise <tt>ActiveSupport::DeprecationException</tt>.
76
+ # [+stderr+] Log all deprecation warnings to +$stderr+.
77
+ # [+log+] Log all deprecation warnings to +Rails.logger+.
78
+ # [+notify+] Use +ActiveSupport::Notifications+ to notify +deprecation.rails+.
79
+ # [+silence+] Do nothing.
80
+ #
81
+ # Setting behaviors only affects deprecations that happen after boot time.
82
+ # Deprecation warnings raised by gems are not affected by this setting
83
+ # because they happen before Rails boots up.
84
+ #
85
+ # ActiveSupport::Deprecation.behavior = :stderr
86
+ # ActiveSupport::Deprecation.behavior = [:stderr, :log]
87
+ # ActiveSupport::Deprecation.behavior = MyCustomHandler
88
+ # ActiveSupport::Deprecation.behavior = ->(message, callstack, deprecation_horizon, gem_name) {
89
+ # # custom stuff
90
+ # }
91
+ def behavior=(behavior)
92
+ @behavior = Array(behavior).map { |b| DEFAULT_BEHAVIORS[b] || arity_coerce(b) }
93
+ end
94
+
95
+ private
96
+ def arity_coerce(behavior)
97
+ unless behavior.respond_to?(:call)
98
+ raise ArgumentError, "#{behavior.inspect} is not a valid deprecation behavior."
99
+ end
100
+
101
+ if behavior.arity == 4 || behavior.arity == -1
102
+ behavior
103
+ else
104
+ -> message, callstack, _, _ { behavior.call(message, callstack) }
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveSupport
4
+ class Deprecation
5
+ # DeprecatedConstantAccessor transforms a constant into a deprecated one by
6
+ # hooking +const_missing+.
7
+ #
8
+ # It takes the names of an old (deprecated) constant and of a new constant
9
+ # (both in string form) and optionally a deprecator. The deprecator defaults
10
+ # to +ActiveSupport::Deprecator+ if none is specified.
11
+ #
12
+ # The deprecated constant now returns the same object as the new one rather
13
+ # than a proxy object, so it can be used transparently in +rescue+ blocks
14
+ # etc.
15
+ #
16
+ # PLANETS = %w(mercury venus earth mars jupiter saturn uranus neptune pluto)
17
+ #
18
+ # # (In a later update, the original implementation of `PLANETS` has been removed.)
19
+ #
20
+ # PLANETS_POST_2006 = %w(mercury venus earth mars jupiter saturn uranus neptune)
21
+ # include ActiveSupport::Deprecation::DeprecatedConstantAccessor
22
+ # deprecate_constant 'PLANETS', 'PLANETS_POST_2006'
23
+ #
24
+ # PLANETS.map { |planet| planet.capitalize }
25
+ # # => DEPRECATION WARNING: PLANETS is deprecated! Use PLANETS_POST_2006 instead.
26
+ # (Backtrace information…)
27
+ # ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"]
28
+ module DeprecatedConstantAccessor
29
+ def self.included(base)
30
+ require "active_support/inflector/methods"
31
+
32
+ extension = Module.new do
33
+ def const_missing(missing_const_name)
34
+ if class_variable_defined?(:@@_deprecated_constants)
35
+ if (replacement = class_variable_get(:@@_deprecated_constants)[missing_const_name.to_s])
36
+ replacement[:deprecator].warn(replacement[:message] || "#{name}::#{missing_const_name} is deprecated! Use #{replacement[:new]} instead.", caller_locations)
37
+ return ActiveSupport::Inflector.constantize(replacement[:new].to_s)
38
+ end
39
+ end
40
+ super
41
+ end
42
+
43
+ def deprecate_constant(const_name, new_constant, message: nil, deprecator: ActiveSupport::Deprecation.instance)
44
+ class_variable_set(:@@_deprecated_constants, {}) unless class_variable_defined?(:@@_deprecated_constants)
45
+ class_variable_get(:@@_deprecated_constants)[const_name.to_s] = { new: new_constant, message: message, deprecator: deprecator }
46
+ end
47
+ end
48
+ base.singleton_class.prepend extension
49
+ end
50
+ end
51
+ end
52
+ end