activesupport 4.0.12 → 7.0.2.4

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 (295) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +249 -501
  3. data/MIT-LICENSE +2 -2
  4. data/README.rdoc +10 -5
  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 +48 -0
  8. data/lib/active_support/backtrace_cleaner.rb +41 -13
  9. data/lib/active_support/benchmarkable.rb +7 -15
  10. data/lib/active_support/builder.rb +3 -1
  11. data/lib/active_support/cache/file_store.rb +96 -74
  12. data/lib/active_support/cache/mem_cache_store.rb +211 -103
  13. data/lib/active_support/cache/memory_store.rb +90 -58
  14. data/lib/active_support/cache/null_store.rb +19 -7
  15. data/lib/active_support/cache/redis_cache_store.rb +468 -0
  16. data/lib/active_support/cache/strategy/local_cache.rb +86 -83
  17. data/lib/active_support/cache/strategy/local_cache_middleware.rb +45 -0
  18. data/lib/active_support/cache.rb +580 -241
  19. data/lib/active_support/callbacks.rb +812 -425
  20. data/lib/active_support/code_generator.rb +65 -0
  21. data/lib/active_support/concern.rb +103 -14
  22. data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +33 -0
  23. data/lib/active_support/concurrency/share_lock.rb +226 -0
  24. data/lib/active_support/configurable.rb +21 -19
  25. data/lib/active_support/configuration_file.rb +51 -0
  26. data/lib/active_support/core_ext/array/access.rb +47 -1
  27. data/lib/active_support/core_ext/array/conversions.rb +35 -44
  28. data/lib/active_support/core_ext/array/deprecated_conversions.rb +25 -0
  29. data/lib/active_support/core_ext/array/extract.rb +21 -0
  30. data/lib/active_support/core_ext/array/extract_options.rb +2 -0
  31. data/lib/active_support/core_ext/array/grouping.rb +26 -16
  32. data/lib/active_support/core_ext/array/inquiry.rb +19 -0
  33. data/lib/active_support/core_ext/array/wrap.rb +7 -4
  34. data/lib/active_support/core_ext/array.rb +10 -7
  35. data/lib/active_support/core_ext/benchmark.rb +5 -3
  36. data/lib/active_support/core_ext/big_decimal/conversions.rb +9 -26
  37. data/lib/active_support/core_ext/big_decimal.rb +3 -1
  38. data/lib/active_support/core_ext/class/attribute.rb +52 -49
  39. data/lib/active_support/core_ext/class/attribute_accessors.rb +5 -169
  40. data/lib/active_support/core_ext/class/subclasses.rb +25 -26
  41. data/lib/active_support/core_ext/class.rb +4 -4
  42. data/lib/active_support/core_ext/date/acts_like.rb +3 -1
  43. data/lib/active_support/core_ext/date/blank.rb +14 -0
  44. data/lib/active_support/core_ext/date/calculations.rb +31 -18
  45. data/lib/active_support/core_ext/date/conversions.rb +43 -32
  46. data/lib/active_support/core_ext/date/deprecated_conversions.rb +26 -0
  47. data/lib/active_support/core_ext/date/zones.rb +5 -34
  48. data/lib/active_support/core_ext/date.rb +7 -4
  49. data/lib/active_support/core_ext/date_and_time/calculations.rb +198 -66
  50. data/lib/active_support/core_ext/date_and_time/compatibility.rb +31 -0
  51. data/lib/active_support/core_ext/date_and_time/zones.rb +40 -0
  52. data/lib/active_support/core_ext/date_time/acts_like.rb +4 -2
  53. data/lib/active_support/core_ext/date_time/blank.rb +14 -0
  54. data/lib/active_support/core_ext/date_time/calculations.rb +79 -38
  55. data/lib/active_support/core_ext/date_time/compatibility.rb +18 -0
  56. data/lib/active_support/core_ext/date_time/conversions.rb +31 -26
  57. data/lib/active_support/core_ext/date_time/deprecated_conversions.rb +22 -0
  58. data/lib/active_support/core_ext/date_time.rb +8 -4
  59. data/lib/active_support/core_ext/digest/uuid.rb +79 -0
  60. data/lib/active_support/core_ext/digest.rb +3 -0
  61. data/lib/active_support/core_ext/enumerable.rb +249 -17
  62. data/lib/active_support/core_ext/file/atomic.rb +41 -32
  63. data/lib/active_support/core_ext/file.rb +3 -1
  64. data/lib/active_support/core_ext/hash/conversions.rb +71 -49
  65. data/lib/active_support/core_ext/hash/deep_merge.rb +9 -13
  66. data/lib/active_support/core_ext/hash/deep_transform_values.rb +46 -0
  67. data/lib/active_support/core_ext/hash/except.rb +14 -5
  68. data/lib/active_support/core_ext/hash/indifferent_access.rb +5 -3
  69. data/lib/active_support/core_ext/hash/keys.rb +39 -56
  70. data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
  71. data/lib/active_support/core_ext/hash/slice.rb +8 -23
  72. data/lib/active_support/core_ext/hash.rb +10 -8
  73. data/lib/active_support/core_ext/integer/inflections.rb +3 -1
  74. data/lib/active_support/core_ext/integer/multiple.rb +3 -1
  75. data/lib/active_support/core_ext/integer/time.rb +11 -33
  76. data/lib/active_support/core_ext/integer.rb +5 -3
  77. data/lib/active_support/core_ext/kernel/concern.rb +14 -0
  78. data/lib/active_support/core_ext/kernel/reporting.rb +9 -78
  79. data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
  80. data/lib/active_support/core_ext/kernel.rb +5 -4
  81. data/lib/active_support/core_ext/load_error.rb +5 -21
  82. data/lib/active_support/core_ext/module/aliasing.rb +6 -44
  83. data/lib/active_support/core_ext/module/anonymous.rb +12 -1
  84. data/lib/active_support/core_ext/module/attr_internal.rb +8 -8
  85. data/lib/active_support/core_ext/module/attribute_accessors.rb +186 -44
  86. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +157 -0
  87. data/lib/active_support/core_ext/module/concerning.rb +140 -0
  88. data/lib/active_support/core_ext/module/delegation.rb +172 -45
  89. data/lib/active_support/core_ext/module/deprecation.rb +3 -3
  90. data/lib/active_support/core_ext/module/introspection.rb +23 -38
  91. data/lib/active_support/core_ext/module/redefine_method.rb +40 -0
  92. data/lib/active_support/core_ext/module/remove_method.rb +8 -3
  93. data/lib/active_support/core_ext/module.rb +13 -10
  94. data/lib/active_support/core_ext/name_error.rb +45 -4
  95. data/lib/active_support/core_ext/numeric/bytes.rb +22 -0
  96. data/lib/active_support/core_ext/numeric/conversions.rb +135 -127
  97. data/lib/active_support/core_ext/numeric/deprecated_conversions.rb +60 -0
  98. data/lib/active_support/core_ext/numeric/time.rb +37 -50
  99. data/lib/active_support/core_ext/numeric.rb +6 -3
  100. data/lib/active_support/core_ext/object/acts_like.rb +41 -6
  101. data/lib/active_support/core_ext/object/blank.rb +70 -20
  102. data/lib/active_support/core_ext/object/conversions.rb +6 -4
  103. data/lib/active_support/core_ext/object/deep_dup.rb +19 -10
  104. data/lib/active_support/core_ext/object/duplicable.rb +17 -47
  105. data/lib/active_support/core_ext/object/inclusion.rb +18 -15
  106. data/lib/active_support/core_ext/object/instance_variables.rb +3 -1
  107. data/lib/active_support/core_ext/object/json.rb +244 -0
  108. data/lib/active_support/core_ext/object/to_param.rb +3 -1
  109. data/lib/active_support/core_ext/object/to_query.rb +21 -8
  110. data/lib/active_support/core_ext/object/try.rb +106 -26
  111. data/lib/active_support/core_ext/object/with_options.rb +64 -5
  112. data/lib/active_support/core_ext/object.rb +14 -12
  113. data/lib/active_support/core_ext/pathname/existence.rb +21 -0
  114. data/lib/active_support/core_ext/pathname.rb +3 -0
  115. data/lib/active_support/core_ext/range/compare_range.rb +57 -0
  116. data/lib/active_support/core_ext/range/conversions.rb +37 -15
  117. data/lib/active_support/core_ext/range/deprecated_conversions.rb +26 -0
  118. data/lib/active_support/core_ext/range/each.rb +18 -17
  119. data/lib/active_support/core_ext/range/include_time_with_zone.rb +7 -0
  120. data/lib/active_support/core_ext/range/overlaps.rb +2 -0
  121. data/lib/active_support/core_ext/range.rb +7 -4
  122. data/lib/active_support/core_ext/regexp.rb +10 -1
  123. data/lib/active_support/core_ext/securerandom.rb +45 -0
  124. data/lib/active_support/core_ext/string/access.rb +42 -51
  125. data/lib/active_support/core_ext/string/behavior.rb +3 -1
  126. data/lib/active_support/core_ext/string/conversions.rb +18 -13
  127. data/lib/active_support/core_ext/string/exclude.rb +5 -3
  128. data/lib/active_support/core_ext/string/filters.rb +97 -7
  129. data/lib/active_support/core_ext/string/indent.rb +6 -4
  130. data/lib/active_support/core_ext/string/inflections.rb +106 -25
  131. data/lib/active_support/core_ext/string/inquiry.rb +4 -1
  132. data/lib/active_support/core_ext/string/multibyte.rb +18 -9
  133. data/lib/active_support/core_ext/string/output_safety.rb +227 -54
  134. data/lib/active_support/core_ext/string/starts_ends_with.rb +4 -2
  135. data/lib/active_support/core_ext/string/strip.rb +6 -5
  136. data/lib/active_support/core_ext/string/zones.rb +4 -1
  137. data/lib/active_support/core_ext/string.rb +15 -13
  138. data/lib/active_support/core_ext/symbol/starts_ends_with.rb +6 -0
  139. data/lib/active_support/core_ext/symbol.rb +3 -0
  140. data/lib/active_support/core_ext/time/acts_like.rb +3 -1
  141. data/lib/active_support/core_ext/time/calculations.rb +178 -116
  142. data/lib/active_support/core_ext/time/compatibility.rb +16 -0
  143. data/lib/active_support/core_ext/time/conversions.rb +37 -25
  144. data/lib/active_support/core_ext/time/deprecated_conversions.rb +22 -0
  145. data/lib/active_support/core_ext/time/zones.rb +44 -42
  146. data/lib/active_support/core_ext/time.rb +8 -5
  147. data/lib/active_support/core_ext/uri.rb +4 -25
  148. data/lib/active_support/core_ext.rb +4 -2
  149. data/lib/active_support/current_attributes/test_helper.rb +13 -0
  150. data/lib/active_support/current_attributes.rb +226 -0
  151. data/lib/active_support/dependencies/autoload.rb +3 -1
  152. data/lib/active_support/dependencies/interlock.rb +49 -0
  153. data/lib/active_support/dependencies/require_dependency.rb +28 -0
  154. data/lib/active_support/dependencies.rb +71 -696
  155. data/lib/active_support/deprecation/behaviors.rb +65 -16
  156. data/lib/active_support/deprecation/constant_accessor.rb +52 -0
  157. data/lib/active_support/deprecation/disallowed.rb +56 -0
  158. data/lib/active_support/deprecation/instance_delegator.rb +16 -2
  159. data/lib/active_support/deprecation/method_wrappers.rb +62 -21
  160. data/lib/active_support/deprecation/proxy_wrappers.rb +82 -31
  161. data/lib/active_support/deprecation/reporting.rb +81 -18
  162. data/lib/active_support/deprecation.rb +19 -11
  163. data/lib/active_support/descendants_tracker.rb +192 -34
  164. data/lib/active_support/digest.rb +22 -0
  165. data/lib/active_support/duration/iso8601_parser.rb +123 -0
  166. data/lib/active_support/duration/iso8601_serializer.rb +67 -0
  167. data/lib/active_support/duration.rb +437 -39
  168. data/lib/active_support/encrypted_configuration.rb +56 -0
  169. data/lib/active_support/encrypted_file.rb +117 -0
  170. data/lib/active_support/environment_inquirer.rb +20 -0
  171. data/lib/active_support/error_reporter.rb +117 -0
  172. data/lib/active_support/evented_file_update_checker.rb +170 -0
  173. data/lib/active_support/execution_context/test_helper.rb +13 -0
  174. data/lib/active_support/execution_context.rb +53 -0
  175. data/lib/active_support/execution_wrapper.rb +151 -0
  176. data/lib/active_support/executor/test_helper.rb +7 -0
  177. data/lib/active_support/executor.rb +8 -0
  178. data/lib/active_support/file_update_checker.rb +62 -37
  179. data/lib/active_support/fork_tracker.rb +71 -0
  180. data/lib/active_support/gem_version.rb +17 -0
  181. data/lib/active_support/gzip.rb +7 -5
  182. data/lib/active_support/hash_with_indifferent_access.rb +207 -54
  183. data/lib/active_support/html_safe_translation.rb +43 -0
  184. data/lib/active_support/i18n.rb +10 -6
  185. data/lib/active_support/i18n_railtie.rb +48 -19
  186. data/lib/active_support/inflections.rb +19 -12
  187. data/lib/active_support/inflector/inflections.rb +97 -37
  188. data/lib/active_support/inflector/methods.rb +192 -157
  189. data/lib/active_support/inflector/transliterate.rb +83 -33
  190. data/lib/active_support/inflector.rb +7 -5
  191. data/lib/active_support/isolated_execution_state.rb +64 -0
  192. data/lib/active_support/json/decoding.rb +37 -42
  193. data/lib/active_support/json/encoding.rb +93 -293
  194. data/lib/active_support/json.rb +4 -2
  195. data/lib/active_support/key_generator.rb +30 -47
  196. data/lib/active_support/lazy_load_hooks.rb +54 -21
  197. data/lib/active_support/locale/en.rb +33 -0
  198. data/lib/active_support/locale/en.yml +10 -4
  199. data/lib/active_support/log_subscriber/test_helper.rb +14 -12
  200. data/lib/active_support/log_subscriber.rb +61 -18
  201. data/lib/active_support/logger.rb +40 -4
  202. data/lib/active_support/logger_silence.rb +17 -20
  203. data/lib/active_support/logger_thread_safe_level.rb +69 -0
  204. data/lib/active_support/message_encryptor.rb +178 -55
  205. data/lib/active_support/message_verifier.rb +195 -26
  206. data/lib/active_support/messages/metadata.rb +80 -0
  207. data/lib/active_support/messages/rotation_configuration.rb +23 -0
  208. data/lib/active_support/messages/rotator.rb +57 -0
  209. data/lib/active_support/multibyte/chars.rb +45 -92
  210. data/lib/active_support/multibyte/unicode.rb +44 -377
  211. data/lib/active_support/multibyte.rb +5 -3
  212. data/lib/active_support/notifications/fanout.rb +177 -44
  213. data/lib/active_support/notifications/instrumenter.rb +117 -17
  214. data/lib/active_support/notifications.rb +106 -39
  215. data/lib/active_support/number_helper/number_converter.rb +181 -0
  216. data/lib/active_support/number_helper/number_to_currency_converter.rb +46 -0
  217. data/lib/active_support/number_helper/number_to_delimited_converter.rb +30 -0
  218. data/lib/active_support/number_helper/number_to_human_converter.rb +69 -0
  219. data/lib/active_support/number_helper/number_to_human_size_converter.rb +60 -0
  220. data/lib/active_support/number_helper/number_to_percentage_converter.rb +16 -0
  221. data/lib/active_support/number_helper/number_to_phone_converter.rb +59 -0
  222. data/lib/active_support/number_helper/number_to_rounded_converter.rb +59 -0
  223. data/lib/active_support/number_helper/rounding_helper.rb +46 -0
  224. data/lib/active_support/number_helper.rb +152 -394
  225. data/lib/active_support/option_merger.rb +18 -5
  226. data/lib/active_support/ordered_hash.rb +8 -6
  227. data/lib/active_support/ordered_options.rb +43 -7
  228. data/lib/active_support/parameter_filter.rb +138 -0
  229. data/lib/active_support/per_thread_registry.rb +24 -11
  230. data/lib/active_support/proxy_object.rb +2 -0
  231. data/lib/active_support/rails.rb +10 -11
  232. data/lib/active_support/railtie.rb +118 -12
  233. data/lib/active_support/reloader.rb +130 -0
  234. data/lib/active_support/rescuable.rb +112 -57
  235. data/lib/active_support/ruby_features.rb +7 -0
  236. data/lib/active_support/secure_compare_rotator.rb +51 -0
  237. data/lib/active_support/security_utils.rb +38 -0
  238. data/lib/active_support/string_inquirer.rb +11 -4
  239. data/lib/active_support/subscriber.rb +109 -39
  240. data/lib/active_support/tagged_logging.rb +54 -17
  241. data/lib/active_support/test_case.rb +121 -37
  242. data/lib/active_support/testing/assertions.rb +177 -39
  243. data/lib/active_support/testing/autorun.rb +5 -3
  244. data/lib/active_support/testing/constant_lookup.rb +3 -6
  245. data/lib/active_support/testing/declarative.rb +10 -22
  246. data/lib/active_support/testing/deprecation.rb +65 -11
  247. data/lib/active_support/testing/file_fixtures.rb +38 -0
  248. data/lib/active_support/testing/isolation.rb +56 -87
  249. data/lib/active_support/testing/method_call_assertions.rb +70 -0
  250. data/lib/active_support/testing/parallelization/server.rb +82 -0
  251. data/lib/active_support/testing/parallelization/worker.rb +103 -0
  252. data/lib/active_support/testing/parallelization.rb +55 -0
  253. data/lib/active_support/testing/parallelize_executor.rb +76 -0
  254. data/lib/active_support/testing/setup_and_teardown.rb +30 -10
  255. data/lib/active_support/testing/stream.rb +41 -0
  256. data/lib/active_support/testing/tagged_logging.rb +6 -4
  257. data/lib/active_support/testing/time_helpers.rb +246 -0
  258. data/lib/active_support/time.rb +13 -13
  259. data/lib/active_support/time_with_zone.rb +315 -90
  260. data/lib/active_support/values/time_zone.rb +306 -135
  261. data/lib/active_support/version.rb +6 -7
  262. data/lib/active_support/xml_mini/jdom.rb +117 -115
  263. data/lib/active_support/xml_mini/libxml.rb +22 -21
  264. data/lib/active_support/xml_mini/libxmlsax.rb +17 -19
  265. data/lib/active_support/xml_mini/nokogiri.rb +19 -19
  266. data/lib/active_support/xml_mini/nokogirisax.rb +16 -17
  267. data/lib/active_support/xml_mini/rexml.rb +25 -17
  268. data/lib/active_support/xml_mini.rb +67 -56
  269. data/lib/active_support.rb +58 -3
  270. metadata +125 -66
  271. data/lib/active_support/basic_object.rb +0 -11
  272. data/lib/active_support/buffered_logger.rb +0 -21
  273. data/lib/active_support/concurrency/latch.rb +0 -27
  274. data/lib/active_support/core_ext/array/prepend_and_append.rb +0 -7
  275. data/lib/active_support/core_ext/array/uniq_by.rb +0 -19
  276. data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -40
  277. data/lib/active_support/core_ext/date_time/zones.rb +0 -24
  278. data/lib/active_support/core_ext/hash/diff.rb +0 -14
  279. data/lib/active_support/core_ext/kernel/agnostics.rb +0 -11
  280. data/lib/active_support/core_ext/kernel/debugger.rb +0 -10
  281. data/lib/active_support/core_ext/logger.rb +0 -67
  282. data/lib/active_support/core_ext/marshal.rb +0 -21
  283. data/lib/active_support/core_ext/module/qualified_const.rb +0 -52
  284. data/lib/active_support/core_ext/module/reachable.rb +0 -8
  285. data/lib/active_support/core_ext/object/to_json.rb +0 -27
  286. data/lib/active_support/core_ext/proc.rb +0 -17
  287. data/lib/active_support/core_ext/range/include_range.rb +0 -23
  288. data/lib/active_support/core_ext/string/encoding.rb +0 -8
  289. data/lib/active_support/core_ext/struct.rb +0 -6
  290. data/lib/active_support/core_ext/thread.rb +0 -79
  291. data/lib/active_support/core_ext/time/marshal.rb +0 -30
  292. data/lib/active_support/file_watcher.rb +0 -36
  293. data/lib/active_support/json/variable.rb +0 -18
  294. data/lib/active_support/testing/pending.rb +0 -14
  295. data/lib/active_support/values/unicode_tables.dat +0 -0
@@ -1,9 +1,11 @@
1
- require 'active_support/core_ext/hash/deep_merge'
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/hash/deep_merge"
2
4
 
3
5
  module ActiveSupport
4
- class OptionMerger #:nodoc:
6
+ class OptionMerger # :nodoc:
5
7
  instance_methods.each do |method|
6
- undef_method(method) if method !~ /^(__|instance_eval|class|object_id)/
8
+ undef_method(method) unless method.start_with?("__", "instance_eval", "class", "object_id")
7
9
  end
8
10
 
9
11
  def initialize(context, options)
@@ -12,14 +14,25 @@ module ActiveSupport
12
14
 
13
15
  private
14
16
  def method_missing(method, *arguments, &block)
17
+ options = nil
15
18
  if arguments.first.is_a?(Proc)
16
19
  proc = arguments.pop
17
20
  arguments << lambda { |*args| @options.deep_merge(proc.call(*args)) }
21
+ elsif arguments.last.respond_to?(:to_hash)
22
+ options = @options.deep_merge(arguments.pop)
18
23
  else
19
- arguments << (arguments.last.respond_to?(:to_hash) ? @options.deep_merge(arguments.pop) : @options.dup)
24
+ options = @options
20
25
  end
21
26
 
22
- @context.__send__(method, *arguments, &block)
27
+ if options
28
+ @context.__send__(method, *arguments, **options, &block)
29
+ else
30
+ @context.__send__(method, *arguments, &block)
31
+ end
32
+ end
33
+
34
+ def respond_to_missing?(*arguments)
35
+ @context.respond_to?(*arguments)
23
36
  end
24
37
  end
25
38
  end
@@ -1,11 +1,13 @@
1
- require 'yaml'
1
+ # frozen_string_literal: true
2
+
3
+ require "yaml"
2
4
 
3
5
  YAML.add_builtin_type("omap") do |type, val|
4
- ActiveSupport::OrderedHash[val.map{ |v| v.to_a.first }]
6
+ ActiveSupport::OrderedHash[val.map { |v| v.to_a.first }]
5
7
  end
6
8
 
7
9
  module ActiveSupport
8
- # <tt>ActiveSupport::OrderedHash</tt> implements a hash that preserves
10
+ # DEPRECATED: <tt>ActiveSupport::OrderedHash</tt> implements a hash that preserves
9
11
  # insertion order.
10
12
  #
11
13
  # oh = ActiveSupport::OrderedHash.new
@@ -14,18 +16,18 @@ module ActiveSupport
14
16
  # oh.keys # => [:a, :b], this order is guaranteed
15
17
  #
16
18
  # Also, maps the +omap+ feature for YAML files
17
- # (See http://yaml.org/type/omap.html) to support ordered items
19
+ # (See https://yaml.org/type/omap.html) to support ordered items
18
20
  # when loading from yaml.
19
21
  #
20
22
  # <tt>ActiveSupport::OrderedHash</tt> is namespaced to prevent conflicts
21
23
  # with other implementations.
22
- class OrderedHash < ::Hash
24
+ class OrderedHash < ::Hash # :nodoc:
23
25
  def to_yaml_type
24
26
  "!tag:yaml.org,2002:omap"
25
27
  end
26
28
 
27
29
  def encode_with(coder)
28
- coder.represent_seq '!omap', map { |k,v| { k => v } }
30
+ coder.represent_seq "!omap", map { |k, v| { k => v } }
29
31
  end
30
32
 
31
33
  def select(*args, &block)
@@ -1,19 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/object/blank"
4
+
1
5
  module ActiveSupport
2
- # Usually key value pairs are handled something like this:
6
+ # +OrderedOptions+ inherits from +Hash+ and provides dynamic accessor methods.
7
+ #
8
+ # With a +Hash+, key-value pairs are typically managed like this:
3
9
  #
4
10
  # h = {}
5
11
  # h[:boy] = 'John'
6
12
  # h[:girl] = 'Mary'
7
13
  # h[:boy] # => 'John'
8
14
  # h[:girl] # => 'Mary'
15
+ # h[:dog] # => nil
9
16
  #
10
- # Using +OrderedOptions+, the above code could be reduced to:
17
+ # Using +OrderedOptions+, the above code can be written as:
11
18
  #
12
19
  # h = ActiveSupport::OrderedOptions.new
13
20
  # h.boy = 'John'
14
21
  # h.girl = 'Mary'
15
22
  # h.boy # => 'John'
16
23
  # h.girl # => 'Mary'
24
+ # h.dog # => nil
25
+ #
26
+ # To raise an exception when the value is blank, append a
27
+ # bang to the key name, like:
28
+ #
29
+ # h.dog! # => raises KeyError: :dog is blank
30
+ #
17
31
  class OrderedOptions < Hash
18
32
  alias_method :_get, :[] # preserve the original #[] method
19
33
  protected :_get # make it protected
@@ -27,26 +41,48 @@ module ActiveSupport
27
41
  end
28
42
 
29
43
  def method_missing(name, *args)
30
- name_string = name.to_s
31
- if name_string.chomp!('=')
44
+ name_string = +name.to_s
45
+ if name_string.chomp!("=")
32
46
  self[name_string] = args.first
33
47
  else
34
- self[name]
48
+ bangs = name_string.chomp!("!")
49
+
50
+ if bangs
51
+ self[name_string].presence || raise(KeyError.new(":#{name_string} is blank"))
52
+ else
53
+ self[name_string]
54
+ end
35
55
  end
36
56
  end
37
57
 
38
58
  def respond_to_missing?(name, include_private)
39
59
  true
40
60
  end
61
+
62
+ def extractable_options?
63
+ true
64
+ end
65
+
66
+ def inspect
67
+ "#<#{self.class.name} #{super}>"
68
+ end
41
69
  end
42
70
 
71
+ # +InheritableOptions+ provides a constructor to build an +OrderedOptions+
72
+ # hash inherited from another hash.
73
+ #
74
+ # Use this if you already have some hash and you want to create a new one based on it.
75
+ #
76
+ # h = ActiveSupport::InheritableOptions.new({ girl: 'Mary', boy: 'John' })
77
+ # h.girl # => 'Mary'
78
+ # h.boy # => 'John'
43
79
  class InheritableOptions < OrderedOptions
44
80
  def initialize(parent = nil)
45
81
  if parent.kind_of?(OrderedOptions)
46
82
  # use the faster _get when dealing with OrderedOptions
47
- super() { |h,k| parent._get(k) }
83
+ super() { |h, k| parent._get(k) }
48
84
  elsif parent
49
- super() { |h,k| parent[k] }
85
+ super() { |h, k| parent[k] }
50
86
  else
51
87
  super()
52
88
  end
@@ -0,0 +1,138 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/object/duplicable"
4
+
5
+ module ActiveSupport
6
+ # +ParameterFilter+ allows you to specify keys for sensitive data from
7
+ # hash-like object and replace corresponding value. Filtering only certain
8
+ # sub-keys from a hash is possible by using the dot notation:
9
+ # 'credit_card.number'. If a proc is given, each key and value of a hash and
10
+ # all sub-hashes are passed to it, where the value or the key can be replaced
11
+ # using String#replace or similar methods.
12
+ #
13
+ # ActiveSupport::ParameterFilter.new([:password])
14
+ # => replaces the value to all keys matching /password/i with "[FILTERED]"
15
+ #
16
+ # ActiveSupport::ParameterFilter.new([:foo, "bar"])
17
+ # => replaces the value to all keys matching /foo|bar/i with "[FILTERED]"
18
+ #
19
+ # ActiveSupport::ParameterFilter.new([/\Apin\z/i, /\Apin_/i])
20
+ # => replaces the value for the exact (case-insensitive) key 'pin' and all
21
+ # (case-insensitive) keys beginning with 'pin_', with "[FILTERED]".
22
+ # Does not match keys with 'pin' as a substring, such as 'shipping_id'.
23
+ #
24
+ # ActiveSupport::ParameterFilter.new(["credit_card.code"])
25
+ # => replaces { credit_card: {code: "xxxx"} } with "[FILTERED]", does not
26
+ # change { file: { code: "xxxx"} }
27
+ #
28
+ # ActiveSupport::ParameterFilter.new([-> (k, v) do
29
+ # v.reverse! if /secret/i.match?(k)
30
+ # end])
31
+ # => reverses the value to all keys matching /secret/i
32
+ class ParameterFilter
33
+ FILTERED = "[FILTERED]" # :nodoc:
34
+
35
+ # Create instance with given filters. Supported type of filters are +String+, +Regexp+, and +Proc+.
36
+ # Other types of filters are treated as +String+ using +to_s+.
37
+ # For +Proc+ filters, key, value, and optional original hash is passed to block arguments.
38
+ #
39
+ # ==== Options
40
+ #
41
+ # * <tt>:mask</tt> - A replaced object when filtered. Defaults to <tt>"[FILTERED]"</tt>.
42
+ def initialize(filters = [], mask: FILTERED)
43
+ @filters = filters
44
+ @mask = mask
45
+ end
46
+
47
+ # Mask value of +params+ if key matches one of filters.
48
+ def filter(params)
49
+ compiled_filter.call(params)
50
+ end
51
+
52
+ # Returns filtered value for given key. For +Proc+ filters, third block argument is not populated.
53
+ def filter_param(key, value)
54
+ @filters.empty? ? value : compiled_filter.value_for_key(key, value)
55
+ end
56
+
57
+ private
58
+ def compiled_filter
59
+ @compiled_filter ||= CompiledFilter.compile(@filters, mask: @mask)
60
+ end
61
+
62
+ class CompiledFilter # :nodoc:
63
+ def self.compile(filters, mask:)
64
+ return lambda { |params| params.dup } if filters.empty?
65
+
66
+ strings, regexps, blocks, deep_regexps, deep_strings = [], [], [], nil, nil
67
+
68
+ filters.each do |item|
69
+ case item
70
+ when Proc
71
+ blocks << item
72
+ when Regexp
73
+ if item.to_s.include?("\\.")
74
+ (deep_regexps ||= []) << item
75
+ else
76
+ regexps << item
77
+ end
78
+ else
79
+ s = Regexp.escape(item.to_s)
80
+ if s.include?("\\.")
81
+ (deep_strings ||= []) << s
82
+ else
83
+ strings << s
84
+ end
85
+ end
86
+ end
87
+
88
+ regexps << Regexp.new(strings.join("|"), true) unless strings.empty?
89
+ (deep_regexps ||= []) << Regexp.new(deep_strings.join("|"), true) if deep_strings&.any?
90
+
91
+ new regexps, deep_regexps, blocks, mask: mask
92
+ end
93
+
94
+ attr_reader :regexps, :deep_regexps, :blocks
95
+
96
+ def initialize(regexps, deep_regexps, blocks, mask:)
97
+ @regexps = regexps
98
+ @deep_regexps = deep_regexps&.any? ? deep_regexps : nil
99
+ @blocks = blocks
100
+ @mask = mask
101
+ end
102
+
103
+ def call(params, parents = [], original_params = params)
104
+ filtered_params = params.class.new
105
+
106
+ params.each do |key, value|
107
+ filtered_params[key] = value_for_key(key, value, parents, original_params)
108
+ end
109
+
110
+ filtered_params
111
+ end
112
+
113
+ def value_for_key(key, value, parents = [], original_params = nil)
114
+ parents.push(key) if deep_regexps
115
+ if regexps.any? { |r| r.match?(key.to_s) }
116
+ value = @mask
117
+ elsif deep_regexps && (joined = parents.join(".")) && deep_regexps.any? { |r| r.match?(joined) }
118
+ value = @mask
119
+ elsif value.is_a?(Hash)
120
+ value = call(value, parents, original_params)
121
+ elsif value.is_a?(Array)
122
+ # If we don't pop the current parent it will be duplicated as we
123
+ # process each array value.
124
+ parents.pop if deep_regexps
125
+ value = value.map { |v| value_for_key(key, v, parents, original_params) }
126
+ # Restore the parent stack after processing the array.
127
+ parents.push(key) if deep_regexps
128
+ elsif blocks.any?
129
+ key = key.dup if key.duplicable?
130
+ value = value.dup if value.duplicable?
131
+ blocks.each { |b| b.arity == 2 ? b.call(key, value) : b.call(key, value, original_params) }
132
+ end
133
+ parents.pop if deep_regexps
134
+ value
135
+ end
136
+ end
137
+ end
138
+ end
@@ -1,4 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/module/delegation"
4
+
1
5
  module ActiveSupport
6
+ # NOTE: This approach has been deprecated for end-user code in favor of {thread_mattr_accessor}[rdoc-ref:Module#thread_mattr_accessor] and friends.
7
+ # Please use that approach instead.
8
+ #
2
9
  # This module is used to encapsulate access to thread local variables.
3
10
  #
4
11
  # Instead of polluting the thread locals namespace:
@@ -32,21 +39,27 @@ module ActiveSupport
32
39
  #
33
40
  # If the class has an initializer, it must accept no arguments.
34
41
  module PerThreadRegistry
35
- protected
42
+ def self.extended(object)
43
+ ActiveSupport::Deprecation.warn(<<~MSG)
44
+ ActiveSupport::PerThreadRegistry is deprecated and will be removed in Rails 7.1.
45
+ Use `Module#thread_mattr_accessor` instead.
46
+ MSG
47
+ object.instance_variable_set :@per_thread_registry_key, object.name.freeze
48
+ end
36
49
 
37
- def method_missing(name, *args, &block) # :nodoc:
38
- # Caches the method definition as a singleton method of the receiver.
39
- define_singleton_method(name) do |*a, &b|
40
- per_thread_registry_instance.public_send(name, *a, &b)
41
- end
42
-
43
- send(name, *args, &block)
44
- end
50
+ def instance
51
+ Thread.current[@per_thread_registry_key] ||= new
52
+ end
45
53
 
46
54
  private
55
+ def method_missing(name, *args, &block)
56
+ # Caches the method definition as a singleton method of the receiver.
57
+ #
58
+ # By letting #delegate handle it, we avoid an enclosure that'll capture args.
59
+ singleton_class.delegate name, to: :instance
47
60
 
48
- def per_thread_registry_instance
49
- Thread.current[name] ||= new
61
+ send(name, *args, &block)
50
62
  end
63
+ ruby2_keywords(:method_missing)
51
64
  end
52
65
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveSupport
2
4
  # A class with no predefined methods that behaves similarly to Builder's
3
5
  # BlankSlate. Used for proxy classes.
@@ -1,27 +1,26 @@
1
- # This is private interface.
1
+ # frozen_string_literal: true
2
+
3
+ # This is a private interface.
2
4
  #
3
5
  # Rails components cherry pick from Active Support as needed, but there are a
4
- # few features that are used for sure some way or another and it is not worth
5
- # to put individual requires absolutely everywhere. Think blank? for example.
6
+ # few features that are used for sure in some way or another and it is not worth
7
+ # putting individual requires absolutely everywhere. Think blank? for example.
6
8
  #
7
9
  # This file is loaded by every Rails component except Active Support itself,
8
10
  # but it does not belong to the Rails public interface. It is internal to
9
11
  # Rails and can change anytime.
10
12
 
11
13
  # Defines Object#blank? and Object#present?.
12
- require 'active_support/core_ext/object/blank'
13
-
14
- # Rails own autoload, eager_load, etc.
15
- require 'active_support/dependencies/autoload'
14
+ require "active_support/core_ext/object/blank"
16
15
 
17
16
  # Support for ClassMethods and the included macro.
18
- require 'active_support/concern'
17
+ require "active_support/concern"
19
18
 
20
19
  # Defines Class#class_attribute.
21
- require 'active_support/core_ext/class/attribute'
20
+ require "active_support/core_ext/class/attribute"
22
21
 
23
22
  # Defines Module#delegate.
24
- require 'active_support/core_ext/module/delegation'
23
+ require "active_support/core_ext/module/delegation"
25
24
 
26
25
  # Defines ActiveSupport::Deprecation.
27
- require 'active_support/deprecation'
26
+ require "active_support/deprecation"
@@ -1,45 +1,151 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support"
2
4
  require "active_support/i18n_railtie"
3
5
 
4
6
  module ActiveSupport
5
7
  class Railtie < Rails::Railtie # :nodoc:
6
8
  config.active_support = ActiveSupport::OrderedOptions.new
9
+ config.active_support.disable_to_s_conversion = false
7
10
 
8
11
  config.eager_load_namespaces << ActiveSupport
9
12
 
13
+ initializer "active_support.isolation_level" do |app|
14
+ if level = app.config.active_support.delete(:isolation_level)
15
+ ActiveSupport::IsolatedExecutionState.isolation_level = level
16
+ end
17
+ end
18
+
19
+ initializer "active_support.remove_deprecated_time_with_zone_name" do |app|
20
+ config.after_initialize do
21
+ if app.config.active_support.remove_deprecated_time_with_zone_name
22
+ require "active_support/time_with_zone"
23
+ TimeWithZone.singleton_class.remove_method(:name)
24
+ end
25
+ end
26
+ end
27
+
28
+ initializer "active_support.set_authenticated_message_encryption" do |app|
29
+ config.after_initialize do
30
+ unless app.config.active_support.use_authenticated_message_encryption.nil?
31
+ ActiveSupport::MessageEncryptor.use_authenticated_message_encryption =
32
+ app.config.active_support.use_authenticated_message_encryption
33
+ end
34
+ end
35
+ end
36
+
37
+ initializer "active_support.reset_execution_context" do |app|
38
+ app.reloader.before_class_unload { ActiveSupport::ExecutionContext.clear }
39
+ app.executor.to_run { ActiveSupport::ExecutionContext.clear }
40
+ app.executor.to_complete { ActiveSupport::ExecutionContext.clear }
41
+ end
42
+
43
+ initializer "active_support.reset_all_current_attributes_instances" do |app|
44
+ executor_around_test_case = app.config.active_support.executor_around_test_case
45
+
46
+ app.reloader.before_class_unload { ActiveSupport::CurrentAttributes.clear_all }
47
+ app.executor.to_run { ActiveSupport::CurrentAttributes.reset_all }
48
+ app.executor.to_complete { ActiveSupport::CurrentAttributes.reset_all }
49
+
50
+ ActiveSupport.on_load(:active_support_test_case) do
51
+ if executor_around_test_case
52
+ require "active_support/executor/test_helper"
53
+ include ActiveSupport::Executor::TestHelper
54
+ else
55
+ require "active_support/current_attributes/test_helper"
56
+ include ActiveSupport::CurrentAttributes::TestHelper
57
+
58
+ require "active_support/execution_context/test_helper"
59
+ include ActiveSupport::ExecutionContext::TestHelper
60
+ end
61
+ end
62
+ end
63
+
10
64
  initializer "active_support.deprecation_behavior" do |app|
11
- if deprecation = app.config.active_support.deprecation
12
- ActiveSupport::Deprecation.behavior = deprecation
65
+ if app.config.active_support.report_deprecations == false
66
+ ActiveSupport::Deprecation.silenced = true
67
+ ActiveSupport::Deprecation.behavior = :silence
68
+ ActiveSupport::Deprecation.disallowed_behavior = :silence
69
+ else
70
+ if deprecation = app.config.active_support.deprecation
71
+ ActiveSupport::Deprecation.behavior = deprecation
72
+ end
73
+
74
+ if disallowed_deprecation = app.config.active_support.disallowed_deprecation
75
+ ActiveSupport::Deprecation.disallowed_behavior = disallowed_deprecation
76
+ end
77
+
78
+ if disallowed_warnings = app.config.active_support.disallowed_deprecation_warnings
79
+ ActiveSupport::Deprecation.disallowed_warnings = disallowed_warnings
80
+ end
13
81
  end
14
82
  end
15
83
 
16
84
  # Sets the default value for Time.zone
17
85
  # If assigned value cannot be matched to a TimeZone, an exception will be raised.
18
86
  initializer "active_support.initialize_time_zone" do |app|
19
- require 'active_support/core_ext/time/zones'
20
- zone_default = Time.find_zone!(app.config.time_zone)
21
-
22
- unless zone_default
23
- raise 'Value assigned to config.time_zone not recognized. ' \
24
- 'Run "rake -D time" for a list of tasks for finding appropriate time zone names.'
87
+ begin
88
+ TZInfo::DataSource.get
89
+ rescue TZInfo::DataSourceNotFound => e
90
+ raise e.exception "tzinfo-data is not present. Please add gem 'tzinfo-data' to your Gemfile and run bundle install"
25
91
  end
26
-
27
- Time.zone_default = zone_default
92
+ require "active_support/core_ext/time/zones"
93
+ Time.zone_default = Time.find_zone!(app.config.time_zone)
28
94
  end
29
95
 
30
96
  # Sets the default week start
31
97
  # If assigned value is not a valid day symbol (e.g. :sunday, :monday, ...), an exception will be raised.
32
98
  initializer "active_support.initialize_beginning_of_week" do |app|
33
- require 'active_support/core_ext/date/calculations'
99
+ require "active_support/core_ext/date/calculations"
34
100
  beginning_of_week_default = Date.find_beginning_of_week!(app.config.beginning_of_week)
35
101
 
36
102
  Date.beginning_of_week_default = beginning_of_week_default
37
103
  end
38
104
 
105
+ initializer "active_support.require_master_key" do |app|
106
+ if app.config.respond_to?(:require_master_key) && app.config.require_master_key
107
+ begin
108
+ app.credentials.key
109
+ rescue ActiveSupport::EncryptedFile::MissingKeyError => error
110
+ $stderr.puts error.message
111
+ exit 1
112
+ end
113
+ end
114
+ end
115
+
116
+ initializer "active_support.set_error_reporter" do |app|
117
+ ActiveSupport.error_reporter = app.executor.error_reporter
118
+ end
119
+
39
120
  initializer "active_support.set_configs" do |app|
40
121
  app.config.active_support.each do |k, v|
41
122
  k = "#{k}="
42
- ActiveSupport.send(k, v) if ActiveSupport.respond_to? k
123
+ ActiveSupport.public_send(k, v) if ActiveSupport.respond_to? k
124
+ end
125
+ end
126
+
127
+ initializer "active_support.set_hash_digest_class" do |app|
128
+ config.after_initialize do
129
+ if klass = app.config.active_support.hash_digest_class
130
+ ActiveSupport::Digest.hash_digest_class = klass
131
+ end
132
+ end
133
+ end
134
+
135
+ initializer "active_support.set_key_generator_hash_digest_class" do |app|
136
+ config.after_initialize do
137
+ if klass = app.config.active_support.key_generator_hash_digest_class
138
+ ActiveSupport::KeyGenerator.hash_digest_class = klass
139
+ end
140
+ end
141
+ end
142
+
143
+ initializer "active_support.set_rfc4122_namespaced_uuids" do |app|
144
+ config.after_initialize do
145
+ if app.config.active_support.use_rfc4122_namespaced_uuids
146
+ require "active_support/core_ext/digest"
147
+ ::Digest::UUID.use_rfc4122_namespaced_uuids = app.config.active_support.use_rfc4122_namespaced_uuids
148
+ end
43
149
  end
44
150
  end
45
151
  end