activesupport 4.2.11.1 → 6.0.3.1

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 (263) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +399 -411
  3. data/MIT-LICENSE +2 -2
  4. data/README.rdoc +7 -7
  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 +34 -6
  9. data/lib/active_support/benchmarkable.rb +6 -4
  10. data/lib/active_support/builder.rb +3 -1
  11. data/lib/active_support/cache/file_store.rb +58 -53
  12. data/lib/active_support/cache/mem_cache_store.rb +95 -91
  13. data/lib/active_support/cache/memory_store.rb +39 -36
  14. data/lib/active_support/cache/null_store.rb +11 -7
  15. data/lib/active_support/cache/redis_cache_store.rb +493 -0
  16. data/lib/active_support/cache/strategy/local_cache.rb +75 -42
  17. data/lib/active_support/cache/strategy/local_cache_middleware.rb +10 -9
  18. data/lib/active_support/cache.rb +331 -217
  19. data/lib/active_support/callbacks.rb +650 -592
  20. data/lib/active_support/concern.rb +35 -6
  21. data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +35 -0
  22. data/lib/active_support/concurrency/share_lock.rb +226 -0
  23. data/lib/active_support/configurable.rb +13 -14
  24. data/lib/active_support/core_ext/array/access.rb +41 -1
  25. data/lib/active_support/core_ext/array/conversions.rb +24 -20
  26. data/lib/active_support/core_ext/array/extract.rb +21 -0
  27. data/lib/active_support/core_ext/array/extract_options.rb +2 -0
  28. data/lib/active_support/core_ext/array/grouping.rb +11 -18
  29. data/lib/active_support/core_ext/array/inquiry.rb +19 -0
  30. data/lib/active_support/core_ext/array/prepend_and_append.rb +4 -6
  31. data/lib/active_support/core_ext/array/wrap.rb +7 -4
  32. data/lib/active_support/core_ext/array.rb +9 -6
  33. data/lib/active_support/core_ext/benchmark.rb +3 -1
  34. data/lib/active_support/core_ext/big_decimal/conversions.rb +10 -12
  35. data/lib/active_support/core_ext/big_decimal.rb +3 -1
  36. data/lib/active_support/core_ext/class/attribute.rb +45 -31
  37. data/lib/active_support/core_ext/class/attribute_accessors.rb +3 -1
  38. data/lib/active_support/core_ext/class/subclasses.rb +20 -6
  39. data/lib/active_support/core_ext/class.rb +4 -3
  40. data/lib/active_support/core_ext/date/acts_like.rb +3 -1
  41. data/lib/active_support/core_ext/date/blank.rb +14 -0
  42. data/lib/active_support/core_ext/date/calculations.rb +17 -14
  43. data/lib/active_support/core_ext/date/conversions.rb +25 -23
  44. data/lib/active_support/core_ext/date/zones.rb +4 -2
  45. data/lib/active_support/core_ext/date.rb +6 -4
  46. data/lib/active_support/core_ext/date_and_time/calculations.rb +154 -65
  47. data/lib/active_support/core_ext/date_and_time/compatibility.rb +4 -3
  48. data/lib/active_support/core_ext/date_and_time/zones.rb +12 -13
  49. data/lib/active_support/core_ext/date_time/acts_like.rb +4 -2
  50. data/lib/active_support/core_ext/date_time/blank.rb +14 -0
  51. data/lib/active_support/core_ext/date_time/calculations.rb +37 -19
  52. data/lib/active_support/core_ext/date_time/compatibility.rb +8 -6
  53. data/lib/active_support/core_ext/date_time/conversions.rb +16 -13
  54. data/lib/active_support/core_ext/date_time.rb +7 -5
  55. data/lib/active_support/core_ext/digest/uuid.rb +7 -5
  56. data/lib/active_support/core_ext/digest.rb +3 -0
  57. data/lib/active_support/core_ext/enumerable.rb +114 -22
  58. data/lib/active_support/core_ext/file/atomic.rb +38 -31
  59. data/lib/active_support/core_ext/file.rb +3 -1
  60. data/lib/active_support/core_ext/hash/compact.rb +4 -23
  61. data/lib/active_support/core_ext/hash/conversions.rb +62 -41
  62. data/lib/active_support/core_ext/hash/deep_merge.rb +9 -13
  63. data/lib/active_support/core_ext/hash/deep_transform_values.rb +46 -0
  64. data/lib/active_support/core_ext/hash/except.rb +12 -9
  65. data/lib/active_support/core_ext/hash/indifferent_access.rb +4 -3
  66. data/lib/active_support/core_ext/hash/keys.rb +19 -42
  67. data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
  68. data/lib/active_support/core_ext/hash/slice.rb +5 -27
  69. data/lib/active_support/core_ext/hash/transform_values.rb +4 -22
  70. data/lib/active_support/core_ext/hash.rb +10 -9
  71. data/lib/active_support/core_ext/integer/inflections.rb +3 -1
  72. data/lib/active_support/core_ext/integer/multiple.rb +3 -1
  73. data/lib/active_support/core_ext/integer/time.rb +11 -18
  74. data/lib/active_support/core_ext/integer.rb +5 -3
  75. data/lib/active_support/core_ext/kernel/concern.rb +5 -1
  76. data/lib/active_support/core_ext/kernel/reporting.rb +4 -84
  77. data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
  78. data/lib/active_support/core_ext/kernel.rb +5 -5
  79. data/lib/active_support/core_ext/load_error.rb +3 -22
  80. data/lib/active_support/core_ext/marshal.rb +8 -8
  81. data/lib/active_support/core_ext/module/aliasing.rb +6 -44
  82. data/lib/active_support/core_ext/module/anonymous.rb +12 -1
  83. data/lib/active_support/core_ext/module/attr_internal.rb +8 -9
  84. data/lib/active_support/core_ext/module/attribute_accessors.rb +46 -46
  85. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +144 -0
  86. data/lib/active_support/core_ext/module/concerning.rb +11 -12
  87. data/lib/active_support/core_ext/module/delegation.rb +133 -30
  88. data/lib/active_support/core_ext/module/deprecation.rb +4 -2
  89. data/lib/active_support/core_ext/module/introspection.rb +44 -19
  90. data/lib/active_support/core_ext/module/reachable.rb +5 -7
  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 -11
  94. data/lib/active_support/core_ext/name_error.rb +22 -2
  95. data/lib/active_support/core_ext/numeric/bytes.rb +22 -0
  96. data/lib/active_support/core_ext/numeric/conversions.rb +129 -136
  97. data/lib/active_support/core_ext/numeric/inquiry.rb +5 -0
  98. data/lib/active_support/core_ext/numeric/time.rb +35 -23
  99. data/lib/active_support/core_ext/numeric.rb +5 -3
  100. data/lib/active_support/core_ext/object/acts_like.rb +12 -1
  101. data/lib/active_support/core_ext/object/blank.rb +27 -3
  102. data/lib/active_support/core_ext/object/conversions.rb +6 -4
  103. data/lib/active_support/core_ext/object/deep_dup.rb +13 -4
  104. data/lib/active_support/core_ext/object/duplicable.rb +13 -93
  105. data/lib/active_support/core_ext/object/inclusion.rb +5 -3
  106. data/lib/active_support/core_ext/object/instance_variables.rb +3 -1
  107. data/lib/active_support/core_ext/object/json.rb +51 -20
  108. data/lib/active_support/core_ext/object/to_param.rb +3 -1
  109. data/lib/active_support/core_ext/object/to_query.rb +10 -5
  110. data/lib/active_support/core_ext/object/try.rb +81 -23
  111. data/lib/active_support/core_ext/object/with_options.rb +16 -3
  112. data/lib/active_support/core_ext/object.rb +14 -13
  113. data/lib/active_support/core_ext/range/compare_range.rb +76 -0
  114. data/lib/active_support/core_ext/range/conversions.rb +37 -15
  115. data/lib/active_support/core_ext/range/each.rb +18 -17
  116. data/lib/active_support/core_ext/range/include_range.rb +7 -21
  117. data/lib/active_support/core_ext/range/include_time_with_zone.rb +23 -0
  118. data/lib/active_support/core_ext/range/overlaps.rb +2 -0
  119. data/lib/active_support/core_ext/range.rb +7 -4
  120. data/lib/active_support/core_ext/regexp.rb +2 -0
  121. data/lib/active_support/core_ext/securerandom.rb +45 -0
  122. data/lib/active_support/core_ext/string/access.rb +16 -6
  123. data/lib/active_support/core_ext/string/behavior.rb +3 -1
  124. data/lib/active_support/core_ext/string/conversions.rb +7 -4
  125. data/lib/active_support/core_ext/string/exclude.rb +2 -0
  126. data/lib/active_support/core_ext/string/filters.rb +48 -6
  127. data/lib/active_support/core_ext/string/indent.rb +6 -4
  128. data/lib/active_support/core_ext/string/inflections.rb +66 -24
  129. data/lib/active_support/core_ext/string/inquiry.rb +3 -1
  130. data/lib/active_support/core_ext/string/multibyte.rb +16 -7
  131. data/lib/active_support/core_ext/string/output_safety.rb +93 -40
  132. data/lib/active_support/core_ext/string/starts_ends_with.rb +2 -0
  133. data/lib/active_support/core_ext/string/strip.rb +6 -5
  134. data/lib/active_support/core_ext/string/zones.rb +4 -2
  135. data/lib/active_support/core_ext/string.rb +15 -13
  136. data/lib/active_support/core_ext/time/acts_like.rb +3 -1
  137. data/lib/active_support/core_ext/time/calculations.rb +115 -52
  138. data/lib/active_support/core_ext/time/compatibility.rb +4 -2
  139. data/lib/active_support/core_ext/time/conversions.rb +20 -13
  140. data/lib/active_support/core_ext/time/zones.rb +41 -7
  141. data/lib/active_support/core_ext/time.rb +7 -6
  142. data/lib/active_support/core_ext/uri.rb +6 -7
  143. data/lib/active_support/core_ext.rb +3 -1
  144. data/lib/active_support/current_attributes.rb +203 -0
  145. data/lib/active_support/dependencies/autoload.rb +2 -0
  146. data/lib/active_support/dependencies/interlock.rb +57 -0
  147. data/lib/active_support/dependencies/zeitwerk_integration.rb +117 -0
  148. data/lib/active_support/dependencies.rb +208 -166
  149. data/lib/active_support/deprecation/behaviors.rb +44 -11
  150. data/lib/active_support/deprecation/constant_accessor.rb +52 -0
  151. data/lib/active_support/deprecation/instance_delegator.rb +17 -2
  152. data/lib/active_support/deprecation/method_wrappers.rb +61 -21
  153. data/lib/active_support/deprecation/proxy_wrappers.rb +81 -30
  154. data/lib/active_support/deprecation/reporting.rb +32 -12
  155. data/lib/active_support/deprecation.rb +12 -9
  156. data/lib/active_support/descendants_tracker.rb +57 -9
  157. data/lib/active_support/digest.rb +20 -0
  158. data/lib/active_support/duration/iso8601_parser.rb +123 -0
  159. data/lib/active_support/duration/iso8601_serializer.rb +53 -0
  160. data/lib/active_support/duration.rb +315 -40
  161. data/lib/active_support/encrypted_configuration.rb +45 -0
  162. data/lib/active_support/encrypted_file.rb +100 -0
  163. data/lib/active_support/evented_file_update_checker.rb +234 -0
  164. data/lib/active_support/execution_wrapper.rb +129 -0
  165. data/lib/active_support/executor.rb +8 -0
  166. data/lib/active_support/file_update_checker.rb +62 -37
  167. data/lib/active_support/gem_version.rb +6 -4
  168. data/lib/active_support/gzip.rb +7 -5
  169. data/lib/active_support/hash_with_indifferent_access.rb +129 -30
  170. data/lib/active_support/i18n.rb +9 -6
  171. data/lib/active_support/i18n_railtie.rb +50 -14
  172. data/lib/active_support/inflections.rb +13 -11
  173. data/lib/active_support/inflector/inflections.rb +58 -13
  174. data/lib/active_support/inflector/methods.rb +159 -145
  175. data/lib/active_support/inflector/transliterate.rb +84 -34
  176. data/lib/active_support/inflector.rb +7 -5
  177. data/lib/active_support/json/decoding.rb +32 -30
  178. data/lib/active_support/json/encoding.rb +17 -60
  179. data/lib/active_support/json.rb +4 -2
  180. data/lib/active_support/key_generator.rb +11 -43
  181. data/lib/active_support/lazy_load_hooks.rb +53 -20
  182. data/lib/active_support/locale/en.rb +33 -0
  183. data/lib/active_support/locale/en.yml +2 -0
  184. data/lib/active_support/log_subscriber/test_helper.rb +14 -12
  185. data/lib/active_support/log_subscriber.rb +44 -19
  186. data/lib/active_support/logger.rb +9 -23
  187. data/lib/active_support/logger_silence.rb +32 -14
  188. data/lib/active_support/logger_thread_safe_level.rb +32 -8
  189. data/lib/active_support/message_encryptor.rb +166 -53
  190. data/lib/active_support/message_verifier.rb +149 -16
  191. data/lib/active_support/messages/metadata.rb +72 -0
  192. data/lib/active_support/messages/rotation_configuration.rb +22 -0
  193. data/lib/active_support/messages/rotator.rb +56 -0
  194. data/lib/active_support/multibyte/chars.rb +56 -63
  195. data/lib/active_support/multibyte/unicode.rb +56 -290
  196. data/lib/active_support/multibyte.rb +4 -2
  197. data/lib/active_support/notifications/fanout.rb +109 -22
  198. data/lib/active_support/notifications/instrumenter.rb +107 -16
  199. data/lib/active_support/notifications.rb +51 -10
  200. data/lib/active_support/number_helper/number_converter.rb +16 -15
  201. data/lib/active_support/number_helper/number_to_currency_converter.rb +14 -15
  202. data/lib/active_support/number_helper/number_to_delimited_converter.rb +11 -4
  203. data/lib/active_support/number_helper/number_to_human_converter.rb +13 -10
  204. data/lib/active_support/number_helper/number_to_human_size_converter.rb +11 -9
  205. data/lib/active_support/number_helper/number_to_percentage_converter.rb +5 -1
  206. data/lib/active_support/number_helper/number_to_phone_converter.rb +15 -5
  207. data/lib/active_support/number_helper/number_to_rounded_converter.rb +25 -57
  208. data/lib/active_support/number_helper/rounding_helper.rb +66 -0
  209. data/lib/active_support/number_helper.rb +105 -68
  210. data/lib/active_support/option_merger.rb +24 -4
  211. data/lib/active_support/ordered_hash.rb +7 -5
  212. data/lib/active_support/ordered_options.rb +27 -5
  213. data/lib/active_support/parameter_filter.rb +128 -0
  214. data/lib/active_support/per_thread_registry.rb +9 -4
  215. data/lib/active_support/proxy_object.rb +2 -0
  216. data/lib/active_support/rails.rb +10 -8
  217. data/lib/active_support/railtie.rb +43 -9
  218. data/lib/active_support/reloader.rb +130 -0
  219. data/lib/active_support/rescuable.rb +108 -53
  220. data/lib/active_support/security_utils.rb +15 -11
  221. data/lib/active_support/string_inquirer.rb +11 -4
  222. data/lib/active_support/subscriber.rb +74 -30
  223. data/lib/active_support/tagged_logging.rb +25 -13
  224. data/lib/active_support/test_case.rb +107 -44
  225. data/lib/active_support/testing/assertions.rb +151 -20
  226. data/lib/active_support/testing/autorun.rb +4 -2
  227. data/lib/active_support/testing/constant_lookup.rb +2 -1
  228. data/lib/active_support/testing/declarative.rb +3 -1
  229. data/lib/active_support/testing/deprecation.rb +13 -10
  230. data/lib/active_support/testing/file_fixtures.rb +38 -0
  231. data/lib/active_support/testing/isolation.rb +35 -26
  232. data/lib/active_support/testing/method_call_assertions.rb +70 -0
  233. data/lib/active_support/testing/parallelization.rb +134 -0
  234. data/lib/active_support/testing/setup_and_teardown.rb +13 -8
  235. data/lib/active_support/testing/stream.rb +43 -0
  236. data/lib/active_support/testing/tagged_logging.rb +3 -1
  237. data/lib/active_support/testing/time_helpers.rb +84 -20
  238. data/lib/active_support/time.rb +14 -12
  239. data/lib/active_support/time_with_zone.rb +179 -39
  240. data/lib/active_support/values/time_zone.rb +203 -63
  241. data/lib/active_support/version.rb +3 -1
  242. data/lib/active_support/xml_mini/jdom.rb +116 -115
  243. data/lib/active_support/xml_mini/libxml.rb +16 -13
  244. data/lib/active_support/xml_mini/libxmlsax.rb +15 -14
  245. data/lib/active_support/xml_mini/nokogiri.rb +14 -12
  246. data/lib/active_support/xml_mini/nokogirisax.rb +14 -13
  247. data/lib/active_support/xml_mini/rexml.rb +11 -9
  248. data/lib/active_support/xml_mini.rb +38 -46
  249. data/lib/active_support.rb +13 -11
  250. metadata +84 -26
  251. data/lib/active_support/concurrency/latch.rb +0 -27
  252. data/lib/active_support/core_ext/big_decimal/yaml_conversions.rb +0 -16
  253. data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -45
  254. data/lib/active_support/core_ext/date_time/zones.rb +0 -6
  255. data/lib/active_support/core_ext/kernel/agnostics.rb +0 -11
  256. data/lib/active_support/core_ext/kernel/debugger.rb +0 -10
  257. data/lib/active_support/core_ext/module/method_transplanting.rb +0 -13
  258. data/lib/active_support/core_ext/module/qualified_const.rb +0 -52
  259. data/lib/active_support/core_ext/object/itself.rb +0 -15
  260. data/lib/active_support/core_ext/struct.rb +0 -6
  261. data/lib/active_support/core_ext/thread.rb +0 -86
  262. data/lib/active_support/core_ext/time/marshal.rb +0 -30
  263. data/lib/active_support/values/unicode_tables.dat +0 -0
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # in case active_support/inflector is required without the rest of active_support
2
- require 'active_support/inflector/inflections'
3
- require 'active_support/inflector/transliterate'
4
- require 'active_support/inflector/methods'
4
+ require "active_support/inflector/inflections"
5
+ require "active_support/inflector/transliterate"
6
+ require "active_support/inflector/methods"
5
7
 
6
- require 'active_support/inflections'
7
- require 'active_support/core_ext/string/inflections'
8
+ require "active_support/inflections"
9
+ require "active_support/core_ext/string/inflections"
@@ -1,6 +1,8 @@
1
- require 'active_support/core_ext/module/attribute_accessors'
2
- require 'active_support/core_ext/module/delegation'
3
- require 'json'
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/module/attribute_accessors"
4
+ require "active_support/core_ext/module/delegation"
5
+ require "json"
4
6
 
5
7
  module ActiveSupport
6
8
  # Look for and parse json strings that look like ISO 8601 times.
@@ -8,21 +10,16 @@ module ActiveSupport
8
10
 
9
11
  module JSON
10
12
  # matches YAML-formatted dates
11
- DATE_REGEX = /^(?:\d{4}-\d{2}-\d{2}|\d{4}-\d{1,2}-\d{1,2}[T \t]+\d{1,2}:\d{2}:\d{2}(\.[0-9]*)?(([ \t]*)Z|[-+]\d{2}?(:\d{2})?))$/
12
-
13
+ DATE_REGEX = /^\d{4}-\d{2}-\d{2}$/
14
+ DATETIME_REGEX = /^(?:\d{4}-\d{2}-\d{2}|\d{4}-\d{1,2}-\d{1,2}[T \t]+\d{1,2}:\d{2}:\d{2}(\.[0-9]*)?(([ \t]*)Z|[-+]\d{2}?(:\d{2})?)?)$/
15
+
13
16
  class << self
14
17
  # Parses a JSON string (JavaScript Object Notation) into a hash.
15
18
  # See http://www.json.org for more info.
16
19
  #
17
20
  # ActiveSupport::JSON.decode("{\"team\":\"rails\",\"players\":\"36\"}")
18
21
  # => {"team" => "rails", "players" => "36"}
19
- def decode(json, options = {})
20
- if options.present?
21
- raise ArgumentError, "In Rails 4.1, ActiveSupport::JSON.decode no longer " \
22
- "accepts an options hash for MultiJSON. MultiJSON reached its end of life " \
23
- "and has been removed."
24
- end
25
-
22
+ def decode(json)
26
23
  data = ::JSON.parse(json, quirks_mode: true)
27
24
 
28
25
  if ActiveSupport.parse_json_times
@@ -47,27 +44,32 @@ module ActiveSupport
47
44
  end
48
45
 
49
46
  private
50
-
51
- def convert_dates_from(data)
52
- case data
53
- when nil
54
- nil
55
- when DATE_REGEX
56
- begin
57
- DateTime.parse(data)
58
- rescue ArgumentError
47
+ def convert_dates_from(data)
48
+ case data
49
+ when nil
50
+ nil
51
+ when DATE_REGEX
52
+ begin
53
+ Date.parse(data)
54
+ rescue ArgumentError
55
+ data
56
+ end
57
+ when DATETIME_REGEX
58
+ begin
59
+ Time.zone.parse(data)
60
+ rescue ArgumentError
61
+ data
62
+ end
63
+ when Array
64
+ data.map! { |d| convert_dates_from(d) }
65
+ when Hash
66
+ data.each do |key, value|
67
+ data[key] = convert_dates_from(value)
68
+ end
69
+ else
59
70
  data
60
71
  end
61
- when Array
62
- data.map! { |d| convert_dates_from(d) }
63
- when Hash
64
- data.each do |key, value|
65
- data[key] = convert_dates_from(value)
66
- end
67
- else
68
- data
69
72
  end
70
- end
71
73
  end
72
74
  end
73
75
  end
@@ -1,15 +1,15 @@
1
- require 'active_support/core_ext/object/json'
2
- require 'active_support/core_ext/module/delegation'
3
- require 'active_support/deprecation'
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/object/json"
4
+ require "active_support/core_ext/module/delegation"
4
5
 
5
6
  module ActiveSupport
6
7
  class << self
7
8
  delegate :use_standard_json_time_format, :use_standard_json_time_format=,
8
9
  :time_precision, :time_precision=,
9
10
  :escape_html_entities_in_json, :escape_html_entities_in_json=,
10
- :encode_big_decimal_as_string, :encode_big_decimal_as_string=,
11
11
  :json_encoder, :json_encoder=,
12
- :to => :'ActiveSupport::JSON::Encoding'
12
+ to: :'ActiveSupport::JSON::Encoding'
13
13
  end
14
14
 
15
15
  module JSON
@@ -42,9 +42,9 @@ module ActiveSupport
42
42
  ESCAPED_CHARS = {
43
43
  "\u2028" => '\u2028',
44
44
  "\u2029" => '\u2029',
45
- '>' => '\u003e',
46
- '<' => '\u003c',
47
- '&' => '\u0026',
45
+ ">" => '\u003e',
46
+ "<" => '\u003c',
47
+ "&" => '\u0026',
48
48
  }
49
49
 
50
50
  ESCAPE_REGEX_WITH_HTML_ENTITIES = /[\u2028\u2029><&]/u
@@ -54,9 +54,13 @@ module ActiveSupport
54
54
  class EscapedString < String #:nodoc:
55
55
  def to_json(*)
56
56
  if Encoding.escape_html_entities_in_json
57
- super.gsub ESCAPE_REGEX_WITH_HTML_ENTITIES, ESCAPED_CHARS
57
+ s = super
58
+ s.gsub! ESCAPE_REGEX_WITH_HTML_ENTITIES, ESCAPED_CHARS
59
+ s
58
60
  else
59
- super.gsub ESCAPE_REGEX_WITHOUT_HTML_ENTITIES, ESCAPED_CHARS
61
+ s = super
62
+ s.gsub! ESCAPE_REGEX_WITHOUT_HTML_ENTITIES, ESCAPED_CHARS
63
+ s
60
64
  end
61
65
  end
62
66
 
@@ -70,7 +74,8 @@ module ActiveSupport
70
74
  :ESCAPE_REGEX_WITHOUT_HTML_ENTITIES, :EscapedString
71
75
 
72
76
  # Convert an object into a "JSON-ready" representation composed of
73
- # primitives like Hash, Array, String, Numeric, and true/false/nil.
77
+ # primitives like Hash, Array, String, Numeric,
78
+ # and +true+/+false+/+nil+.
74
79
  # Recursively calls #as_json to the object to recursively build a
75
80
  # fully JSON-ready object.
76
81
  #
@@ -86,7 +91,7 @@ module ActiveSupport
86
91
  when String
87
92
  EscapedString.new(value)
88
93
  when Numeric, NilClass, TrueClass, FalseClass
89
- value
94
+ value.as_json
90
95
  when Hash
91
96
  Hash[value.map { |k, v| [jsonify(k), jsonify(v)] }]
92
97
  when Array
@@ -118,54 +123,6 @@ module ActiveSupport
118
123
  # Sets the encoder used by Rails to encode Ruby objects into JSON strings
119
124
  # in +Object#to_json+ and +ActiveSupport::JSON.encode+.
120
125
  attr_accessor :json_encoder
121
-
122
- def encode_big_decimal_as_string=(as_string)
123
- message = \
124
- "The JSON encoder in Rails 4.1 no longer supports encoding BigDecimals as JSON numbers. Instead, " \
125
- "the new encoder will always encode them as strings.\n\n" \
126
- "You are seeing this error because you have 'active_support.encode_big_decimal_as_string' in " \
127
- "your configuration file. If you have been setting this to true, you can safely remove it from " \
128
- "your configuration. Otherwise, you should add the 'activesupport-json_encoder' gem to your " \
129
- "Gemfile in order to restore this functionality."
130
-
131
- raise NotImplementedError, message
132
- end
133
-
134
- def encode_big_decimal_as_string
135
- message = \
136
- "The JSON encoder in Rails 4.1 no longer supports encoding BigDecimals as JSON numbers. Instead, " \
137
- "the new encoder will always encode them as strings.\n\n" \
138
- "You are seeing this error because you are trying to check the value of the related configuration, " \
139
- "`active_support.encode_big_decimal_as_string`. If your application depends on this option, you should " \
140
- "add the 'activesupport-json_encoder' gem to your Gemfile. For now, this option will always be true. " \
141
- "In the future, it will be removed from Rails, so you should stop checking its value."
142
-
143
- ActiveSupport::Deprecation.warn message
144
-
145
- true
146
- end
147
-
148
- # Deprecate CircularReferenceError
149
- def const_missing(name)
150
- if name == :CircularReferenceError
151
- message = "The JSON encoder in Rails 4.1 no longer offers protection from circular references. " \
152
- "You are seeing this warning because you are rescuing from (or otherwise referencing) " \
153
- "ActiveSupport::Encoding::CircularReferenceError. In the future, this error will be " \
154
- "removed from Rails. You should remove these rescue blocks from your code and ensure " \
155
- "that your data structures are free of circular references so they can be properly " \
156
- "serialized into JSON.\n\n" \
157
- "For example, the following Hash contains a circular reference to itself:\n" \
158
- " h = {}\n" \
159
- " h['circular'] = h\n" \
160
- "In this case, calling h.to_json would not work properly."
161
-
162
- ActiveSupport::Deprecation.warn message
163
-
164
- SystemStackError
165
- else
166
- super
167
- end
168
- end
169
126
  end
170
127
 
171
128
  self.use_standard_json_time_format = true
@@ -1,2 +1,4 @@
1
- require 'active_support/json/decoding'
2
- require 'active_support/json/encoding'
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/json/decoding"
4
+ require "active_support/json/encoding"
@@ -1,8 +1,10 @@
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
9
  # This lets Rails applications have a single secure secret, but avoid reusing that
8
10
  # key in multiple incompatible contexts.
@@ -17,57 +19,23 @@ module ActiveSupport
17
19
  # Returns a derived key suitable for use. The default key_size is chosen
18
20
  # to be compatible with the default settings of ActiveSupport::MessageVerifier.
19
21
  # i.e. OpenSSL::Digest::SHA1#block_length
20
- def generate_key(salt, key_size=64)
22
+ def generate_key(salt, key_size = 64)
21
23
  OpenSSL::PKCS5.pbkdf2_hmac_sha1(@secret, salt, @iterations, key_size)
22
24
  end
23
25
  end
24
26
 
25
27
  # CachingKeyGenerator is a wrapper around KeyGenerator which allows users to avoid
26
28
  # re-executing the key generation process when it's called using the same salt and
27
- # key_size
29
+ # key_size.
28
30
  class CachingKeyGenerator
29
31
  def initialize(key_generator)
30
32
  @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)
33
+ @cache_keys = Concurrent::Map.new
39
34
  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
48
- end
49
-
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 integrity hash " \
61
- "for cookie session data. Set a secret_key_base of at least " \
62
- "#{SECRET_MIN_LENGTH} characters in config/secrets.yml."
63
- end
64
35
 
65
- if secret.length < SECRET_MIN_LENGTH
66
- raise ArgumentError, "Secret should be something secure, " \
67
- "like \"#{SecureRandom.hex(16)}\". The value you " \
68
- "provided, \"#{secret}\", is shorter than the minimum length " \
69
- "of #{SECRET_MIN_LENGTH} characters."
70
- end
36
+ # Returns a derived key suitable for use.
37
+ def generate_key(*args)
38
+ @cache_keys[args.join] ||= @key_generator.generate_key(*args)
71
39
  end
72
40
  end
73
41
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveSupport
2
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
@@ -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
+ }
@@ -106,6 +106,8 @@ en:
106
106
  mb: "MB"
107
107
  gb: "GB"
108
108
  tb: "TB"
109
+ pb: "PB"
110
+ eb: "EB"
109
111
  # Used in NumberHelper.number_to_human()
110
112
  decimal_units:
111
113
  format: "%n %u"
@@ -1,6 +1,8 @@
1
- require 'active_support/log_subscriber'
2
- require 'active_support/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,36 @@ 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
+ # After configured, whenever a <tt>"sql.active_record"</tt> notification is published,
33
+ # it will properly dispatch the event
34
+ # (<tt>ActiveSupport::Notifications::Event</tt>) to the sql method.
35
+ #
36
+ # Being an <tt>ActiveSupport::Notifications</tt> consumer,
37
+ # <tt>ActiveSupport::LogSubscriber</tt> exposes a simple interface to check if
38
+ # instrumented code raises an exception. It is common to log a different
39
+ # message in case of an error, and this can be achieved by extending
40
+ # the previous example:
41
+ #
42
+ # module ActiveRecord
43
+ # class LogSubscriber < ActiveSupport::LogSubscriber
44
+ # def sql(event)
45
+ # exception = event.payload[:exception]
46
+ #
47
+ # if exception
48
+ # exception_object = event.payload[:exception_object]
49
+ #
50
+ # error "[ERROR] #{event.payload[:name]}: #{exception.join(', ')} " \
51
+ # "(#{exception_object.backtrace.first})"
52
+ # else
53
+ # # standard logger code
54
+ # end
55
+ # end
56
+ # end
57
+ # end
33
58
  #
34
59
  # 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.
60
+ # flushes all logs when the request finishes
61
+ # (via <tt>action_dispatch.callback</tt> notification) in a Rails environment.
37
62
  class LogSubscriber < Subscriber
38
63
  # Embed in a String to clear all previous ANSI sequences.
39
64
  CLEAR = "\e[0m"
@@ -49,8 +74,7 @@ module ActiveSupport
49
74
  CYAN = "\e[36m"
50
75
  WHITE = "\e[37m"
51
76
 
52
- mattr_accessor :colorize_logging
53
- self.colorize_logging = true
77
+ mattr_accessor :colorize_logging, default: true
54
78
 
55
79
  class << self
56
80
  def logger
@@ -81,12 +105,13 @@ module ActiveSupport
81
105
 
82
106
  def finish(name, id, payload)
83
107
  super if logger
84
- rescue Exception => e
85
- logger.error "Could not log #{name.inspect} event. #{e.class}: #{e.message} #{e.backtrace}"
108
+ rescue => e
109
+ if logger
110
+ logger.error "Could not log #{name.inspect} event. #{e.class}: #{e.message} #{e.backtrace}"
111
+ end
86
112
  end
87
113
 
88
- protected
89
-
114
+ private
90
115
  %w(info debug warn error fatal unknown).each do |level|
91
116
  class_eval <<-METHOD, __FILE__, __LINE__ + 1
92
117
  def #{level}(progname = nil, &block)
@@ -95,11 +120,11 @@ module ActiveSupport
95
120
  METHOD
96
121
  end
97
122
 
98
- # Set color by using a string or one of the defined constants. If a third
123
+ # Set color by using a symbol or one of the defined constants. If a third
99
124
  # option is set to +true+, it also adds bold to the string. This is based
100
125
  # on the Highline implementation and will automatically append CLEAR to the
101
126
  # end of the returned String.
102
- def color(text, color, bold=false)
127
+ def color(text, color, bold = false) # :doc:
103
128
  return text unless colorize_logging
104
129
  color = self.class.const_get(color.upcase) if color.is_a?(Symbol)
105
130
  bold = bold ? BOLD : ""