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
@@ -1,31 +1,147 @@
1
- class OrderedOptions < Array #:nodoc:
2
- def []=(key, value)
3
- key = key.to_sym
4
-
5
- if pair = find_pair(key)
6
- pair.pop
7
- pair << value
8
- else
9
- self << [key, value]
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/object/blank"
4
+
5
+ module ActiveSupport
6
+ # = Ordered Options
7
+ #
8
+ # +OrderedOptions+ inherits from +Hash+ and provides dynamic accessor methods.
9
+ #
10
+ # With a +Hash+, key-value pairs are typically managed like this:
11
+ #
12
+ # h = {}
13
+ # h[:boy] = 'John'
14
+ # h[:girl] = 'Mary'
15
+ # h[:boy] # => 'John'
16
+ # h[:girl] # => 'Mary'
17
+ # h[:dog] # => nil
18
+ #
19
+ # Using +OrderedOptions+, the above code can be written as:
20
+ #
21
+ # h = ActiveSupport::OrderedOptions.new
22
+ # h.boy = 'John'
23
+ # h.girl = 'Mary'
24
+ # h.boy # => 'John'
25
+ # h.girl # => 'Mary'
26
+ # h.dog # => nil
27
+ #
28
+ # To raise an exception when the value is blank, append a
29
+ # bang to the key name, like:
30
+ #
31
+ # h.dog! # => raises KeyError: :dog is blank
32
+ #
33
+ class OrderedOptions < Hash
34
+ alias_method :_get, :[] # preserve the original #[] method
35
+ protected :_get # make it protected
36
+
37
+ def []=(key, value)
38
+ super(key.to_sym, value)
10
39
  end
11
- end
12
-
13
- def [](key)
14
- pair = find_pair(key.to_sym)
15
- pair ? pair.last : nil
16
- end
17
40
 
18
- def method_missing(name, *args)
19
- if name.to_s =~ /(.*)=$/
20
- self[$1.to_sym] = args.first
21
- else
22
- self[name]
41
+ def [](key)
42
+ super(key.to_sym)
43
+ end
44
+
45
+ def dig(key, *identifiers)
46
+ super(key.to_sym, *identifiers)
47
+ end
48
+
49
+ def method_missing(method, *args)
50
+ if method.end_with?("=")
51
+ self[method.name.chomp("=")] = args.first
52
+ elsif method.end_with?("!")
53
+ name_string = method.name.chomp("!")
54
+ self[name_string].presence || raise(KeyError.new(":#{name_string} is blank"))
55
+ else
56
+ self[method.name]
57
+ end
58
+ end
59
+
60
+ def respond_to_missing?(name, include_private)
61
+ true
62
+ end
63
+
64
+ def extractable_options?
65
+ true
66
+ end
67
+
68
+ def inspect
69
+ "#<#{self.class.name} #{super}>"
23
70
  end
24
71
  end
25
72
 
26
- private
27
- def find_pair(key)
28
- self.each { |i| return i if i.first == key }
29
- return false
73
+ # = Inheritable Options
74
+ #
75
+ # +InheritableOptions+ provides a constructor to build an OrderedOptions
76
+ # hash inherited from another hash.
77
+ #
78
+ # Use this if you already have some hash and you want to create a new one based on it.
79
+ #
80
+ # h = ActiveSupport::InheritableOptions.new({ girl: 'Mary', boy: 'John' })
81
+ # h.girl # => 'Mary'
82
+ # h.boy # => 'John'
83
+ #
84
+ # If the existing hash has string keys, call Hash#symbolize_keys on it.
85
+ #
86
+ # h = ActiveSupport::InheritableOptions.new({ 'girl' => 'Mary', 'boy' => 'John' }.symbolize_keys)
87
+ # h.girl # => 'Mary'
88
+ # h.boy # => 'John'
89
+ class InheritableOptions < OrderedOptions
90
+ def initialize(parent = nil)
91
+ @parent = parent
92
+ if @parent.kind_of?(OrderedOptions)
93
+ # use the faster _get when dealing with OrderedOptions
94
+ super() { |h, k| @parent._get(k) }
95
+ elsif @parent
96
+ super() { |h, k| @parent[k] }
97
+ else
98
+ super()
99
+ @parent = {}
100
+ end
101
+ end
102
+
103
+ def to_h
104
+ @parent.merge(self)
105
+ end
106
+
107
+ def ==(other)
108
+ to_h == other.to_h
30
109
  end
31
- end
110
+
111
+ def inspect
112
+ "#<#{self.class.name} #{to_h.inspect}>"
113
+ end
114
+
115
+ def to_s
116
+ to_h.to_s
117
+ end
118
+
119
+ def pretty_print(pp)
120
+ pp.pp_hash(to_h)
121
+ end
122
+
123
+ alias_method :own_key?, :key?
124
+ private :own_key?
125
+
126
+ def key?(key)
127
+ super || @parent.key?(key)
128
+ end
129
+
130
+ def overridden?(key)
131
+ !!(@parent && @parent.key?(key) && own_key?(key.to_sym))
132
+ end
133
+
134
+ def inheritable_copy
135
+ self.class.new(self)
136
+ end
137
+
138
+ def to_a
139
+ entries
140
+ end
141
+
142
+ def each(&block)
143
+ to_h.each(&block)
144
+ self
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,157 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/object/duplicable"
4
+ require "active_support/core_ext/array/extract"
5
+
6
+ module ActiveSupport
7
+ # = Active Support Parameter Filter
8
+ #
9
+ # +ParameterFilter+ replaces values in a <tt>Hash</tt>-like object if their
10
+ # keys match one of the specified filters.
11
+ #
12
+ # Matching based on nested keys is possible by using dot notation, e.g.
13
+ # <tt>"credit_card.number"</tt>.
14
+ #
15
+ # If a proc is given as a filter, each key and value of the <tt>Hash</tt>-like
16
+ # and of any nested <tt>Hash</tt>es will be passed to it. The value or key can
17
+ # then be mutated as desired using methods such as <tt>String#replace</tt>.
18
+ #
19
+ # # Replaces values with "[FILTERED]" for keys that match /password/i.
20
+ # ActiveSupport::ParameterFilter.new([:password])
21
+ #
22
+ # # Replaces values with "[FILTERED]" for keys that match /foo|bar/i.
23
+ # ActiveSupport::ParameterFilter.new([:foo, "bar"])
24
+ #
25
+ # # Replaces values for the exact key "pin" and for keys that begin with
26
+ # # "pin_". Does not match keys that otherwise include "pin" as a
27
+ # # substring, such as "shipping_id".
28
+ # ActiveSupport::ParameterFilter.new([/\Apin\z/, /\Apin_/])
29
+ #
30
+ # # Replaces the value for :code in `{ credit_card: { code: "xxxx" } }`.
31
+ # # Does not change `{ file: { code: "xxxx" } }`.
32
+ # ActiveSupport::ParameterFilter.new(["credit_card.code"])
33
+ #
34
+ # # Reverses values for keys that match /secret/i.
35
+ # ActiveSupport::ParameterFilter.new([-> (k, v) do
36
+ # v.reverse! if /secret/i.match?(k)
37
+ # end])
38
+ #
39
+ class ParameterFilter
40
+ FILTERED = "[FILTERED]" # :nodoc:
41
+
42
+ # Precompiles an array of filters that otherwise would be passed directly to
43
+ # #initialize. Depending on the quantity and types of filters,
44
+ # precompilation can improve filtering performance, especially in the case
45
+ # where the ParameterFilter instance itself cannot be retained (but the
46
+ # precompiled filters can be retained).
47
+ #
48
+ # filters = [/foo/, :bar, "nested.baz", /nested\.qux/]
49
+ #
50
+ # precompiled = ActiveSupport::ParameterFilter.precompile_filters(filters)
51
+ # # => [/(?-mix:foo)|(?i:bar)/, /(?i:nested\.baz)|(?-mix:nested\.qux)/]
52
+ #
53
+ # ActiveSupport::ParameterFilter.new(precompiled)
54
+ #
55
+ def self.precompile_filters(filters)
56
+ filters, patterns = filters.partition { |filter| filter.is_a?(Proc) }
57
+
58
+ patterns.map! do |pattern|
59
+ pattern.is_a?(Regexp) ? pattern : "(?i:#{Regexp.escape pattern.to_s})"
60
+ end
61
+
62
+ deep_patterns = patterns.extract! { |pattern| pattern.to_s.include?("\\.") }
63
+
64
+ filters << Regexp.new(patterns.join("|")) if patterns.any?
65
+ filters << Regexp.new(deep_patterns.join("|")) if deep_patterns.any?
66
+
67
+ filters
68
+ end
69
+
70
+ # Create instance with given filters. Supported type of filters are +String+, +Regexp+, and +Proc+.
71
+ # Other types of filters are treated as +String+ using +to_s+.
72
+ # For +Proc+ filters, key, value, and optional original hash is passed to block arguments.
73
+ #
74
+ # ==== Options
75
+ #
76
+ # * <tt>:mask</tt> - A replaced object when filtered. Defaults to <tt>"[FILTERED]"</tt>.
77
+ def initialize(filters = [], mask: FILTERED)
78
+ @mask = mask
79
+ compile_filters!(filters)
80
+ end
81
+
82
+ # Mask value of +params+ if key matches one of filters.
83
+ def filter(params)
84
+ @no_filters ? params.dup : call(params)
85
+ end
86
+
87
+ # Returns filtered value for given key. For +Proc+ filters, third block argument is not populated.
88
+ def filter_param(key, value)
89
+ @no_filters ? value : value_for_key(key, value)
90
+ end
91
+
92
+ private
93
+ def compile_filters!(filters)
94
+ @no_filters = filters.empty?
95
+ return if @no_filters
96
+
97
+ @regexps, strings = [], []
98
+ @deep_regexps, deep_strings = nil, nil
99
+ @blocks = nil
100
+
101
+ filters.each do |item|
102
+ case item
103
+ when Proc
104
+ (@blocks ||= []) << item
105
+ when Regexp
106
+ if item.to_s.include?("\\.")
107
+ (@deep_regexps ||= []) << item
108
+ else
109
+ @regexps << item
110
+ end
111
+ else
112
+ s = Regexp.escape(item.to_s)
113
+ if s.include?("\\.")
114
+ (deep_strings ||= []) << s
115
+ else
116
+ strings << s
117
+ end
118
+ end
119
+ end
120
+
121
+ @regexps << Regexp.new(strings.join("|"), true) unless strings.empty?
122
+ (@deep_regexps ||= []) << Regexp.new(deep_strings.join("|"), true) if deep_strings
123
+ end
124
+
125
+ def call(params, full_parent_key = nil, original_params = params)
126
+ filtered_params = params.class.new
127
+
128
+ params.each do |key, value|
129
+ filtered_params[key] = value_for_key(key, value, full_parent_key, original_params)
130
+ end
131
+
132
+ filtered_params
133
+ end
134
+
135
+ def value_for_key(key, value, full_parent_key = nil, original_params = nil)
136
+ if @deep_regexps
137
+ full_key = full_parent_key ? "#{full_parent_key}.#{key}" : key.to_s
138
+ end
139
+
140
+ if @regexps.any? { |r| r.match?(key.to_s) }
141
+ value = @mask
142
+ elsif @deep_regexps&.any? { |r| r.match?(full_key) }
143
+ value = @mask
144
+ elsif value.is_a?(Hash)
145
+ value = call(value, full_key, original_params)
146
+ elsif value.is_a?(Array)
147
+ value = value.map { |v| value_for_key(key, v, full_parent_key, original_params) }
148
+ elsif @blocks
149
+ key = key.dup if key.duplicable?
150
+ value = value.dup if value.duplicable?
151
+ @blocks.each { |b| b.arity == 2 ? b.call(key, value) : b.call(key, value, original_params) }
152
+ end
153
+
154
+ value
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This is a private interface.
4
+ #
5
+ # Rails components cherry pick from Active Support as needed, but there are a
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.
8
+ #
9
+ # This file is loaded by every Rails component except Active Support itself,
10
+ # but it does not belong to the Rails public interface. It is internal to
11
+ # Rails and can change anytime.
12
+
13
+ # Defines Object#blank? and Object#present?.
14
+ require "active_support/core_ext/object/blank"
15
+
16
+ # Support for ClassMethods and the included macro.
17
+ require "active_support/concern"
18
+
19
+ # Defines Class#class_attribute.
20
+ require "active_support/core_ext/class/attribute"
21
+
22
+ # Defines Module#delegate.
23
+ require "active_support/core_ext/module/delegation"
24
+
25
+ # Defines ActiveSupport::Deprecation.
26
+ require "active_support/deprecation"
@@ -0,0 +1,180 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support"
4
+ require "active_support/i18n_railtie"
5
+
6
+ module ActiveSupport
7
+ class Railtie < Rails::Railtie # :nodoc:
8
+ config.active_support = ActiveSupport::OrderedOptions.new
9
+
10
+ config.eager_load_namespaces << ActiveSupport
11
+
12
+ initializer "active_support.deprecator", before: :load_environment_config do |app|
13
+ app.deprecators[:active_support] = ActiveSupport.deprecator
14
+ end
15
+
16
+ initializer "active_support.isolation_level" do |app|
17
+ config.after_initialize do
18
+ if level = app.config.active_support.isolation_level
19
+ ActiveSupport::IsolatedExecutionState.isolation_level = level
20
+ end
21
+ end
22
+ end
23
+
24
+ initializer "active_support.raise_on_invalid_cache_expiration_time" do |app|
25
+ config.after_initialize do
26
+ if app.config.active_support.raise_on_invalid_cache_expiration_time
27
+ ActiveSupport::Cache::Store.raise_on_invalid_cache_expiration_time = true
28
+ end
29
+ end
30
+ end
31
+
32
+ initializer "active_support.set_authenticated_message_encryption" do |app|
33
+ config.after_initialize do
34
+ unless app.config.active_support.use_authenticated_message_encryption.nil?
35
+ ActiveSupport::MessageEncryptor.use_authenticated_message_encryption =
36
+ app.config.active_support.use_authenticated_message_encryption
37
+ end
38
+ end
39
+ end
40
+
41
+ initializer "active_support.set_event_reporter_context_store" do |app|
42
+ config.after_initialize do
43
+ if klass = app.config.active_support.event_reporter_context_store
44
+ ActiveSupport::EventReporter.context_store = klass
45
+ end
46
+ end
47
+ end
48
+
49
+ initializer "active_support.reset_execution_context" do |app|
50
+ app.reloader.before_class_unload do
51
+ ActiveSupport::CurrentAttributes.clear_all
52
+ ActiveSupport::ExecutionContext.clear
53
+ ActiveSupport.event_reporter.clear_context
54
+ end
55
+
56
+ app.executor.to_run do
57
+ ActiveSupport::ExecutionContext.push
58
+ end
59
+
60
+ app.executor.to_complete do
61
+ ActiveSupport::CurrentAttributes.clear_all
62
+ ActiveSupport::ExecutionContext.pop
63
+ ActiveSupport.event_reporter.clear_context
64
+ end
65
+
66
+ ActiveSupport.on_load(:active_support_test_case) do
67
+ if app.config.active_support.executor_around_test_case
68
+ ActiveSupport::ExecutionContext.nestable = true
69
+
70
+ require "active_support/executor/test_helper"
71
+ include ActiveSupport::Executor::TestHelper
72
+ else
73
+ require "active_support/current_attributes/test_helper"
74
+ include ActiveSupport::CurrentAttributes::TestHelper
75
+
76
+ require "active_support/execution_context/test_helper"
77
+ include ActiveSupport::ExecutionContext::TestHelper
78
+ end
79
+ end
80
+ end
81
+
82
+ initializer "active_support.set_filter_parameters" do |app|
83
+ config.after_initialize do
84
+ ActiveSupport.filter_parameters += Rails.application.config.filter_parameters
85
+ ActiveSupport.event_reporter.reload_payload_filter
86
+ end
87
+ end
88
+
89
+ initializer "active_support.deprecation_behavior" do |app|
90
+ if app.config.active_support.report_deprecations == false
91
+ app.deprecators.silenced = true
92
+ app.deprecators.behavior = :silence
93
+ app.deprecators.disallowed_behavior = :silence
94
+ else
95
+ if deprecation = app.config.active_support.deprecation
96
+ app.deprecators.behavior = deprecation
97
+ end
98
+
99
+ if disallowed_deprecation = app.config.active_support.disallowed_deprecation
100
+ app.deprecators.disallowed_behavior = disallowed_deprecation
101
+ end
102
+
103
+ if disallowed_warnings = app.config.active_support.disallowed_deprecation_warnings
104
+ app.deprecators.disallowed_warnings = disallowed_warnings
105
+ end
106
+ end
107
+ end
108
+
109
+ # Sets the default value for Time.zone
110
+ # If assigned value cannot be matched to a TimeZone, an exception will be raised.
111
+ initializer "active_support.initialize_time_zone" do |app|
112
+ begin
113
+ TZInfo::DataSource.get
114
+ rescue TZInfo::DataSourceNotFound => e
115
+ raise e.exception('tzinfo-data is not present. Please add gem "tzinfo-data" to your Gemfile and run bundle install')
116
+ end
117
+ require "active_support/core_ext/time/zones"
118
+ Time.zone_default = Time.find_zone!(app.config.time_zone)
119
+ config.eager_load_namespaces << TZInfo
120
+ end
121
+
122
+ # Sets the default week start
123
+ # If assigned value is not a valid day symbol (e.g. :sunday, :monday, ...), an exception will be raised.
124
+ initializer "active_support.initialize_beginning_of_week" do |app|
125
+ require "active_support/core_ext/date/calculations"
126
+ beginning_of_week_default = Date.find_beginning_of_week!(app.config.beginning_of_week)
127
+
128
+ Date.beginning_of_week_default = beginning_of_week_default
129
+ end
130
+
131
+ initializer "active_support.require_master_key" do |app|
132
+ if app.config.respond_to?(:require_master_key) && app.config.require_master_key
133
+ begin
134
+ app.credentials.key
135
+ rescue ActiveSupport::EncryptedFile::MissingKeyError => error
136
+ $stderr.puts error.message
137
+ exit 1
138
+ end
139
+ end
140
+ end
141
+
142
+ initializer "active_support.set_configs" do |app|
143
+ app.config.active_support.each do |k, v|
144
+ k = "#{k}="
145
+ ActiveSupport.public_send(k, v) if ActiveSupport.respond_to? k
146
+ end
147
+ end
148
+
149
+ initializer "active_support.set_hash_digest_class" do |app|
150
+ config.after_initialize do
151
+ if klass = app.config.active_support.hash_digest_class
152
+ ActiveSupport::Digest.hash_digest_class = klass
153
+ end
154
+ end
155
+ end
156
+
157
+ initializer "active_support.set_key_generator_hash_digest_class" do |app|
158
+ config.after_initialize do
159
+ if klass = app.config.active_support.key_generator_hash_digest_class
160
+ ActiveSupport::KeyGenerator.hash_digest_class = klass
161
+ end
162
+ end
163
+ end
164
+
165
+ initializer "active_support.set_default_message_serializer" do |app|
166
+ config.after_initialize do
167
+ if message_serializer = app.config.active_support.message_serializer
168
+ ActiveSupport::Messages::Codec.default_serializer = message_serializer
169
+ end
170
+ end
171
+ end
172
+
173
+ initializer "active_support.set_use_message_serializer_for_metadata" do |app|
174
+ config.after_initialize do
175
+ ActiveSupport::Messages::Metadata.use_message_serializer_for_metadata =
176
+ app.config.active_support.use_message_serializer_for_metadata
177
+ end
178
+ end
179
+ end
180
+ end
@@ -0,0 +1,138 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/execution_wrapper"
4
+ require "active_support/executor"
5
+
6
+ module ActiveSupport
7
+ # = Active Support \Reloader
8
+ #
9
+ # This class defines several callbacks:
10
+ #
11
+ # to_prepare -- Run once at application startup, and also from
12
+ # +to_run+.
13
+ #
14
+ # to_run -- Run before a work run that is reloading. If
15
+ # +reload_classes_only_on_change+ is true (the default), the class
16
+ # unload will have already occurred.
17
+ #
18
+ # to_complete -- Run after a work run that has reloaded. If
19
+ # +reload_classes_only_on_change+ is false, the class unload will
20
+ # have occurred after the work run, but before this callback.
21
+ #
22
+ # before_class_unload -- Run immediately before the classes are
23
+ # unloaded.
24
+ #
25
+ # after_class_unload -- Run immediately after the classes are
26
+ # unloaded.
27
+ #
28
+ class Reloader < ExecutionWrapper
29
+ define_callbacks :prepare
30
+
31
+ define_callbacks :class_unload
32
+
33
+ # Registers a callback that will run once at application startup and every time the code is reloaded.
34
+ def self.to_prepare(*args, &block)
35
+ set_callback(:prepare, *args, &block)
36
+ end
37
+
38
+ # Registers a callback that will run immediately before the classes are unloaded.
39
+ def self.before_class_unload(*args, &block)
40
+ set_callback(:class_unload, *args, &block)
41
+ end
42
+
43
+ # Registers a callback that will run immediately after the classes are unloaded.
44
+ def self.after_class_unload(*args, &block)
45
+ set_callback(:class_unload, :after, *args, &block)
46
+ end
47
+
48
+ to_run(:after) { self.class.prepare! }
49
+
50
+ # Initiate a manual reload
51
+ def self.reload!
52
+ executor.wrap do
53
+ new.tap do |instance|
54
+ instance.run!
55
+ ensure
56
+ instance.complete!
57
+ end
58
+ end
59
+ prepare!
60
+ end
61
+
62
+ def self.run!(reset: false) # :nodoc:
63
+ if check!
64
+ super
65
+ else
66
+ Null
67
+ end
68
+ end
69
+
70
+ # Run the supplied block as a work unit, reloading code as needed
71
+ def self.wrap(**kwargs)
72
+ return yield if active?
73
+
74
+ executor.wrap(**kwargs) do
75
+ instance = run!
76
+ begin
77
+ yield
78
+ ensure
79
+ instance.complete!
80
+ end
81
+ end
82
+ end
83
+
84
+ class_attribute :executor, default: Executor
85
+ class_attribute :check, default: lambda { false }
86
+
87
+ def self.check! # :nodoc:
88
+ @should_reload ||= check.call
89
+ end
90
+
91
+ def self.reloaded! # :nodoc:
92
+ @should_reload = false
93
+ end
94
+
95
+ def self.prepare! # :nodoc:
96
+ new.run_callbacks(:prepare)
97
+ end
98
+
99
+ def initialize
100
+ super
101
+ @locked = false
102
+ end
103
+
104
+ # Acquire the ActiveSupport::Dependencies::Interlock unload lock,
105
+ # ensuring it will be released automatically
106
+ def require_unload_lock!
107
+ unless @locked
108
+ ActiveSupport::Dependencies.interlock.start_unloading
109
+ @locked = true
110
+ end
111
+ end
112
+
113
+ # Release the unload lock if it has been previously obtained
114
+ def release_unload_lock!
115
+ if @locked
116
+ @locked = false
117
+ ActiveSupport::Dependencies.interlock.done_unloading
118
+ end
119
+ end
120
+
121
+ def run! # :nodoc:
122
+ super
123
+ release_unload_lock!
124
+ end
125
+
126
+ def class_unload!(&block) # :nodoc:
127
+ require_unload_lock!
128
+ run_callbacks(:class_unload, &block)
129
+ end
130
+
131
+ def complete! # :nodoc:
132
+ super
133
+ self.class.reloaded!
134
+ ensure
135
+ release_unload_lock!
136
+ end
137
+ end
138
+ end