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,75 +1,58 @@
1
- require 'thread_safe'
2
- require 'openssl'
1
+ # frozen_string_literal: true
2
+
3
+ require "concurrent/map"
4
+ require "openssl"
3
5
 
4
6
  module ActiveSupport
5
- # KeyGenerator is a simple wrapper around OpenSSL's implementation of PBKDF2
7
+ # KeyGenerator is a simple wrapper around OpenSSL's implementation of PBKDF2.
6
8
  # It can be used to derive a number of keys for various purposes from a given secret.
7
- # This lets rails applications have a single secure secret, but avoid reusing that
9
+ # This lets Rails applications have a single secure secret, but avoid reusing that
8
10
  # key in multiple incompatible contexts.
9
11
  class KeyGenerator
12
+ class << self
13
+ def hash_digest_class=(klass)
14
+ if klass.kind_of?(Class) && klass < OpenSSL::Digest
15
+ @hash_digest_class = klass
16
+ else
17
+ raise ArgumentError, "#{klass} is expected to be an OpenSSL::Digest subclass"
18
+ end
19
+ end
20
+
21
+ def hash_digest_class
22
+ @hash_digest_class ||= OpenSSL::Digest::SHA1
23
+ end
24
+ end
25
+
10
26
  def initialize(secret, options = {})
11
27
  @secret = secret
12
28
  # The default iterations are higher than required for our key derivation uses
13
29
  # on the off chance someone uses this for password storage
14
30
  @iterations = options[:iterations] || 2**16
31
+ # Also allow configuration here so people can use this to build a rotation
32
+ # scheme when switching the digest class.
33
+ @hash_digest_class = options[:hash_digest_class] || self.class.hash_digest_class
15
34
  end
16
35
 
17
36
  # Returns a derived key suitable for use. The default key_size is chosen
18
37
  # to be compatible with the default settings of ActiveSupport::MessageVerifier.
19
38
  # i.e. OpenSSL::Digest::SHA1#block_length
20
- def generate_key(salt, key_size=64)
21
- OpenSSL::PKCS5.pbkdf2_hmac_sha1(@secret, salt, @iterations, key_size)
39
+ def generate_key(salt, key_size = 64)
40
+ OpenSSL::PKCS5.pbkdf2_hmac(@secret, salt, @iterations, key_size, @hash_digest_class.new)
22
41
  end
23
42
  end
24
43
 
25
44
  # CachingKeyGenerator is a wrapper around KeyGenerator which allows users to avoid
26
45
  # re-executing the key generation process when it's called using the same salt and
27
- # key_size
46
+ # key_size.
28
47
  class CachingKeyGenerator
29
48
  def initialize(key_generator)
30
49
  @key_generator = key_generator
31
- @cache_keys = ThreadSafe::Cache.new
32
- end
33
-
34
- # Returns a derived key suitable for use. The default key_size is chosen
35
- # to be compatible with the default settings of ActiveSupport::MessageVerifier.
36
- # i.e. OpenSSL::Digest::SHA1#block_length
37
- def generate_key(salt, key_size=64)
38
- @cache_keys["#{salt}#{key_size}"] ||= @key_generator.generate_key(salt, key_size)
39
- end
40
- end
41
-
42
- class LegacyKeyGenerator # :nodoc:
43
- SECRET_MIN_LENGTH = 30 # Characters
44
-
45
- def initialize(secret)
46
- ensure_secret_secure(secret)
47
- @secret = secret
50
+ @cache_keys = Concurrent::Map.new
48
51
  end
49
52
 
50
- def generate_key(salt)
51
- @secret
52
- end
53
-
54
- private
55
-
56
- # To prevent users from using something insecure like "Password" we make sure that the
57
- # secret they've provided is at least 30 characters in length.
58
- def ensure_secret_secure(secret)
59
- if secret.blank?
60
- raise ArgumentError, "A secret is required to generate an " +
61
- "integrity hash for cookie session data. Use " +
62
- "config.secret_key_base = \"some secret phrase of at " +
63
- "least #{SECRET_MIN_LENGTH} characters\"" +
64
- "in config/initializers/secret_token.rb"
65
- end
66
-
67
- if secret.length < SECRET_MIN_LENGTH
68
- raise ArgumentError, "Secret should be something secure, " +
69
- "like \"#{SecureRandom.hex(16)}\". The value you " +
70
- "provided, \"#{secret}\", is shorter than the minimum length " +
71
- "of #{SECRET_MIN_LENGTH} characters"
72
- end
53
+ # Returns a derived key suitable for use.
54
+ def generate_key(*args)
55
+ @cache_keys[args.join("|")] ||= @key_generator.generate_key(*args)
73
56
  end
74
57
  end
75
58
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveSupport
2
- # lazy_load_hooks allows rails to lazily load a lot of components and thus
4
+ # lazy_load_hooks allows Rails to lazily load a lot of components and thus
3
5
  # making the app boot faster. Because of this feature now there is no need to
4
6
  # require <tt>ActiveRecord::Base</tt> at boot time purely to apply
5
7
  # configuration. Instead a hook is registered that applies configuration once
@@ -15,34 +17,65 @@ module ActiveSupport
15
17
  # end
16
18
  # end
17
19
  #
18
- # When the entirety of +activerecord/lib/active_record/base.rb+ has been
20
+ # When the entirety of +ActiveRecord::Base+ has been
19
21
  # evaluated then +run_load_hooks+ is invoked. The very last line of
20
- # +activerecord/lib/active_record/base.rb+ is:
22
+ # +ActiveRecord::Base+ is:
21
23
  #
22
24
  # ActiveSupport.run_load_hooks(:active_record, ActiveRecord::Base)
23
- @load_hooks = Hash.new { |h,k| h[k] = [] }
24
- @loaded = Hash.new { |h,k| h[k] = [] }
25
-
26
- def self.on_load(name, options = {}, &block)
27
- @loaded[name].each do |base|
28
- execute_hook(base, options, block)
25
+ module LazyLoadHooks
26
+ def self.extended(base) # :nodoc:
27
+ base.class_eval do
28
+ @load_hooks = Hash.new { |h, k| h[k] = [] }
29
+ @loaded = Hash.new { |h, k| h[k] = [] }
30
+ @run_once = Hash.new { |h, k| h[k] = [] }
31
+ end
29
32
  end
30
33
 
31
- @load_hooks[name] << [block, options]
32
- end
34
+ # Declares a block that will be executed when a Rails component is fully
35
+ # loaded.
36
+ #
37
+ # Options:
38
+ #
39
+ # * <tt>:yield</tt> - Yields the object that run_load_hooks to +block+.
40
+ # * <tt>:run_once</tt> - Given +block+ will run only once.
41
+ def on_load(name, options = {}, &block)
42
+ @loaded[name].each do |base|
43
+ execute_hook(name, base, options, block)
44
+ end
33
45
 
34
- def self.execute_hook(base, options, block)
35
- if options[:yield]
36
- block.call(base)
37
- else
38
- base.instance_eval(&block)
46
+ @load_hooks[name] << [block, options]
39
47
  end
40
- end
41
48
 
42
- def self.run_load_hooks(name, base = Object)
43
- @loaded[name] << base
44
- @load_hooks[name].each do |hook, options|
45
- execute_hook(base, options, hook)
49
+ def run_load_hooks(name, base = Object)
50
+ @loaded[name] << base
51
+ @load_hooks[name].each do |hook, options|
52
+ execute_hook(name, base, options, hook)
53
+ end
46
54
  end
55
+
56
+ private
57
+ def with_execution_control(name, block, once)
58
+ unless @run_once[name].include?(block)
59
+ @run_once[name] << block if once
60
+
61
+ yield
62
+ end
63
+ end
64
+
65
+ def execute_hook(name, base, options, block)
66
+ with_execution_control(name, block, options[:run_once]) do
67
+ if options[:yield]
68
+ block.call(base)
69
+ else
70
+ if base.is_a?(Module)
71
+ base.class_eval(&block)
72
+ else
73
+ base.instance_eval(&block)
74
+ end
75
+ end
76
+ end
77
+ end
47
78
  end
79
+
80
+ extend LazyLoadHooks
48
81
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ {
4
+ en: {
5
+ number: {
6
+ nth: {
7
+ ordinals: lambda do |_key, options|
8
+ number = options[:number]
9
+ case number
10
+ when 1; "st"
11
+ when 2; "nd"
12
+ when 3; "rd"
13
+ when 4, 5, 6, 7, 8, 9, 10, 11, 12, 13; "th"
14
+ else
15
+ num_modulo = number.to_i.abs % 100
16
+ num_modulo %= 10 if num_modulo > 13
17
+ case num_modulo
18
+ when 1; "st"
19
+ when 2; "nd"
20
+ when 3; "rd"
21
+ else "th"
22
+ end
23
+ end
24
+ end,
25
+
26
+ ordinalized: lambda do |_key, options|
27
+ number = options[:number]
28
+ "#{number}#{ActiveSupport::Inflector.ordinal(number)}"
29
+ end
30
+ }
31
+ }
32
+ }
33
+ }
@@ -44,22 +44,25 @@ en:
44
44
  delimiter: ","
45
45
  # Number of decimals, behind the separator (the number 1 with a precision of 2 gives: 1.00)
46
46
  precision: 3
47
+ # Determine how rounding is performed (see BigDecimal::mode)
48
+ round_mode: default
47
49
  # If set to true, precision will mean the number of significant digits instead
48
50
  # of the number of decimal digits (1234 with precision 2 becomes 1200, 1.23543 becomes 1.2)
49
51
  significant: false
50
- # If set, the zeros after the decimal separator will always be stripped (eg.: 1.200 will be 1.2)
52
+ # If set, the zeros after the decimal separator will always be stripped (e.g.: 1.200 will be 1.2)
51
53
  strip_insignificant_zeros: false
52
54
 
53
55
  # Used in NumberHelper.number_to_currency()
54
56
  currency:
55
57
  format:
56
- # Where is the currency sign? %u is the currency unit, %n the number (default: $5.00)
58
+ # Where is the currency sign? %u is the currency unit, %n is the number (default: $5.00)
57
59
  format: "%u%n"
58
60
  unit: "$"
59
- # These five are to override number.format and are optional
61
+ # These six are to override number.format and are optional
60
62
  separator: "."
61
63
  delimiter: ","
62
64
  precision: 2
65
+ # round_mode:
63
66
  significant: false
64
67
  strip_insignificant_zeros: false
65
68
 
@@ -87,10 +90,11 @@ en:
87
90
  # Used in NumberHelper.number_to_human_size() and NumberHelper.number_to_human()
88
91
  human:
89
92
  format:
90
- # These five are to override number.format and are optional
93
+ # These six are to override number.format and are optional
91
94
  # separator:
92
95
  delimiter: ""
93
96
  precision: 3
97
+ # round_mode:
94
98
  significant: true
95
99
  strip_insignificant_zeros: true
96
100
  # Used in number_to_human_size()
@@ -106,6 +110,8 @@ en:
106
110
  mb: "MB"
107
111
  gb: "GB"
108
112
  tb: "TB"
113
+ pb: "PB"
114
+ eb: "EB"
109
115
  # Used in NumberHelper.number_to_human()
110
116
  decimal_units:
111
117
  format: "%n %u"
@@ -1,6 +1,8 @@
1
- require 'active_support/log_subscriber'
2
- require 'active_support/buffered_logger'
3
- require 'active_support/notifications'
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/log_subscriber"
4
+ require "active_support/logger"
5
+ require "active_support/notifications"
4
6
 
5
7
  module ActiveSupport
6
8
  class LogSubscriber
@@ -10,7 +12,7 @@ module ActiveSupport
10
12
  # class SyncLogSubscriberTest < ActiveSupport::TestCase
11
13
  # include ActiveSupport::LogSubscriber::TestHelper
12
14
  #
13
- # def setup
15
+ # setup do
14
16
  # ActiveRecord::LogSubscriber.attach_to(:active_record)
15
17
  # end
16
18
  #
@@ -33,7 +35,7 @@ module ActiveSupport
33
35
  # you can collect them doing @logger.logged(level), where level is the level
34
36
  # used in logging, like info, debug, warn and so on.
35
37
  module TestHelper
36
- def setup
38
+ def setup # :nodoc:
37
39
  @logger = MockLogger.new
38
40
  @notifier = ActiveSupport::Notifications::Fanout.new
39
41
 
@@ -44,7 +46,7 @@ module ActiveSupport
44
46
  ActiveSupport::Notifications.notifier = @notifier
45
47
  end
46
48
 
47
- def teardown
49
+ def teardown # :nodoc:
48
50
  set_logger(nil)
49
51
  ActiveSupport::Notifications.notifier = @old_notifier
50
52
  end
@@ -58,15 +60,15 @@ module ActiveSupport
58
60
  def initialize(level = DEBUG)
59
61
  @flush_count = 0
60
62
  @level = level
61
- @logged = Hash.new { |h,k| h[k] = [] }
63
+ @logged = Hash.new { |h, k| h[k] = [] }
62
64
  end
63
65
 
64
66
  def method_missing(level, message = nil)
65
- if block_given?
66
- @logged[level] << yield
67
- else
68
- @logged[level] << message
69
- end
67
+ if block_given?
68
+ @logged[level] << yield
69
+ else
70
+ @logged[level] << message
71
+ end
70
72
  end
71
73
 
72
74
  def logged(level)
@@ -1,10 +1,12 @@
1
- require 'active_support/core_ext/module/attribute_accessors'
2
- require 'active_support/core_ext/class/attribute'
3
- require 'active_support/subscriber'
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/module/attribute_accessors"
4
+ require "active_support/core_ext/class/attribute"
5
+ require "active_support/subscriber"
4
6
 
5
7
  module ActiveSupport
6
- # ActiveSupport::LogSubscriber is an object set to consume
7
- # ActiveSupport::Notifications with the sole purpose of logging them.
8
+ # <tt>ActiveSupport::LogSubscriber</tt> is an object set to consume
9
+ # <tt>ActiveSupport::Notifications</tt> with the sole purpose of logging them.
8
10
  # The log subscriber dispatches notifications to a registered object based
9
11
  # on its given namespace.
10
12
  #
@@ -14,7 +16,7 @@ module ActiveSupport
14
16
  # module ActiveRecord
15
17
  # class LogSubscriber < ActiveSupport::LogSubscriber
16
18
  # def sql(event)
17
- # "#{event.payload[:name]} (#{event.duration}) #{event.payload[:sql]}"
19
+ # info "#{event.payload[:name]} (#{event.duration}) #{event.payload[:sql]}"
18
20
  # end
19
21
  # end
20
22
  # end
@@ -27,13 +29,39 @@ module ActiveSupport
27
29
  # subscriber, the line above should be called after your
28
30
  # <tt>ActiveRecord::LogSubscriber</tt> definition.
29
31
  #
30
- # After configured, whenever a "sql.active_record" notification is published,
31
- # it will properly dispatch the event (ActiveSupport::Notifications::Event) to
32
- # the sql method.
32
+ # A logger also needs to be set with <tt>ActiveRecord::LogSubscriber.logger=</tt>.
33
+ # This is assigned automatically in a Rails environment.
34
+ #
35
+ # After configured, whenever a <tt>"sql.active_record"</tt> notification is published,
36
+ # it will properly dispatch the event
37
+ # (<tt>ActiveSupport::Notifications::Event</tt>) to the sql method.
38
+ #
39
+ # Being an <tt>ActiveSupport::Notifications</tt> consumer,
40
+ # <tt>ActiveSupport::LogSubscriber</tt> exposes a simple interface to check if
41
+ # instrumented code raises an exception. It is common to log a different
42
+ # message in case of an error, and this can be achieved by extending
43
+ # the previous example:
44
+ #
45
+ # module ActiveRecord
46
+ # class LogSubscriber < ActiveSupport::LogSubscriber
47
+ # def sql(event)
48
+ # exception = event.payload[:exception]
49
+ #
50
+ # if exception
51
+ # exception_object = event.payload[:exception_object]
52
+ #
53
+ # error "[ERROR] #{event.payload[:name]}: #{exception.join(', ')} " \
54
+ # "(#{exception_object.backtrace.first})"
55
+ # else
56
+ # # standard logger code
57
+ # end
58
+ # end
59
+ # end
60
+ # end
33
61
  #
34
62
  # Log subscriber also has some helpers to deal with logging and automatically
35
- # flushes all logs when the request finishes (via action_dispatch.callback
36
- # notification) in a Rails environment.
63
+ # flushes all logs when the request finishes
64
+ # (via <tt>action_dispatch.callback</tt> notification) in a Rails environment.
37
65
  class LogSubscriber < Subscriber
38
66
  # Embed in a String to clear all previous ANSI sequences.
39
67
  CLEAR = "\e[0m"
@@ -49,8 +77,7 @@ module ActiveSupport
49
77
  CYAN = "\e[36m"
50
78
  WHITE = "\e[37m"
51
79
 
52
- mattr_accessor :colorize_logging
53
- self.colorize_logging = true
80
+ mattr_accessor :colorize_logging, default: true
54
81
 
55
82
  class << self
56
83
  def logger
@@ -69,6 +96,11 @@ module ActiveSupport
69
96
  def flush_all!
70
97
  logger.flush if logger.respond_to?(:flush)
71
98
  end
99
+
100
+ private
101
+ def fetch_public_methods(subscriber, inherit_all)
102
+ subscriber.public_methods(inherit_all) - LogSubscriber.public_instance_methods(true)
103
+ end
72
104
  end
73
105
 
74
106
  def logger
@@ -81,12 +113,17 @@ module ActiveSupport
81
113
 
82
114
  def finish(name, id, payload)
83
115
  super if logger
84
- rescue Exception => e
85
- logger.error "Could not log #{name.inspect} event. #{e.class}: #{e.message} #{e.backtrace}"
116
+ rescue => e
117
+ log_exception(name, e)
86
118
  end
87
119
 
88
- protected
120
+ def publish_event(event)
121
+ super if logger
122
+ rescue => e
123
+ log_exception(event.name, e)
124
+ end
89
125
 
126
+ private
90
127
  %w(info debug warn error fatal unknown).each do |level|
91
128
  class_eval <<-METHOD, __FILE__, __LINE__ + 1
92
129
  def #{level}(progname = nil, &block)
@@ -95,15 +132,21 @@ module ActiveSupport
95
132
  METHOD
96
133
  end
97
134
 
98
- # Set color by using a string or one of the defined constants. If a third
135
+ # Set color by using a symbol or one of the defined constants. If a third
99
136
  # option is set to +true+, it also adds bold to the string. This is based
100
137
  # on the Highline implementation and will automatically append CLEAR to the
101
138
  # end of the returned String.
102
- def color(text, color, bold=false)
139
+ def color(text, color, bold = false) # :doc:
103
140
  return text unless colorize_logging
104
141
  color = self.class.const_get(color.upcase) if color.is_a?(Symbol)
105
142
  bold = bold ? BOLD : ""
106
143
  "#{bold}#{color}#{text}#{CLEAR}"
107
144
  end
145
+
146
+ def log_exception(name, e)
147
+ if logger
148
+ logger.error "Could not log #{name.inspect} event. #{e.class}: #{e.message} #{e.backtrace}"
149
+ end
150
+ end
108
151
  end
109
152
  end
@@ -1,11 +1,24 @@
1
- require 'active_support/core_ext/class/attribute_accessors'
2
- require 'active_support/logger_silence'
3
- require 'logger'
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/logger_silence"
4
+ require "active_support/logger_thread_safe_level"
5
+ require "logger"
4
6
 
5
7
  module ActiveSupport
6
8
  class Logger < ::Logger
7
9
  include LoggerSilence
8
10
 
11
+ # Returns true if the logger destination matches one of the sources
12
+ #
13
+ # logger = Logger.new(STDOUT)
14
+ # ActiveSupport::Logger.logger_outputs_to?(logger, STDOUT)
15
+ # # => true
16
+ def self.logger_outputs_to?(logger, *sources)
17
+ logdev = logger.instance_variable_get(:@logdev)
18
+ logger_source = logdev.dev if logdev.respond_to?(:dev)
19
+ sources.any? { |source| source == logger_source }
20
+ end
21
+
9
22
  # Broadcasts logs to multiple loggers.
10
23
  def self.broadcast(logger) # :nodoc:
11
24
  Module.new do
@@ -38,10 +51,33 @@ module ActiveSupport
38
51
  logger.level = level
39
52
  super(level)
40
53
  end
54
+
55
+ define_method(:local_level=) do |level|
56
+ logger.local_level = level if logger.respond_to?(:local_level=)
57
+ super(level) if respond_to?(:local_level=)
58
+ end
59
+
60
+ define_method(:silence) do |level = Logger::ERROR, &block|
61
+ if logger.respond_to?(:silence)
62
+ logger.silence(level) do
63
+ if defined?(super)
64
+ super(level, &block)
65
+ else
66
+ block.call(self)
67
+ end
68
+ end
69
+ else
70
+ if defined?(super)
71
+ super(level, &block)
72
+ else
73
+ block.call(self)
74
+ end
75
+ end
76
+ end
41
77
  end
42
78
  end
43
79
 
44
- def initialize(*args)
80
+ def initialize(*args, **kwargs)
45
81
  super
46
82
  @formatter = SimpleFormatter.new
47
83
  end
@@ -1,24 +1,21 @@
1
- require 'active_support/concern'
1
+ # frozen_string_literal: true
2
2
 
3
- module LoggerSilence
4
- extend ActiveSupport::Concern
5
-
6
- included do
7
- cattr_accessor :silencer
8
- self.silencer = true
9
- end
3
+ require "active_support/concern"
4
+ require "active_support/core_ext/module/attribute_accessors"
5
+ require "active_support/logger_thread_safe_level"
6
+
7
+ module ActiveSupport
8
+ module LoggerSilence
9
+ extend ActiveSupport::Concern
10
+
11
+ included do
12
+ cattr_accessor :silencer, default: true
13
+ include ActiveSupport::LoggerThreadSafeLevel
14
+ end
10
15
 
11
- # Silences the logger for the duration of the block.
12
- def silence(temporary_level = Logger::ERROR)
13
- if silencer
14
- begin
15
- old_logger_level, self.level = level, temporary_level
16
- yield self
17
- ensure
18
- self.level = old_logger_level
19
- end
20
- else
21
- yield self
16
+ # Silences the logger for the duration of the block.
17
+ def silence(severity = Logger::ERROR)
18
+ silencer ? log_at(severity) { yield self } : yield(self)
22
19
  end
23
20
  end
24
- end
21
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+ require "active_support/core_ext/module/attribute_accessors"
5
+ require "concurrent"
6
+ require "fiber"
7
+
8
+ module ActiveSupport
9
+ module LoggerThreadSafeLevel # :nodoc:
10
+ extend ActiveSupport::Concern
11
+
12
+ Logger::Severity.constants.each do |severity|
13
+ class_eval(<<-EOT, __FILE__, __LINE__ + 1)
14
+ def #{severity.downcase}? # def debug?
15
+ Logger::#{severity} >= level # DEBUG >= level
16
+ end # end
17
+ EOT
18
+ end
19
+
20
+ def local_level
21
+ IsolatedExecutionState[:logger_thread_safe_level]
22
+ end
23
+
24
+ def local_level=(level)
25
+ case level
26
+ when Integer
27
+ when Symbol
28
+ level = Logger::Severity.const_get(level.to_s.upcase)
29
+ when nil
30
+ else
31
+ raise ArgumentError, "Invalid log level: #{level.inspect}"
32
+ end
33
+ IsolatedExecutionState[:logger_thread_safe_level] = level
34
+ end
35
+
36
+ def level
37
+ local_level || super
38
+ end
39
+
40
+ # Change the thread-local level for the duration of the given block.
41
+ def log_at(level)
42
+ old_local_level, self.local_level = local_level, level
43
+ yield
44
+ ensure
45
+ self.local_level = old_local_level
46
+ end
47
+
48
+ # Redefined to check severity against #level, and thus the thread-local level, rather than +@level+.
49
+ # FIXME: Remove when the minimum Ruby version supports overriding Logger#level.
50
+ def add(severity, message = nil, progname = nil, &block) # :nodoc:
51
+ severity ||= UNKNOWN
52
+ progname ||= @progname
53
+
54
+ return true if @logdev.nil? || severity < level
55
+
56
+ if message.nil?
57
+ if block_given?
58
+ message = yield
59
+ else
60
+ message = progname
61
+ progname = @progname
62
+ end
63
+ end
64
+
65
+ @logdev.write \
66
+ format_message(format_severity(severity), Time.now, progname, message)
67
+ end
68
+ end
69
+ end