activesupport 4.2.11.1 → 5.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 (256) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +399 -440
  3. data/MIT-LICENSE +2 -2
  4. data/README.rdoc +4 -5
  5. data/lib/active_support/all.rb +5 -3
  6. data/lib/active_support/array_inquirer.rb +48 -0
  7. data/lib/active_support/backtrace_cleaner.rb +7 -5
  8. data/lib/active_support/benchmarkable.rb +6 -4
  9. data/lib/active_support/builder.rb +3 -1
  10. data/lib/active_support/cache/file_store.rb +41 -35
  11. data/lib/active_support/cache/mem_cache_store.rb +97 -88
  12. data/lib/active_support/cache/memory_store.rb +27 -30
  13. data/lib/active_support/cache/null_store.rb +7 -8
  14. data/lib/active_support/cache/redis_cache_store.rb +461 -0
  15. data/lib/active_support/cache/strategy/local_cache.rb +67 -34
  16. data/lib/active_support/cache/strategy/local_cache_middleware.rb +10 -9
  17. data/lib/active_support/cache.rb +287 -196
  18. data/lib/active_support/callbacks.rb +640 -590
  19. data/lib/active_support/concern.rb +11 -5
  20. data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +17 -0
  21. data/lib/active_support/concurrency/share_lock.rb +227 -0
  22. data/lib/active_support/configurable.rb +8 -5
  23. data/lib/active_support/core_ext/array/access.rb +29 -1
  24. data/lib/active_support/core_ext/array/conversions.rb +22 -18
  25. data/lib/active_support/core_ext/array/extract_options.rb +2 -0
  26. data/lib/active_support/core_ext/array/grouping.rb +11 -18
  27. data/lib/active_support/core_ext/array/inquiry.rb +19 -0
  28. data/lib/active_support/core_ext/array/prepend_and_append.rb +5 -3
  29. data/lib/active_support/core_ext/array/wrap.rb +7 -4
  30. data/lib/active_support/core_ext/array.rb +9 -6
  31. data/lib/active_support/core_ext/benchmark.rb +3 -1
  32. data/lib/active_support/core_ext/big_decimal/conversions.rb +10 -12
  33. data/lib/active_support/core_ext/big_decimal.rb +3 -1
  34. data/lib/active_support/core_ext/class/attribute.rb +41 -22
  35. data/lib/active_support/core_ext/class/attribute_accessors.rb +3 -1
  36. data/lib/active_support/core_ext/class/subclasses.rb +20 -6
  37. data/lib/active_support/core_ext/class.rb +4 -3
  38. data/lib/active_support/core_ext/date/acts_like.rb +3 -1
  39. data/lib/active_support/core_ext/date/blank.rb +14 -0
  40. data/lib/active_support/core_ext/date/calculations.rb +11 -9
  41. data/lib/active_support/core_ext/date/conversions.rb +25 -23
  42. data/lib/active_support/core_ext/date/zones.rb +4 -2
  43. data/lib/active_support/core_ext/date.rb +6 -4
  44. data/lib/active_support/core_ext/date_and_time/calculations.rb +170 -58
  45. data/lib/active_support/core_ext/date_and_time/compatibility.rb +4 -3
  46. data/lib/active_support/core_ext/date_and_time/zones.rb +12 -12
  47. data/lib/active_support/core_ext/date_time/acts_like.rb +4 -2
  48. data/lib/active_support/core_ext/date_time/blank.rb +14 -0
  49. data/lib/active_support/core_ext/date_time/calculations.rb +36 -18
  50. data/lib/active_support/core_ext/date_time/compatibility.rb +8 -6
  51. data/lib/active_support/core_ext/date_time/conversions.rb +16 -12
  52. data/lib/active_support/core_ext/date_time.rb +7 -5
  53. data/lib/active_support/core_ext/digest/uuid.rb +7 -5
  54. data/lib/active_support/core_ext/digest.rb +3 -0
  55. data/lib/active_support/core_ext/enumerable.rb +101 -33
  56. data/lib/active_support/core_ext/file/atomic.rb +38 -31
  57. data/lib/active_support/core_ext/file.rb +3 -1
  58. data/lib/active_support/core_ext/hash/compact.rb +14 -9
  59. data/lib/active_support/core_ext/hash/conversions.rb +62 -41
  60. data/lib/active_support/core_ext/hash/deep_merge.rb +9 -13
  61. data/lib/active_support/core_ext/hash/except.rb +11 -8
  62. data/lib/active_support/core_ext/hash/indifferent_access.rb +4 -3
  63. data/lib/active_support/core_ext/hash/keys.rb +33 -27
  64. data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
  65. data/lib/active_support/core_ext/hash/slice.rb +8 -8
  66. data/lib/active_support/core_ext/hash/transform_values.rb +14 -5
  67. data/lib/active_support/core_ext/hash.rb +11 -9
  68. data/lib/active_support/core_ext/integer/inflections.rb +3 -1
  69. data/lib/active_support/core_ext/integer/multiple.rb +2 -0
  70. data/lib/active_support/core_ext/integer/time.rb +11 -18
  71. data/lib/active_support/core_ext/integer.rb +5 -3
  72. data/lib/active_support/core_ext/kernel/agnostics.rb +2 -0
  73. data/lib/active_support/core_ext/kernel/concern.rb +5 -1
  74. data/lib/active_support/core_ext/kernel/reporting.rb +4 -84
  75. data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
  76. data/lib/active_support/core_ext/kernel.rb +6 -5
  77. data/lib/active_support/core_ext/load_error.rb +3 -22
  78. data/lib/active_support/core_ext/marshal.rb +8 -8
  79. data/lib/active_support/core_ext/module/aliasing.rb +6 -44
  80. data/lib/active_support/core_ext/module/anonymous.rb +12 -1
  81. data/lib/active_support/core_ext/module/attr_internal.rb +8 -9
  82. data/lib/active_support/core_ext/module/attribute_accessors.rb +43 -40
  83. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +150 -0
  84. data/lib/active_support/core_ext/module/concerning.rb +11 -12
  85. data/lib/active_support/core_ext/module/delegation.rb +99 -29
  86. data/lib/active_support/core_ext/module/deprecation.rb +4 -2
  87. data/lib/active_support/core_ext/module/introspection.rb +9 -9
  88. data/lib/active_support/core_ext/module/reachable.rb +5 -2
  89. data/lib/active_support/core_ext/module/redefine_method.rb +49 -0
  90. data/lib/active_support/core_ext/module/remove_method.rb +8 -3
  91. data/lib/active_support/core_ext/module.rb +14 -11
  92. data/lib/active_support/core_ext/name_error.rb +22 -2
  93. data/lib/active_support/core_ext/numeric/bytes.rb +22 -0
  94. data/lib/active_support/core_ext/numeric/conversions.rb +78 -81
  95. data/lib/active_support/core_ext/numeric/inquiry.rb +28 -0
  96. data/lib/active_support/core_ext/numeric/time.rb +35 -23
  97. data/lib/active_support/core_ext/numeric.rb +6 -3
  98. data/lib/active_support/core_ext/object/acts_like.rb +12 -1
  99. data/lib/active_support/core_ext/object/blank.rb +27 -2
  100. data/lib/active_support/core_ext/object/conversions.rb +6 -4
  101. data/lib/active_support/core_ext/object/deep_dup.rb +13 -4
  102. data/lib/active_support/core_ext/object/duplicable.rb +41 -14
  103. data/lib/active_support/core_ext/object/inclusion.rb +5 -3
  104. data/lib/active_support/core_ext/object/instance_variables.rb +3 -1
  105. data/lib/active_support/core_ext/object/json.rb +49 -19
  106. data/lib/active_support/core_ext/object/to_param.rb +3 -1
  107. data/lib/active_support/core_ext/object/to_query.rb +10 -5
  108. data/lib/active_support/core_ext/object/try.rb +69 -21
  109. data/lib/active_support/core_ext/object/with_options.rb +16 -3
  110. data/lib/active_support/core_ext/object.rb +14 -13
  111. data/lib/active_support/core_ext/range/compare_range.rb +61 -0
  112. data/lib/active_support/core_ext/range/conversions.rb +27 -7
  113. data/lib/active_support/core_ext/range/each.rb +19 -17
  114. data/lib/active_support/core_ext/range/include_range.rb +2 -22
  115. data/lib/active_support/core_ext/range/include_time_with_zone.rb +23 -0
  116. data/lib/active_support/core_ext/range/overlaps.rb +2 -0
  117. data/lib/active_support/core_ext/range.rb +7 -4
  118. data/lib/active_support/core_ext/regexp.rb +6 -0
  119. data/lib/active_support/core_ext/securerandom.rb +25 -0
  120. data/lib/active_support/core_ext/string/access.rb +8 -6
  121. data/lib/active_support/core_ext/string/behavior.rb +3 -1
  122. data/lib/active_support/core_ext/string/conversions.rb +7 -4
  123. data/lib/active_support/core_ext/string/exclude.rb +2 -0
  124. data/lib/active_support/core_ext/string/filters.rb +6 -5
  125. data/lib/active_support/core_ext/string/indent.rb +6 -4
  126. data/lib/active_support/core_ext/string/inflections.rb +61 -24
  127. data/lib/active_support/core_ext/string/inquiry.rb +3 -1
  128. data/lib/active_support/core_ext/string/multibyte.rb +15 -7
  129. data/lib/active_support/core_ext/string/output_safety.rb +34 -38
  130. data/lib/active_support/core_ext/string/starts_ends_with.rb +2 -0
  131. data/lib/active_support/core_ext/string/strip.rb +4 -5
  132. data/lib/active_support/core_ext/string/zones.rb +4 -2
  133. data/lib/active_support/core_ext/string.rb +15 -13
  134. data/lib/active_support/core_ext/time/acts_like.rb +3 -1
  135. data/lib/active_support/core_ext/time/calculations.rb +85 -51
  136. data/lib/active_support/core_ext/time/compatibility.rb +4 -2
  137. data/lib/active_support/core_ext/time/conversions.rb +20 -13
  138. data/lib/active_support/core_ext/time/zones.rb +41 -7
  139. data/lib/active_support/core_ext/time.rb +7 -6
  140. data/lib/active_support/core_ext/uri.rb +6 -8
  141. data/lib/active_support/core_ext.rb +3 -1
  142. data/lib/active_support/current_attributes.rb +195 -0
  143. data/lib/active_support/dependencies/autoload.rb +2 -0
  144. data/lib/active_support/dependencies/interlock.rb +57 -0
  145. data/lib/active_support/dependencies.rb +152 -161
  146. data/lib/active_support/deprecation/behaviors.rb +44 -11
  147. data/lib/active_support/deprecation/constant_accessor.rb +52 -0
  148. data/lib/active_support/deprecation/instance_delegator.rb +17 -2
  149. data/lib/active_support/deprecation/method_wrappers.rb +66 -20
  150. data/lib/active_support/deprecation/proxy_wrappers.rb +56 -28
  151. data/lib/active_support/deprecation/reporting.rb +32 -12
  152. data/lib/active_support/deprecation.rb +12 -9
  153. data/lib/active_support/descendants_tracker.rb +2 -0
  154. data/lib/active_support/digest.rb +20 -0
  155. data/lib/active_support/duration/iso8601_parser.rb +125 -0
  156. data/lib/active_support/duration/iso8601_serializer.rb +55 -0
  157. data/lib/active_support/duration.rb +307 -35
  158. data/lib/active_support/encrypted_configuration.rb +49 -0
  159. data/lib/active_support/encrypted_file.rb +99 -0
  160. data/lib/active_support/evented_file_update_checker.rb +205 -0
  161. data/lib/active_support/execution_wrapper.rb +128 -0
  162. data/lib/active_support/executor.rb +8 -0
  163. data/lib/active_support/file_update_checker.rb +63 -37
  164. data/lib/active_support/gem_version.rb +6 -4
  165. data/lib/active_support/gzip.rb +7 -5
  166. data/lib/active_support/hash_with_indifferent_access.rb +123 -28
  167. data/lib/active_support/i18n.rb +8 -6
  168. data/lib/active_support/i18n_railtie.rb +37 -13
  169. data/lib/active_support/inflections.rb +13 -11
  170. data/lib/active_support/inflector/inflections.rb +61 -12
  171. data/lib/active_support/inflector/methods.rb +163 -136
  172. data/lib/active_support/inflector/transliterate.rb +48 -27
  173. data/lib/active_support/inflector.rb +7 -5
  174. data/lib/active_support/json/decoding.rb +16 -13
  175. data/lib/active_support/json/encoding.rb +11 -58
  176. data/lib/active_support/json.rb +4 -2
  177. data/lib/active_support/key_generator.rb +25 -25
  178. data/lib/active_support/lazy_load_hooks.rb +50 -20
  179. data/lib/active_support/locale/en.yml +2 -0
  180. data/lib/active_support/log_subscriber/test_helper.rb +14 -12
  181. data/lib/active_support/log_subscriber.rb +13 -10
  182. data/lib/active_support/logger.rb +8 -7
  183. data/lib/active_support/logger_silence.rb +6 -4
  184. data/lib/active_support/logger_thread_safe_level.rb +7 -5
  185. data/lib/active_support/message_encryptor.rb +168 -53
  186. data/lib/active_support/message_verifier.rb +150 -17
  187. data/lib/active_support/messages/metadata.rb +71 -0
  188. data/lib/active_support/messages/rotation_configuration.rb +22 -0
  189. data/lib/active_support/messages/rotator.rb +56 -0
  190. data/lib/active_support/multibyte/chars.rb +36 -23
  191. data/lib/active_support/multibyte/unicode.rb +100 -96
  192. data/lib/active_support/multibyte.rb +4 -2
  193. data/lib/active_support/notifications/fanout.rb +11 -9
  194. data/lib/active_support/notifications/instrumenter.rb +27 -7
  195. data/lib/active_support/notifications.rb +11 -7
  196. data/lib/active_support/number_helper/number_converter.rb +13 -11
  197. data/lib/active_support/number_helper/number_to_currency_converter.rb +9 -9
  198. data/lib/active_support/number_helper/number_to_delimited_converter.rb +9 -3
  199. data/lib/active_support/number_helper/number_to_human_converter.rb +11 -9
  200. data/lib/active_support/number_helper/number_to_human_size_converter.rb +9 -8
  201. data/lib/active_support/number_helper/number_to_percentage_converter.rb +3 -1
  202. data/lib/active_support/number_helper/number_to_phone_converter.rb +13 -4
  203. data/lib/active_support/number_helper/number_to_rounded_converter.rb +23 -56
  204. data/lib/active_support/number_helper/rounding_helper.rb +66 -0
  205. data/lib/active_support/number_helper.rb +94 -68
  206. data/lib/active_support/option_merger.rb +3 -1
  207. data/lib/active_support/ordered_hash.rb +6 -4
  208. data/lib/active_support/ordered_options.rb +23 -5
  209. data/lib/active_support/per_thread_registry.rb +9 -4
  210. data/lib/active_support/proxy_object.rb +2 -0
  211. data/lib/active_support/rails.rb +16 -8
  212. data/lib/active_support/railtie.rb +43 -9
  213. data/lib/active_support/reloader.rb +131 -0
  214. data/lib/active_support/rescuable.rb +108 -53
  215. data/lib/active_support/security_utils.rb +15 -11
  216. data/lib/active_support/string_inquirer.rb +11 -3
  217. data/lib/active_support/subscriber.rb +21 -16
  218. data/lib/active_support/tagged_logging.rb +14 -11
  219. data/lib/active_support/test_case.rb +19 -47
  220. data/lib/active_support/testing/assertions.rb +137 -20
  221. data/lib/active_support/testing/autorun.rb +4 -2
  222. data/lib/active_support/testing/constant_lookup.rb +2 -1
  223. data/lib/active_support/testing/declarative.rb +3 -1
  224. data/lib/active_support/testing/deprecation.rb +14 -10
  225. data/lib/active_support/testing/file_fixtures.rb +36 -0
  226. data/lib/active_support/testing/isolation.rb +34 -25
  227. data/lib/active_support/testing/method_call_assertions.rb +43 -0
  228. data/lib/active_support/testing/setup_and_teardown.rb +13 -8
  229. data/lib/active_support/testing/stream.rb +44 -0
  230. data/lib/active_support/testing/tagged_logging.rb +3 -1
  231. data/lib/active_support/testing/time_helpers.rb +81 -15
  232. data/lib/active_support/time.rb +14 -12
  233. data/lib/active_support/time_with_zone.rb +169 -39
  234. data/lib/active_support/values/time_zone.rb +196 -61
  235. data/lib/active_support/values/unicode_tables.dat +0 -0
  236. data/lib/active_support/version.rb +3 -1
  237. data/lib/active_support/xml_mini/jdom.rb +116 -114
  238. data/lib/active_support/xml_mini/libxml.rb +16 -13
  239. data/lib/active_support/xml_mini/libxmlsax.rb +15 -14
  240. data/lib/active_support/xml_mini/nokogiri.rb +14 -12
  241. data/lib/active_support/xml_mini/nokogirisax.rb +14 -13
  242. data/lib/active_support/xml_mini/rexml.rb +11 -9
  243. data/lib/active_support/xml_mini.rb +37 -37
  244. data/lib/active_support.rb +12 -11
  245. metadata +54 -24
  246. data/lib/active_support/concurrency/latch.rb +0 -27
  247. data/lib/active_support/core_ext/big_decimal/yaml_conversions.rb +0 -16
  248. data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -45
  249. data/lib/active_support/core_ext/date_time/zones.rb +0 -6
  250. data/lib/active_support/core_ext/kernel/debugger.rb +0 -10
  251. data/lib/active_support/core_ext/module/method_transplanting.rb +0 -13
  252. data/lib/active_support/core_ext/module/qualified_const.rb +0 -52
  253. data/lib/active_support/core_ext/object/itself.rb +0 -15
  254. data/lib/active_support/core_ext/struct.rb +0 -6
  255. data/lib/active_support/core_ext/thread.rb +0 -86
  256. data/lib/active_support/core_ext/time/marshal.rb +0 -30
@@ -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
@@ -54,7 +51,13 @@ module ActiveSupport
54
51
  nil
55
52
  when DATE_REGEX
56
53
  begin
57
- DateTime.parse(data)
54
+ Date.parse(data)
55
+ rescue ArgumentError
56
+ data
57
+ end
58
+ when DATETIME_REGEX
59
+ begin
60
+ Time.zone.parse(data)
58
61
  rescue ArgumentError
59
62
  data
60
63
  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
@@ -70,7 +70,8 @@ module ActiveSupport
70
70
  :ESCAPE_REGEX_WITHOUT_HTML_ENTITIES, :EscapedString
71
71
 
72
72
  # Convert an object into a "JSON-ready" representation composed of
73
- # primitives like Hash, Array, String, Numeric, and true/false/nil.
73
+ # primitives like Hash, Array, String, Numeric,
74
+ # and +true+/+false+/+nil+.
74
75
  # Recursively calls #as_json to the object to recursively build a
75
76
  # fully JSON-ready object.
76
77
  #
@@ -86,7 +87,7 @@ module ActiveSupport
86
87
  when String
87
88
  EscapedString.new(value)
88
89
  when Numeric, NilClass, TrueClass, FalseClass
89
- value
90
+ value.as_json
90
91
  when Hash
91
92
  Hash[value.map { |k, v| [jsonify(k), jsonify(v)] }]
92
93
  when Array
@@ -118,54 +119,6 @@ module ActiveSupport
118
119
  # Sets the encoder used by Rails to encode Ruby objects into JSON strings
119
120
  # in +Object#to_json+ and +ActiveSupport::JSON.encode+.
120
121
  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
122
  end
170
123
 
171
124
  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,25 +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
33
+ @cache_keys = Concurrent::Map.new
32
34
  end
33
35
 
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)
36
+ # Returns a derived key suitable for use.
37
+ def generate_key(*args)
38
+ @cache_keys[args.join] ||= @key_generator.generate_key(*args)
39
39
  end
40
40
  end
41
41
 
@@ -53,21 +53,21 @@ module ActiveSupport
53
53
 
54
54
  private
55
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
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 via `bin/rails credentials:edit`."
63
+ end
64
64
 
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."
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
70
71
  end
71
- end
72
72
  end
73
73
  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,62 @@ 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
+
58
+ def with_execution_control(name, block, once)
59
+ unless @run_once[name].include?(block)
60
+ @run_once[name] << block if once
61
+
62
+ yield
63
+ end
64
+ end
65
+
66
+ def execute_hook(name, base, options, block)
67
+ with_execution_control(name, block, options[:run_once]) do
68
+ if options[:yield]
69
+ block.call(base)
70
+ else
71
+ base.instance_eval(&block)
72
+ end
73
+ end
74
+ end
47
75
  end
76
+
77
+ extend LazyLoadHooks
48
78
  end
@@ -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,6 +1,8 @@
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
8
  # ActiveSupport::LogSubscriber is an object set to consume
@@ -49,8 +51,7 @@ module ActiveSupport
49
51
  CYAN = "\e[36m"
50
52
  WHITE = "\e[37m"
51
53
 
52
- mattr_accessor :colorize_logging
53
- self.colorize_logging = true
54
+ mattr_accessor :colorize_logging, default: true
54
55
 
55
56
  class << self
56
57
  def logger
@@ -81,11 +82,13 @@ module ActiveSupport
81
82
 
82
83
  def finish(name, id, payload)
83
84
  super if logger
84
- rescue Exception => e
85
- logger.error "Could not log #{name.inspect} event. #{e.class}: #{e.message} #{e.backtrace}"
85
+ rescue => e
86
+ if logger
87
+ logger.error "Could not log #{name.inspect} event. #{e.class}: #{e.message} #{e.backtrace}"
88
+ end
86
89
  end
87
90
 
88
- protected
91
+ private
89
92
 
90
93
  %w(info debug warn error fatal unknown).each do |level|
91
94
  class_eval <<-METHOD, __FILE__, __LINE__ + 1
@@ -95,11 +98,11 @@ module ActiveSupport
95
98
  METHOD
96
99
  end
97
100
 
98
- # Set color by using a string or one of the defined constants. If a third
101
+ # Set color by using a symbol or one of the defined constants. If a third
99
102
  # option is set to +true+, it also adds bold to the string. This is based
100
103
  # on the Highline implementation and will automatically append CLEAR to the
101
104
  # end of the returned String.
102
- def color(text, color, bold=false)
105
+ def color(text, color, bold = false) # :doc:
103
106
  return text unless colorize_logging
104
107
  color = self.class.const_get(color.upcase) if color.is_a?(Symbol)
105
108
  bold = bold ? BOLD : ""
@@ -1,7 +1,8 @@
1
- require 'active_support/core_ext/module/attribute_accessors'
2
- require 'active_support/logger_silence'
3
- require 'active_support/logger_thread_safe_level'
4
- 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"
5
6
 
6
7
  module ActiveSupport
7
8
  class Logger < ::Logger
@@ -58,16 +59,16 @@ module ActiveSupport
58
59
  end
59
60
 
60
61
  define_method(:silence) do |level = Logger::ERROR, &block|
61
- if logger.respond_to?(:silence) && logger.method(:silence).owner != ::Kernel
62
+ if logger.respond_to?(:silence)
62
63
  logger.silence(level) do
63
- if respond_to?(:silence) && method(:silence).owner != ::Kernel
64
+ if defined?(super)
64
65
  super(level, &block)
65
66
  else
66
67
  block.call(self)
67
68
  end
68
69
  end
69
70
  else
70
- if respond_to?(:silence) && method(:silence).owner != ::Kernel
71
+ if defined?(super)
71
72
  super(level, &block)
72
73
  else
73
74
  block.call(self)
@@ -1,12 +1,14 @@
1
- require 'active_support/concern'
2
- require 'thread_safe'
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+ require "active_support/core_ext/module/attribute_accessors"
5
+ require "concurrent"
3
6
 
4
7
  module LoggerSilence
5
8
  extend ActiveSupport::Concern
6
9
 
7
10
  included do
8
- cattr_accessor :silencer
9
- self.silencer = true
11
+ cattr_accessor :silencer, default: true
10
12
  end
11
13
 
12
14
  # Silences the logger for the duration of the block.
@@ -1,16 +1,18 @@
1
- require 'active_support/concern'
2
- require 'thread_safe'
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+ require "fiber"
3
5
 
4
6
  module ActiveSupport
5
- module LoggerThreadSafeLevel
7
+ module LoggerThreadSafeLevel # :nodoc:
6
8
  extend ActiveSupport::Concern
7
9
 
8
10
  def after_initialize
9
- @local_levels = ThreadSafe::Cache.new
11
+ @local_levels = Concurrent::Map.new(initial_capacity: 2)
10
12
  end
11
13
 
12
14
  def local_log_id
13
- Thread.current.__id__
15
+ Fiber.current.__id__
14
16
  end
15
17
 
16
18
  def local_level