activesupport 1.2.4 → 8.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (309) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +505 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +40 -0
  5. data/lib/active_support/actionable_error.rb +50 -0
  6. data/lib/active_support/all.rb +5 -0
  7. data/lib/active_support/array_inquirer.rb +50 -0
  8. data/lib/active_support/backtrace_cleaner.rb +234 -0
  9. data/lib/active_support/benchmark.rb +21 -0
  10. data/lib/active_support/benchmarkable.rb +53 -0
  11. data/lib/active_support/broadcast_logger.rb +238 -0
  12. data/lib/active_support/builder.rb +8 -0
  13. data/lib/active_support/cache/coder.rb +153 -0
  14. data/lib/active_support/cache/entry.rb +134 -0
  15. data/lib/active_support/cache/file_store.rb +244 -0
  16. data/lib/active_support/cache/mem_cache_store.rb +288 -0
  17. data/lib/active_support/cache/memory_store.rb +264 -0
  18. data/lib/active_support/cache/null_store.rb +62 -0
  19. data/lib/active_support/cache/redis_cache_store.rb +498 -0
  20. data/lib/active_support/cache/serializer_with_fallback.rb +152 -0
  21. data/lib/active_support/cache/strategy/local_cache.rb +246 -0
  22. data/lib/active_support/cache/strategy/local_cache_middleware.rb +45 -0
  23. data/lib/active_support/cache.rb +1170 -0
  24. data/lib/active_support/callbacks.rb +960 -0
  25. data/lib/active_support/class_attribute.rb +33 -0
  26. data/lib/active_support/code_generator.rb +79 -0
  27. data/lib/active_support/concern.rb +217 -0
  28. data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +18 -0
  29. data/lib/active_support/concurrency/null_lock.rb +13 -0
  30. data/lib/active_support/concurrency/share_lock.rb +225 -0
  31. data/lib/active_support/concurrency/thread_monitor.rb +55 -0
  32. data/lib/active_support/configurable.rb +193 -0
  33. data/lib/active_support/configuration_file.rb +60 -0
  34. data/lib/active_support/continuous_integration.rb +145 -0
  35. data/lib/active_support/core_ext/array/access.rb +100 -0
  36. data/lib/active_support/core_ext/array/conversions.rb +209 -26
  37. data/lib/active_support/core_ext/array/extract.rb +21 -0
  38. data/lib/active_support/core_ext/array/extract_options.rb +31 -0
  39. data/lib/active_support/core_ext/array/grouping.rb +109 -0
  40. data/lib/active_support/core_ext/array/inquiry.rb +19 -0
  41. data/lib/active_support/core_ext/array/wrap.rb +48 -0
  42. data/lib/active_support/core_ext/array.rb +8 -4
  43. data/lib/active_support/core_ext/benchmark.rb +6 -0
  44. data/lib/active_support/core_ext/big_decimal/conversions.rb +14 -0
  45. data/lib/active_support/core_ext/big_decimal.rb +3 -0
  46. data/lib/active_support/core_ext/class/attribute.rb +137 -0
  47. data/lib/active_support/core_ext/class/attribute_accessors.rb +6 -0
  48. data/lib/active_support/core_ext/class/subclasses.rb +24 -0
  49. data/lib/active_support/core_ext/class.rb +4 -0
  50. data/lib/active_support/core_ext/date/acts_like.rb +10 -0
  51. data/lib/active_support/core_ext/date/blank.rb +18 -0
  52. data/lib/active_support/core_ext/date/calculations.rb +161 -0
  53. data/lib/active_support/core_ext/date/conversions.rb +95 -28
  54. data/lib/active_support/core_ext/date/zones.rb +8 -0
  55. data/lib/active_support/core_ext/date.rb +6 -5
  56. data/lib/active_support/core_ext/date_and_time/calculations.rb +374 -0
  57. data/lib/active_support/core_ext/date_and_time/compatibility.rb +23 -0
  58. data/lib/active_support/core_ext/date_and_time/zones.rb +40 -0
  59. data/lib/active_support/core_ext/date_time/acts_like.rb +16 -0
  60. data/lib/active_support/core_ext/date_time/blank.rb +18 -0
  61. data/lib/active_support/core_ext/date_time/calculations.rb +215 -0
  62. data/lib/active_support/core_ext/date_time/compatibility.rb +16 -0
  63. data/lib/active_support/core_ext/date_time/conversions.rb +108 -0
  64. data/lib/active_support/core_ext/date_time.rb +7 -0
  65. data/lib/active_support/core_ext/digest/uuid.rb +76 -0
  66. data/lib/active_support/core_ext/digest.rb +3 -0
  67. data/lib/active_support/core_ext/enumerable.rb +277 -7
  68. data/lib/active_support/core_ext/erb/util.rb +201 -0
  69. data/lib/active_support/core_ext/file/atomic.rb +72 -0
  70. data/lib/active_support/core_ext/file.rb +3 -0
  71. data/lib/active_support/core_ext/hash/conversions.rb +262 -0
  72. data/lib/active_support/core_ext/hash/deep_merge.rb +43 -0
  73. data/lib/active_support/core_ext/hash/deep_transform_values.rb +46 -0
  74. data/lib/active_support/core_ext/hash/except.rb +12 -0
  75. data/lib/active_support/core_ext/hash/indifferent_access.rb +19 -55
  76. data/lib/active_support/core_ext/hash/keys.rb +134 -44
  77. data/lib/active_support/core_ext/hash/reverse_merge.rb +22 -22
  78. data/lib/active_support/core_ext/hash/slice.rb +27 -0
  79. data/lib/active_support/core_ext/hash.rb +9 -8
  80. data/lib/active_support/core_ext/integer/inflections.rb +29 -13
  81. data/lib/active_support/core_ext/integer/multiple.rb +12 -0
  82. data/lib/active_support/core_ext/integer/time.rb +22 -0
  83. data/lib/active_support/core_ext/integer.rb +4 -6
  84. data/lib/active_support/core_ext/kernel/concern.rb +14 -0
  85. data/lib/active_support/core_ext/kernel/reporting.rb +45 -0
  86. data/lib/active_support/core_ext/kernel/singleton_class.rb +8 -0
  87. data/lib/active_support/core_ext/kernel.rb +4 -78
  88. data/lib/active_support/core_ext/load_error.rb +6 -35
  89. data/lib/active_support/core_ext/module/aliasing.rb +31 -0
  90. data/lib/active_support/core_ext/module/anonymous.rb +30 -0
  91. data/lib/active_support/core_ext/module/attr_internal.rb +48 -0
  92. data/lib/active_support/core_ext/module/attribute_accessors.rb +214 -0
  93. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +175 -0
  94. data/lib/active_support/core_ext/module/concerning.rb +140 -0
  95. data/lib/active_support/core_ext/module/delegation.rb +225 -0
  96. data/lib/active_support/core_ext/module/deprecation.rb +25 -0
  97. data/lib/active_support/core_ext/module/introspection.rb +65 -0
  98. data/lib/active_support/core_ext/module/redefine_method.rb +40 -0
  99. data/lib/active_support/core_ext/module/remove_method.rb +17 -0
  100. data/lib/active_support/core_ext/module.rb +13 -0
  101. data/lib/active_support/core_ext/name_error.rb +59 -0
  102. data/lib/active_support/core_ext/numeric/bytes.rb +73 -42
  103. data/lib/active_support/core_ext/numeric/conversions.rb +145 -0
  104. data/lib/active_support/core_ext/numeric/time.rb +64 -57
  105. data/lib/active_support/core_ext/numeric.rb +4 -6
  106. data/lib/active_support/core_ext/object/acts_like.rb +45 -0
  107. data/lib/active_support/core_ext/object/blank.rb +199 -0
  108. data/lib/active_support/core_ext/object/conversions.rb +6 -0
  109. data/lib/active_support/core_ext/object/deep_dup.rb +71 -0
  110. data/lib/active_support/core_ext/object/duplicable.rb +69 -0
  111. data/lib/active_support/core_ext/object/inclusion.rb +37 -0
  112. data/lib/active_support/core_ext/object/instance_variables.rb +32 -0
  113. data/lib/active_support/core_ext/object/json.rb +267 -0
  114. data/lib/active_support/core_ext/object/to_param.rb +3 -0
  115. data/lib/active_support/core_ext/object/to_query.rb +93 -0
  116. data/lib/active_support/core_ext/object/try.rb +158 -0
  117. data/lib/active_support/core_ext/object/with.rb +46 -0
  118. data/lib/active_support/core_ext/object/with_options.rb +101 -0
  119. data/lib/active_support/core_ext/object.rb +17 -0
  120. data/lib/active_support/core_ext/pathname/blank.rb +20 -0
  121. data/lib/active_support/core_ext/pathname/existence.rb +23 -0
  122. data/lib/active_support/core_ext/pathname.rb +4 -0
  123. data/lib/active_support/core_ext/range/compare_range.rb +57 -0
  124. data/lib/active_support/core_ext/range/conversions.rb +58 -17
  125. data/lib/active_support/core_ext/range/overlap.rb +40 -0
  126. data/lib/active_support/core_ext/range/sole.rb +17 -0
  127. data/lib/active_support/core_ext/range.rb +5 -4
  128. data/lib/active_support/core_ext/regexp.rb +14 -0
  129. data/lib/active_support/core_ext/securerandom.rb +57 -0
  130. data/lib/active_support/core_ext/string/access.rb +93 -56
  131. data/lib/active_support/core_ext/string/behavior.rb +8 -0
  132. data/lib/active_support/core_ext/string/conversions.rb +57 -16
  133. data/lib/active_support/core_ext/string/exclude.rb +13 -0
  134. data/lib/active_support/core_ext/string/filters.rb +151 -0
  135. data/lib/active_support/core_ext/string/indent.rb +45 -0
  136. data/lib/active_support/core_ext/string/inflections.rb +297 -54
  137. data/lib/active_support/core_ext/string/inquiry.rb +16 -0
  138. data/lib/active_support/core_ext/string/multibyte.rb +67 -0
  139. data/lib/active_support/core_ext/string/output_safety.rb +235 -0
  140. data/lib/active_support/core_ext/string/starts_ends_with.rb +4 -18
  141. data/lib/active_support/core_ext/string/strip.rb +27 -0
  142. data/lib/active_support/core_ext/string/zones.rb +16 -0
  143. data/lib/active_support/core_ext/string.rb +14 -10
  144. data/lib/active_support/core_ext/symbol/starts_ends_with.rb +6 -0
  145. data/lib/active_support/core_ext/symbol.rb +3 -0
  146. data/lib/active_support/core_ext/thread/backtrace/location.rb +7 -0
  147. data/lib/active_support/core_ext/time/acts_like.rb +10 -0
  148. data/lib/active_support/core_ext/time/calculations.rb +358 -153
  149. data/lib/active_support/core_ext/time/compatibility.rb +15 -0
  150. data/lib/active_support/core_ext/time/conversions.rb +69 -30
  151. data/lib/active_support/core_ext/time/zones.rb +97 -0
  152. data/lib/active_support/core_ext/time.rb +6 -6
  153. data/lib/active_support/core_ext.rb +5 -1
  154. data/lib/active_support/current_attributes/test_helper.rb +13 -0
  155. data/lib/active_support/current_attributes.rb +243 -0
  156. data/lib/active_support/deep_mergeable.rb +53 -0
  157. data/lib/active_support/delegation.rb +183 -0
  158. data/lib/active_support/dependencies/autoload.rb +72 -0
  159. data/lib/active_support/dependencies/interlock.rb +55 -0
  160. data/lib/active_support/dependencies/require_dependency.rb +28 -0
  161. data/lib/active_support/dependencies.rb +84 -222
  162. data/lib/active_support/deprecation/behaviors.rb +148 -0
  163. data/lib/active_support/deprecation/constant_accessor.rb +74 -0
  164. data/lib/active_support/deprecation/deprecators.rb +104 -0
  165. data/lib/active_support/deprecation/disallowed.rb +54 -0
  166. data/lib/active_support/deprecation/method_wrappers.rb +68 -0
  167. data/lib/active_support/deprecation/proxy_wrappers.rb +189 -0
  168. data/lib/active_support/deprecation/reporting.rb +162 -0
  169. data/lib/active_support/deprecation.rb +81 -0
  170. data/lib/active_support/deprecator.rb +7 -0
  171. data/lib/active_support/descendants_tracker.rb +112 -0
  172. data/lib/active_support/digest.rb +22 -0
  173. data/lib/active_support/duration/iso8601_parser.rb +123 -0
  174. data/lib/active_support/duration/iso8601_serializer.rb +64 -0
  175. data/lib/active_support/duration.rb +524 -0
  176. data/lib/active_support/editor.rb +70 -0
  177. data/lib/active_support/encrypted_configuration.rb +126 -0
  178. data/lib/active_support/encrypted_file.rb +133 -0
  179. data/lib/active_support/environment_inquirer.rb +40 -0
  180. data/lib/active_support/error_reporter/test_helper.rb +15 -0
  181. data/lib/active_support/error_reporter.rb +318 -0
  182. data/lib/active_support/event_reporter/test_helper.rb +32 -0
  183. data/lib/active_support/event_reporter.rb +592 -0
  184. data/lib/active_support/evented_file_update_checker.rb +185 -0
  185. data/lib/active_support/execution_context/test_helper.rb +13 -0
  186. data/lib/active_support/execution_context.rb +110 -0
  187. data/lib/active_support/execution_wrapper.rb +150 -0
  188. data/lib/active_support/executor/test_helper.rb +7 -0
  189. data/lib/active_support/executor.rb +8 -0
  190. data/lib/active_support/file_update_checker.rb +166 -0
  191. data/lib/active_support/fork_tracker.rb +43 -0
  192. data/lib/active_support/gem_version.rb +17 -0
  193. data/lib/active_support/gzip.rb +41 -0
  194. data/lib/active_support/hash_with_indifferent_access.rb +464 -0
  195. data/lib/active_support/html_safe_translation.rb +56 -0
  196. data/lib/active_support/i18n.rb +17 -0
  197. data/lib/active_support/i18n_railtie.rb +140 -0
  198. data/lib/active_support/inflections.rb +68 -49
  199. data/lib/active_support/inflector/inflections.rb +290 -0
  200. data/lib/active_support/inflector/methods.rb +387 -0
  201. data/lib/active_support/inflector/transliterate.rb +147 -0
  202. data/lib/active_support/inflector.rb +7 -164
  203. data/lib/active_support/isolated_execution_state.rb +76 -0
  204. data/lib/active_support/json/decoding.rb +78 -0
  205. data/lib/active_support/json/encoding.rb +256 -0
  206. data/lib/active_support/json.rb +4 -0
  207. data/lib/active_support/key_generator.rb +66 -0
  208. data/lib/active_support/lazy_load_hooks.rb +107 -0
  209. data/lib/active_support/locale/en.rb +33 -0
  210. data/lib/active_support/locale/en.yml +141 -0
  211. data/lib/active_support/log_subscriber/test_helper.rb +106 -0
  212. data/lib/active_support/log_subscriber.rb +188 -0
  213. data/lib/active_support/logger.rb +55 -0
  214. data/lib/active_support/logger_silence.rb +21 -0
  215. data/lib/active_support/logger_thread_safe_level.rb +50 -0
  216. data/lib/active_support/message_encryptor.rb +374 -0
  217. data/lib/active_support/message_encryptors.rb +193 -0
  218. data/lib/active_support/message_pack/cache_serializer.rb +23 -0
  219. data/lib/active_support/message_pack/extensions.rb +310 -0
  220. data/lib/active_support/message_pack/serializer.rb +63 -0
  221. data/lib/active_support/message_pack.rb +50 -0
  222. data/lib/active_support/message_verifier.rb +377 -0
  223. data/lib/active_support/message_verifiers.rb +189 -0
  224. data/lib/active_support/messages/codec.rb +65 -0
  225. data/lib/active_support/messages/metadata.rb +146 -0
  226. data/lib/active_support/messages/rotation_configuration.rb +23 -0
  227. data/lib/active_support/messages/rotation_coordinator.rb +102 -0
  228. data/lib/active_support/messages/rotator.rb +69 -0
  229. data/lib/active_support/messages/serializer_with_fallback.rb +158 -0
  230. data/lib/active_support/multibyte/chars.rb +188 -0
  231. data/lib/active_support/multibyte/unicode.rb +42 -0
  232. data/lib/active_support/multibyte.rb +27 -0
  233. data/lib/active_support/notifications/fanout.rb +467 -0
  234. data/lib/active_support/notifications/instrumenter.rb +240 -0
  235. data/lib/active_support/notifications.rb +281 -0
  236. data/lib/active_support/number_helper/number_converter.rb +190 -0
  237. data/lib/active_support/number_helper/number_to_currency_converter.rb +46 -0
  238. data/lib/active_support/number_helper/number_to_delimited_converter.rb +30 -0
  239. data/lib/active_support/number_helper/number_to_human_converter.rb +69 -0
  240. data/lib/active_support/number_helper/number_to_human_size_converter.rb +60 -0
  241. data/lib/active_support/number_helper/number_to_percentage_converter.rb +16 -0
  242. data/lib/active_support/number_helper/number_to_phone_converter.rb +60 -0
  243. data/lib/active_support/number_helper/number_to_rounded_converter.rb +59 -0
  244. data/lib/active_support/number_helper/rounding_helper.rb +46 -0
  245. data/lib/active_support/number_helper.rb +479 -0
  246. data/lib/active_support/option_merger.rb +38 -0
  247. data/lib/active_support/ordered_hash.rb +50 -0
  248. data/lib/active_support/ordered_options.rb +141 -25
  249. data/lib/active_support/parameter_filter.rb +157 -0
  250. data/lib/active_support/rails.rb +26 -0
  251. data/lib/active_support/railtie.rb +180 -0
  252. data/lib/active_support/reloader.rb +138 -0
  253. data/lib/active_support/rescuable.rb +176 -0
  254. data/lib/active_support/secure_compare_rotator.rb +58 -0
  255. data/lib/active_support/security_utils.rb +38 -0
  256. data/lib/active_support/string_inquirer.rb +35 -0
  257. data/lib/active_support/structured_event_subscriber.rb +99 -0
  258. data/lib/active_support/subscriber.rb +141 -0
  259. data/lib/active_support/syntax_error_proxy.rb +67 -0
  260. data/lib/active_support/tagged_logging.rb +157 -0
  261. data/lib/active_support/test_case.rb +365 -0
  262. data/lib/active_support/testing/assertions.rb +369 -0
  263. data/lib/active_support/testing/autorun.rb +10 -0
  264. data/lib/active_support/testing/constant_lookup.rb +51 -0
  265. data/lib/active_support/testing/constant_stubbing.rb +54 -0
  266. data/lib/active_support/testing/declarative.rb +28 -0
  267. data/lib/active_support/testing/deprecation.rb +82 -0
  268. data/lib/active_support/testing/error_reporter_assertions.rb +124 -0
  269. data/lib/active_support/testing/event_reporter_assertions.rb +227 -0
  270. data/lib/active_support/testing/file_fixtures.rb +38 -0
  271. data/lib/active_support/testing/isolation.rb +121 -0
  272. data/lib/active_support/testing/method_call_assertions.rb +69 -0
  273. data/lib/active_support/testing/notification_assertions.rb +92 -0
  274. data/lib/active_support/testing/parallelization/server.rb +98 -0
  275. data/lib/active_support/testing/parallelization/worker.rb +107 -0
  276. data/lib/active_support/testing/parallelization.rb +79 -0
  277. data/lib/active_support/testing/parallelize_executor.rb +81 -0
  278. data/lib/active_support/testing/setup_and_teardown.rb +57 -0
  279. data/lib/active_support/testing/stream.rb +41 -0
  280. data/lib/active_support/testing/tagged_logging.rb +27 -0
  281. data/lib/active_support/testing/tests_without_assertions.rb +19 -0
  282. data/lib/active_support/testing/time_helpers.rb +273 -0
  283. data/lib/active_support/time.rb +20 -0
  284. data/lib/active_support/time_with_zone.rb +613 -0
  285. data/lib/active_support/values/time_zone.rb +599 -158
  286. data/lib/active_support/version.rb +7 -6
  287. data/lib/active_support/xml_mini/jdom.rb +175 -0
  288. data/lib/active_support/xml_mini/libxml.rb +80 -0
  289. data/lib/active_support/xml_mini/libxmlsax.rb +83 -0
  290. data/lib/active_support/xml_mini/nokogiri.rb +83 -0
  291. data/lib/active_support/xml_mini/nokogirisax.rb +86 -0
  292. data/lib/active_support/xml_mini/rexml.rb +137 -0
  293. data/lib/active_support/xml_mini.rb +212 -0
  294. data/lib/active_support.rb +122 -10
  295. metadata +524 -93
  296. data/CHANGELOG +0 -283
  297. data/lib/active_support/binding_of_caller.rb +0 -84
  298. data/lib/active_support/breakpoint.rb +0 -523
  299. data/lib/active_support/class_attribute_accessors.rb +0 -57
  300. data/lib/active_support/class_inheritable_attributes.rb +0 -117
  301. data/lib/active_support/clean_logger.rb +0 -36
  302. data/lib/active_support/core_ext/blank.rb +0 -38
  303. data/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +0 -14
  304. data/lib/active_support/core_ext/cgi.rb +0 -5
  305. data/lib/active_support/core_ext/exception.rb +0 -29
  306. data/lib/active_support/core_ext/integer/even_odd.rb +0 -24
  307. data/lib/active_support/core_ext/object_and_class.rb +0 -44
  308. data/lib/active_support/module_attribute_accessors.rb +0 -57
  309. data/lib/active_support/whiny_nil.rb +0 -38
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveSupport
4
+ class Deprecation
5
+ # A managed collection of deprecators. Configuration methods, such as
6
+ # #behavior=, affect all deprecators in the collection. Additionally, the
7
+ # #silence method silences all deprecators in the collection for the
8
+ # duration of a given block.
9
+ class Deprecators
10
+ def initialize
11
+ @options = {}
12
+ @deprecators = {}
13
+ end
14
+
15
+ # Returns a deprecator added to this collection via #[]=.
16
+ def [](name)
17
+ @deprecators[name]
18
+ end
19
+
20
+ # Adds a given +deprecator+ to this collection. The deprecator will be
21
+ # immediately configured with any options previously set on this
22
+ # collection.
23
+ #
24
+ # deprecators = ActiveSupport::Deprecation::Deprecators.new
25
+ # deprecators.debug = true
26
+ #
27
+ # foo_deprecator = ActiveSupport::Deprecation.new("2.0", "Foo")
28
+ # foo_deprecator.debug # => false
29
+ #
30
+ # deprecators[:foo] = foo_deprecator
31
+ # deprecators[:foo].debug # => true
32
+ # foo_deprecator.debug # => true
33
+ #
34
+ def []=(name, deprecator)
35
+ apply_options(deprecator)
36
+ @deprecators[name] = deprecator
37
+ end
38
+
39
+ # Iterates over all deprecators in this collection. If no block is given,
40
+ # returns an +Enumerator+.
41
+ def each(&block)
42
+ return to_enum(__method__) unless block
43
+ @deprecators.each_value(&block)
44
+ end
45
+
46
+ # Sets the silenced flag for all deprecators in this collection.
47
+ def silenced=(silenced)
48
+ set_option(:silenced, silenced)
49
+ end
50
+
51
+ # Sets the debug flag for all deprecators in this collection.
52
+ def debug=(debug)
53
+ set_option(:debug, debug)
54
+ end
55
+
56
+ # Sets the deprecation warning behavior for all deprecators in this
57
+ # collection.
58
+ #
59
+ # See ActiveSupport::Deprecation#behavior=.
60
+ def behavior=(behavior)
61
+ set_option(:behavior, behavior)
62
+ end
63
+
64
+ # Sets the disallowed deprecation warning behavior for all deprecators in
65
+ # this collection.
66
+ #
67
+ # See ActiveSupport::Deprecation#disallowed_behavior=.
68
+ def disallowed_behavior=(disallowed_behavior)
69
+ set_option(:disallowed_behavior, disallowed_behavior)
70
+ end
71
+
72
+ # Sets the disallowed deprecation warnings for all deprecators in this
73
+ # collection.
74
+ #
75
+ # See ActiveSupport::Deprecation#disallowed_warnings=.
76
+ def disallowed_warnings=(disallowed_warnings)
77
+ set_option(:disallowed_warnings, disallowed_warnings)
78
+ end
79
+
80
+ # Silences all deprecators in this collection for the duration of the
81
+ # given block.
82
+ #
83
+ # See ActiveSupport::Deprecation#silence.
84
+ def silence(&block)
85
+ each { |deprecator| deprecator.begin_silence }
86
+ block.call
87
+ ensure
88
+ each { |deprecator| deprecator.end_silence }
89
+ end
90
+
91
+ private
92
+ def set_option(name, value)
93
+ @options[name] = value
94
+ each { |deprecator| deprecator.public_send("#{name}=", value) }
95
+ end
96
+
97
+ def apply_options(deprecator)
98
+ @options.each do |name, value|
99
+ deprecator.public_send("#{name}=", value)
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveSupport
4
+ class Deprecation
5
+ module Disallowed
6
+ # Sets the criteria used to identify deprecation messages which should be
7
+ # disallowed. Can be an array containing strings, symbols, or regular
8
+ # expressions. (Symbols are treated as strings.) These are compared against
9
+ # the text of the generated deprecation warning.
10
+ #
11
+ # Additionally the scalar symbol +:all+ may be used to treat all
12
+ # deprecations as disallowed.
13
+ #
14
+ # Deprecations matching a substring or regular expression will be handled
15
+ # using the configured Behavior#disallowed_behavior rather than
16
+ # Behavior#behavior.
17
+ attr_writer :disallowed_warnings
18
+
19
+ # Returns the configured criteria used to identify deprecation messages
20
+ # which should be treated as disallowed.
21
+ def disallowed_warnings
22
+ @disallowed_warnings ||= []
23
+ end
24
+
25
+ private
26
+ def deprecation_disallowed?(message)
27
+ return false if explicitly_allowed?(message)
28
+ return true if disallowed_warnings == :all
29
+ message && disallowed_warnings.any? do |rule|
30
+ case rule
31
+ when String, Symbol
32
+ message.include?(rule.to_s)
33
+ when Regexp
34
+ rule.match?(message)
35
+ end
36
+ end
37
+ end
38
+
39
+ def explicitly_allowed?(message)
40
+ allowances = @explicitly_allowed_warnings.value
41
+ return false unless allowances
42
+ return true if allowances == :all
43
+ message && Array(allowances).any? do |rule|
44
+ case rule
45
+ when String, Symbol
46
+ message.include?(rule.to_s)
47
+ when Regexp
48
+ rule.match?(message)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/array/extract_options"
4
+ require "active_support/core_ext/module/redefine_method"
5
+
6
+ module ActiveSupport
7
+ class Deprecation
8
+ module MethodWrapper
9
+ # Declare that a method has been deprecated.
10
+ #
11
+ # class Fred
12
+ # def aaa; end
13
+ # def bbb; end
14
+ # def ccc; end
15
+ # def ddd; end
16
+ # def eee; end
17
+ # end
18
+ #
19
+ # deprecator = ActiveSupport::Deprecation.new('next-release', 'MyGem')
20
+ #
21
+ # deprecator.deprecate_methods(Fred, :aaa, bbb: :zzz, ccc: 'use Bar#ccc instead')
22
+ # # => Fred
23
+ #
24
+ # Fred.new.aaa
25
+ # # DEPRECATION WARNING: aaa is deprecated and will be removed from MyGem next-release. (called from irb_binding at (irb):10)
26
+ # # => nil
27
+ #
28
+ # Fred.new.bbb
29
+ # # DEPRECATION WARNING: bbb is deprecated and will be removed from MyGem next-release (use zzz instead). (called from irb_binding at (irb):11)
30
+ # # => nil
31
+ #
32
+ # Fred.new.ccc
33
+ # # DEPRECATION WARNING: ccc is deprecated and will be removed from MyGem next-release (use Bar#ccc instead). (called from irb_binding at (irb):12)
34
+ # # => nil
35
+ def deprecate_methods(target_module, *method_names)
36
+ options = method_names.extract_options!
37
+ deprecator = options.delete(:deprecator) || self
38
+ method_names += options.keys
39
+ mod = nil
40
+
41
+ method_names.each do |method_name|
42
+ message = options[method_name]
43
+ if target_module.method_defined?(method_name) || target_module.private_method_defined?(method_name)
44
+ method = target_module.instance_method(method_name)
45
+ target_module.module_eval do
46
+ redefine_method(method_name) do |*args, &block|
47
+ deprecator.deprecation_warning(method_name, message)
48
+ method.bind_call(self, *args, &block)
49
+ end
50
+ ruby2_keywords(method_name)
51
+ end
52
+ else
53
+ mod ||= Module.new
54
+ mod.module_eval do
55
+ define_method(method_name) do |*args, &block|
56
+ deprecator.deprecation_warning(method_name, message)
57
+ super(*args, &block)
58
+ end
59
+ ruby2_keywords(method_name)
60
+ end
61
+ end
62
+ end
63
+
64
+ target_module.prepend(mod) if mod
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,189 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveSupport
4
+ class Deprecation
5
+ class DeprecationProxy # :nodoc:
6
+ def self.new(*args, **kwargs, &block)
7
+ object = args.first
8
+
9
+ return object unless object
10
+ super
11
+ end
12
+
13
+ instance_methods.each { |m| undef_method m unless /^__|^object_id$/.match?(m) }
14
+
15
+ # Don't give a deprecation warning on inspect since test/unit and error
16
+ # logs rely on it for diagnostics.
17
+ def inspect
18
+ target.inspect
19
+ end
20
+
21
+ private
22
+ def method_missing(called, *args, &block)
23
+ warn caller_locations, called, args
24
+ target.__send__(called, *args, &block)
25
+ end
26
+ end
27
+
28
+ # DeprecatedObjectProxy transforms an object into a deprecated one. It takes an object, a deprecation message, and
29
+ # a deprecator.
30
+ #
31
+ # deprecated_object = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(Object.new, "This object is now deprecated", ActiveSupport::Deprecation.new)
32
+ # # => #<Object:0x007fb9b34c34b0>
33
+ #
34
+ # deprecated_object.to_s
35
+ # DEPRECATION WARNING: This object is now deprecated.
36
+ # (Backtrace)
37
+ # # => "#<Object:0x007fb9b34c34b0>"
38
+ class DeprecatedObjectProxy < DeprecationProxy
39
+ def initialize(object, message, deprecator)
40
+ @object = object
41
+ @message = message
42
+ @deprecator = deprecator
43
+ end
44
+
45
+ private
46
+ def target
47
+ @object
48
+ end
49
+
50
+ def warn(callstack, called, args)
51
+ @deprecator.warn(@message, callstack)
52
+ end
53
+ end
54
+
55
+ # DeprecatedInstanceVariableProxy transforms an instance variable into a deprecated one. It takes an instance of a
56
+ # class, a method on that class, an instance variable, and a deprecator as the last argument.
57
+ #
58
+ # Trying to use the deprecated instance variable will result in a deprecation warning, pointing to the method as a
59
+ # replacement.
60
+ #
61
+ # class Example
62
+ # def initialize
63
+ # @request = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :request, :@request, ActiveSupport::Deprecation.new)
64
+ # @_request = :special_request
65
+ # end
66
+ #
67
+ # def request
68
+ # @_request
69
+ # end
70
+ #
71
+ # def old_request
72
+ # @request
73
+ # end
74
+ # end
75
+ #
76
+ # example = Example.new
77
+ # # => #<Example:0x007fb9b31090b8 @_request=:special_request, @request=:special_request>
78
+ #
79
+ # example.old_request.to_s
80
+ # # => DEPRECATION WARNING: @request is deprecated! Call request.to_s instead of
81
+ # @request.to_s
82
+ # (Backtrace information…)
83
+ # "special_request"
84
+ #
85
+ # example.request.to_s
86
+ # # => "special_request"
87
+ class DeprecatedInstanceVariableProxy < DeprecationProxy
88
+ def initialize(instance, method, var = "@#{method}", deprecator:)
89
+ @instance = instance
90
+ @method = method
91
+ @var = var
92
+ @deprecator = deprecator
93
+ end
94
+
95
+ private
96
+ def target
97
+ @instance.__send__(@method)
98
+ end
99
+
100
+ def warn(callstack, called, args)
101
+ @deprecator.warn("#{@var} is deprecated! Call #{@method}.#{called} instead of #{@var}.#{called}. Args: #{args.inspect}", callstack)
102
+ end
103
+ end
104
+
105
+ # DeprecatedConstantProxy transforms a constant into a deprecated one. It takes the full names of an old
106
+ # (deprecated) constant and of a new constant (both in string form) and a deprecator. The deprecated constant now
107
+ # returns the value of the new one.
108
+ #
109
+ # PLANETS = %w(mercury venus earth mars jupiter saturn uranus neptune pluto)
110
+ #
111
+ # # (In a later update, the original implementation of `PLANETS` has been removed.)
112
+ #
113
+ # PLANETS_POST_2006 = %w(mercury venus earth mars jupiter saturn uranus neptune)
114
+ # PLANETS = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("PLANETS", "PLANETS_POST_2006", ActiveSupport::Deprecation.new)
115
+ #
116
+ # PLANETS.map { |planet| planet.capitalize }
117
+ # # => DEPRECATION WARNING: PLANETS is deprecated! Use PLANETS_POST_2006 instead.
118
+ # (Backtrace information…)
119
+ # ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"]
120
+ class DeprecatedConstantProxy < Module
121
+ def self.new(*args, **options, &block)
122
+ object = args.first
123
+
124
+ return object unless object
125
+ super
126
+ end
127
+
128
+ def initialize(old_const, new_const, deprecator, message: "#{old_const} is deprecated! Use #{new_const} instead.")
129
+ Kernel.require "active_support/inflector/methods"
130
+
131
+ @old_const = old_const
132
+ @new_const = new_const
133
+ @deprecator = deprecator
134
+ @message = message
135
+ end
136
+
137
+ instance_methods.each { |m| undef_method m unless /^__|^object_id$/.match?(m) }
138
+
139
+ # Don't give a deprecation warning on inspect since test/unit and error
140
+ # logs rely on it for diagnostics.
141
+ def inspect
142
+ target.inspect
143
+ end
144
+
145
+ # Don't give a deprecation warning on methods that IRB may invoke
146
+ # during tab-completion.
147
+ delegate :hash, :instance_methods, :name, :respond_to?, to: :target
148
+
149
+ # Returns the class of the new constant.
150
+ #
151
+ # PLANETS_POST_2006 = %w(mercury venus earth mars jupiter saturn uranus neptune)
152
+ # PLANETS = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('PLANETS', 'PLANETS_POST_2006')
153
+ # PLANETS.class # => Array
154
+ def class
155
+ target.class
156
+ end
157
+
158
+ def append_features(base)
159
+ @deprecator.warn(@message, caller_locations)
160
+ base.include(target)
161
+ end
162
+
163
+ def prepend_features(base)
164
+ @deprecator.warn(@message, caller_locations)
165
+ base.prepend(target)
166
+ end
167
+
168
+ def extended(base)
169
+ @deprecator.warn(@message, caller_locations)
170
+ base.extend(target)
171
+ end
172
+
173
+ private
174
+ def target
175
+ ActiveSupport::Inflector.constantize(@new_const.to_s)
176
+ end
177
+
178
+ def const_missing(name)
179
+ @deprecator.warn(@message, caller_locations)
180
+ target.const_get(name)
181
+ end
182
+
183
+ def method_missing(...)
184
+ @deprecator.warn(@message, caller_locations)
185
+ target.__send__(...)
186
+ end
187
+ end
188
+ end
189
+ end
@@ -0,0 +1,162 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rbconfig"
4
+
5
+ module ActiveSupport
6
+ class Deprecation
7
+ module Reporting
8
+ # Whether to print a message (silent mode)
9
+ attr_writer :silenced
10
+ # Name of gem where method is deprecated
11
+ attr_accessor :gem_name
12
+
13
+ # Outputs a deprecation warning to the output configured by
14
+ # ActiveSupport::Deprecation#behavior.
15
+ #
16
+ # ActiveSupport::Deprecation.new.warn('something broke!')
17
+ # # => "DEPRECATION WARNING: something broke! (called from your_code.rb:1)"
18
+ def warn(message = nil, callstack = nil)
19
+ return if silenced
20
+
21
+ callstack ||= caller_locations(2)
22
+ deprecation_message(callstack, message).tap do |full_message|
23
+ if deprecation_disallowed?(message)
24
+ disallowed_behavior.each { |b| b.call(full_message, callstack, self) }
25
+ else
26
+ behavior.each { |b| b.call(full_message, callstack, self) }
27
+ end
28
+ end
29
+ end
30
+
31
+ # Silence deprecation warnings within the block.
32
+ #
33
+ # deprecator = ActiveSupport::Deprecation.new
34
+ # deprecator.warn('something broke!')
35
+ # # => "DEPRECATION WARNING: something broke! (called from your_code.rb:1)"
36
+ #
37
+ # deprecator.silence do
38
+ # deprecator.warn('something broke!')
39
+ # end
40
+ # # => nil
41
+ def silence(&block)
42
+ begin_silence
43
+ block.call
44
+ ensure
45
+ end_silence
46
+ end
47
+
48
+ def begin_silence # :nodoc:
49
+ @silence_counter.value += 1
50
+ end
51
+
52
+ def end_silence # :nodoc:
53
+ @silence_counter.value -= 1
54
+ end
55
+
56
+ def silenced
57
+ @silenced || @silence_counter.value.nonzero?
58
+ end
59
+
60
+ # Allow previously disallowed deprecation warnings within the block.
61
+ # <tt>allowed_warnings</tt> can be an array containing strings, symbols, or regular
62
+ # expressions. (Symbols are treated as strings). These are compared against
63
+ # the text of deprecation warning messages generated within the block.
64
+ # Matching warnings will be exempt from the rules set by
65
+ # ActiveSupport::Deprecation#disallowed_warnings.
66
+ #
67
+ # The optional <tt>if:</tt> argument accepts a truthy/falsy value or an object that
68
+ # responds to <tt>.call</tt>. If truthy, then matching warnings will be allowed.
69
+ # If falsey then the method yields to the block without allowing the warning.
70
+ #
71
+ # deprecator = ActiveSupport::Deprecation.new
72
+ # deprecator.disallowed_behavior = :raise
73
+ # deprecator.disallowed_warnings = [
74
+ # "something broke"
75
+ # ]
76
+ #
77
+ # deprecator.warn('something broke!')
78
+ # # => ActiveSupport::DeprecationException
79
+ #
80
+ # deprecator.allow ['something broke'] do
81
+ # deprecator.warn('something broke!')
82
+ # end
83
+ # # => nil
84
+ #
85
+ # deprecator.allow ['something broke'], if: Rails.env.production? do
86
+ # deprecator.warn('something broke!')
87
+ # end
88
+ # # => ActiveSupport::DeprecationException for dev/test, nil for production
89
+ def allow(allowed_warnings = :all, if: true, &block)
90
+ conditional = binding.local_variable_get(:if)
91
+ conditional = conditional.call if conditional.respond_to?(:call)
92
+ if conditional
93
+ @explicitly_allowed_warnings.bind(allowed_warnings, &block)
94
+ else
95
+ yield
96
+ end
97
+ end
98
+
99
+ def deprecation_warning(deprecated_method_name, message = nil, caller_backtrace = nil)
100
+ caller_backtrace ||= caller_locations(2)
101
+ deprecated_method_warning(deprecated_method_name, message).tap do |msg|
102
+ warn(msg, caller_backtrace)
103
+ end
104
+ end
105
+
106
+ private
107
+ # Outputs a deprecation warning message
108
+ #
109
+ # deprecated_method_warning(:method_name)
110
+ # # => "method_name is deprecated and will be removed from Rails #{deprecation_horizon}"
111
+ # deprecated_method_warning(:method_name, :another_method)
112
+ # # => "method_name is deprecated and will be removed from Rails #{deprecation_horizon} (use another_method instead)"
113
+ # deprecated_method_warning(:method_name, "Optional message")
114
+ # # => "method_name is deprecated and will be removed from Rails #{deprecation_horizon} (Optional message)"
115
+ def deprecated_method_warning(method_name, message = nil)
116
+ warning = "#{method_name} is deprecated and will be removed from #{gem_name} #{deprecation_horizon}"
117
+ case message
118
+ when Symbol then "#{warning} (use #{message} instead)"
119
+ when String then "#{warning} (#{message})"
120
+ else warning
121
+ end
122
+ end
123
+
124
+ def deprecation_message(callstack, message = nil)
125
+ message ||= "You are using deprecated behavior which will be removed from the next major or minor release."
126
+ "DEPRECATION WARNING: #{message} #{deprecation_caller_message(callstack)}"
127
+ end
128
+
129
+ def deprecation_caller_message(callstack)
130
+ file, line, method = extract_callstack(callstack)
131
+ if file
132
+ if line && method
133
+ "(called from #{method} at #{file}:#{line})"
134
+ else
135
+ "(called from #{file}:#{line})"
136
+ end
137
+ end
138
+ end
139
+
140
+ def extract_callstack(callstack)
141
+ return [] if callstack.empty?
142
+
143
+ offending_line = callstack.find { |frame|
144
+ # Code generated with `eval` doesn't have an `absolute_path`, e.g. templates.
145
+ path = frame.absolute_path || frame.path
146
+ path && !ignored_callstack?(path)
147
+ } || callstack.first
148
+
149
+ [offending_line.path, offending_line.lineno, offending_line.label]
150
+ end
151
+
152
+ RAILS_GEM_ROOT = File.expand_path("../../../..", __dir__) + "/"
153
+ private_constant :RAILS_GEM_ROOT
154
+ LIB_DIR = RbConfig::CONFIG["libdir"]
155
+ private_constant :LIB_DIR
156
+
157
+ def ignored_callstack?(path)
158
+ path.start_with?(RAILS_GEM_ROOT, LIB_DIR) || path.include?("<internal:")
159
+ end
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,81 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveSupport
4
+ # = Active Support \Deprecation
5
+ #
6
+ # \Deprecation specifies the API used by \Rails to deprecate methods, instance variables, objects, and constants. It's
7
+ # also available for gems or applications.
8
+ #
9
+ # For a gem, use Deprecation.new to create a Deprecation object and store it in your module or class (in order for
10
+ # users to be able to configure it).
11
+ #
12
+ # module MyLibrary
13
+ # def self.deprecator
14
+ # @deprecator ||= ActiveSupport::Deprecation.new("2.0", "MyLibrary")
15
+ # end
16
+ # end
17
+ #
18
+ # For a Railtie or Engine, you may also want to add it to the application's deprecators, so that the application's
19
+ # configuration can be applied to it.
20
+ #
21
+ # module MyLibrary
22
+ # class Railtie < Rails::Railtie
23
+ # initializer "my_library.deprecator" do |app|
24
+ # app.deprecators[:my_library] = MyLibrary.deprecator
25
+ # end
26
+ # end
27
+ # end
28
+ #
29
+ # With the above initializer, configuration settings like the following will affect +MyLibrary.deprecator+:
30
+ #
31
+ # # in config/environments/test.rb
32
+ # config.active_support.deprecation = :raise
33
+ class Deprecation
34
+ # active_support.rb sets an autoload for ActiveSupport::Deprecation.
35
+ #
36
+ # If these requires were at the top of the file the constant would not be
37
+ # defined by the time their files were loaded. Since some of them reopen
38
+ # ActiveSupport::Deprecation its autoload would be triggered, resulting in
39
+ # a circular require warning for active_support/deprecation.rb.
40
+ #
41
+ # So, we define the constant first, and load dependencies later.
42
+ require "active_support/deprecation/behaviors"
43
+ require "active_support/deprecation/reporting"
44
+ require "active_support/deprecation/disallowed"
45
+ require "active_support/deprecation/constant_accessor"
46
+ require "active_support/deprecation/method_wrappers"
47
+ require "active_support/deprecation/proxy_wrappers"
48
+ require "active_support/deprecation/deprecators"
49
+ require "active_support/core_ext/module/deprecation"
50
+ require "concurrent/atomic/thread_local_var"
51
+
52
+ include Behavior
53
+ include Reporting
54
+ include Disallowed
55
+ include MethodWrapper
56
+
57
+ MUTEX = Mutex.new # :nodoc:
58
+ private_constant :MUTEX
59
+
60
+ def self._instance # :nodoc:
61
+ @_instance ||= MUTEX.synchronize { @_instance ||= new }
62
+ end
63
+
64
+ # The version number in which the deprecated behavior will be removed, by default.
65
+ attr_accessor :deprecation_horizon
66
+
67
+ # It accepts two parameters on initialization. The first is a version of library
68
+ # and the second is a library name.
69
+ #
70
+ # ActiveSupport::Deprecation.new('2.0', 'MyLibrary')
71
+ def initialize(deprecation_horizon = "8.2", gem_name = "Rails")
72
+ self.gem_name = gem_name
73
+ self.deprecation_horizon = deprecation_horizon
74
+ # By default, warnings are not silenced and debugging is off.
75
+ self.silenced = false
76
+ self.debug = false
77
+ @silence_counter = Concurrent::ThreadLocalVar.new(0)
78
+ @explicitly_allowed_warnings = Concurrent::ThreadLocalVar.new(nil)
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ActiveSupport
4
+ def self.deprecator # :nodoc:
5
+ ActiveSupport::Deprecation._instance
6
+ end
7
+ end