activesupport 5.0.0 → 6.1.0

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 (268) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +343 -590
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +5 -4
  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 +11 -5
  8. data/lib/active_support/backtrace_cleaner.rb +33 -5
  9. data/lib/active_support/benchmarkable.rb +5 -3
  10. data/lib/active_support/builder.rb +3 -1
  11. data/lib/active_support/cache/file_store.rb +45 -53
  12. data/lib/active_support/cache/mem_cache_store.rb +81 -79
  13. data/lib/active_support/cache/memory_store.rb +69 -41
  14. data/lib/active_support/cache/null_store.rb +11 -4
  15. data/lib/active_support/cache/redis_cache_store.rb +493 -0
  16. data/lib/active_support/cache/strategy/local_cache.rb +74 -37
  17. data/lib/active_support/cache/strategy/local_cache_middleware.rb +10 -9
  18. data/lib/active_support/cache.rb +332 -161
  19. data/lib/active_support/callbacks.rb +657 -586
  20. data/lib/active_support/concern.rb +79 -6
  21. data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +35 -0
  22. data/lib/active_support/concurrency/share_lock.rb +59 -19
  23. data/lib/active_support/configurable.rb +15 -17
  24. data/lib/active_support/configuration_file.rb +46 -0
  25. data/lib/active_support/core_ext/array/access.rb +21 -7
  26. data/lib/active_support/core_ext/array/conversions.rb +20 -18
  27. data/lib/active_support/core_ext/array/extract.rb +21 -0
  28. data/lib/active_support/core_ext/array/extract_options.rb +2 -0
  29. data/lib/active_support/core_ext/array/grouping.rb +3 -1
  30. data/lib/active_support/core_ext/array/inquiry.rb +3 -1
  31. data/lib/active_support/core_ext/array/wrap.rb +2 -0
  32. data/lib/active_support/core_ext/array.rb +9 -7
  33. data/lib/active_support/core_ext/benchmark.rb +5 -3
  34. data/lib/active_support/core_ext/big_decimal/conversions.rb +6 -6
  35. data/lib/active_support/core_ext/big_decimal.rb +3 -1
  36. data/lib/active_support/core_ext/class/attribute.rb +52 -49
  37. data/lib/active_support/core_ext/class/attribute_accessors.rb +3 -1
  38. data/lib/active_support/core_ext/class/subclasses.rb +18 -26
  39. data/lib/active_support/core_ext/class.rb +4 -2
  40. data/lib/active_support/core_ext/date/acts_like.rb +3 -1
  41. data/lib/active_support/core_ext/date/blank.rb +3 -1
  42. data/lib/active_support/core_ext/date/calculations.rb +16 -13
  43. data/lib/active_support/core_ext/date/conversions.rb +23 -21
  44. data/lib/active_support/core_ext/date/zones.rb +4 -2
  45. data/lib/active_support/core_ext/date.rb +7 -5
  46. data/lib/active_support/core_ext/date_and_time/calculations.rb +82 -53
  47. data/lib/active_support/core_ext/date_and_time/compatibility.rb +18 -5
  48. data/lib/active_support/core_ext/date_and_time/zones.rb +9 -9
  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 +3 -1
  51. data/lib/active_support/core_ext/date_time/calculations.rb +23 -11
  52. data/lib/active_support/core_ext/date_time/compatibility.rb +15 -2
  53. data/lib/active_support/core_ext/date_time/conversions.rb +14 -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 +165 -29
  58. data/lib/active_support/core_ext/file/atomic.rb +7 -5
  59. data/lib/active_support/core_ext/file.rb +3 -1
  60. data/lib/active_support/core_ext/hash/conversions.rb +40 -39
  61. data/lib/active_support/core_ext/hash/deep_merge.rb +8 -12
  62. data/lib/active_support/core_ext/hash/deep_transform_values.rb +46 -0
  63. data/lib/active_support/core_ext/hash/except.rb +4 -2
  64. data/lib/active_support/core_ext/hash/indifferent_access.rb +3 -2
  65. data/lib/active_support/core_ext/hash/keys.rb +9 -36
  66. data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
  67. data/lib/active_support/core_ext/hash/slice.rb +8 -29
  68. data/lib/active_support/core_ext/hash.rb +10 -9
  69. data/lib/active_support/core_ext/integer/inflections.rb +3 -1
  70. data/lib/active_support/core_ext/integer/multiple.rb +3 -1
  71. data/lib/active_support/core_ext/integer/time.rb +11 -18
  72. data/lib/active_support/core_ext/integer.rb +5 -3
  73. data/lib/active_support/core_ext/kernel/concern.rb +3 -1
  74. data/lib/active_support/core_ext/kernel/reporting.rb +3 -1
  75. data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
  76. data/lib/active_support/core_ext/kernel.rb +5 -4
  77. data/lib/active_support/core_ext/load_error.rb +2 -23
  78. data/lib/active_support/core_ext/marshal.rb +6 -2
  79. data/lib/active_support/core_ext/module/aliasing.rb +5 -48
  80. data/lib/active_support/core_ext/module/anonymous.rb +2 -0
  81. data/lib/active_support/core_ext/module/attr_internal.rb +7 -5
  82. data/lib/active_support/core_ext/module/attribute_accessors.rb +53 -59
  83. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +31 -24
  84. data/lib/active_support/core_ext/module/concerning.rb +16 -11
  85. data/lib/active_support/core_ext/module/delegation.rb +159 -44
  86. data/lib/active_support/core_ext/module/deprecation.rb +2 -0
  87. data/lib/active_support/core_ext/module/introspection.rb +23 -26
  88. data/lib/active_support/core_ext/module/redefine_method.rb +40 -0
  89. data/lib/active_support/core_ext/module/remove_method.rb +5 -23
  90. data/lib/active_support/core_ext/module.rb +13 -12
  91. data/lib/active_support/core_ext/name_error.rb +36 -2
  92. data/lib/active_support/core_ext/numeric/bytes.rb +2 -0
  93. data/lib/active_support/core_ext/numeric/conversions.rb +129 -134
  94. data/lib/active_support/core_ext/numeric/time.rb +18 -26
  95. data/lib/active_support/core_ext/numeric.rb +5 -4
  96. data/lib/active_support/core_ext/object/acts_like.rb +12 -1
  97. data/lib/active_support/core_ext/object/blank.rb +14 -2
  98. data/lib/active_support/core_ext/object/conversions.rb +6 -4
  99. data/lib/active_support/core_ext/object/deep_dup.rb +4 -2
  100. data/lib/active_support/core_ext/object/duplicable.rb +13 -62
  101. data/lib/active_support/core_ext/object/inclusion.rb +3 -1
  102. data/lib/active_support/core_ext/object/instance_variables.rb +2 -0
  103. data/lib/active_support/core_ext/object/json.rb +42 -15
  104. data/lib/active_support/core_ext/object/to_param.rb +3 -1
  105. data/lib/active_support/core_ext/object/to_query.rb +10 -5
  106. data/lib/active_support/core_ext/object/try.rb +20 -8
  107. data/lib/active_support/core_ext/object/with_options.rb +15 -2
  108. data/lib/active_support/core_ext/object.rb +14 -12
  109. data/lib/active_support/core_ext/range/compare_range.rb +82 -0
  110. data/lib/active_support/core_ext/range/conversions.rb +35 -25
  111. data/lib/active_support/core_ext/range/each.rb +5 -2
  112. data/lib/active_support/core_ext/range/include_time_with_zone.rb +28 -0
  113. data/lib/active_support/core_ext/range/overlaps.rb +2 -0
  114. data/lib/active_support/core_ext/range.rb +7 -4
  115. data/lib/active_support/core_ext/regexp.rb +10 -1
  116. data/lib/active_support/core_ext/securerandom.rb +28 -6
  117. data/lib/active_support/core_ext/string/access.rb +9 -18
  118. data/lib/active_support/core_ext/string/behavior.rb +2 -0
  119. data/lib/active_support/core_ext/string/conversions.rb +5 -2
  120. data/lib/active_support/core_ext/string/exclude.rb +2 -0
  121. data/lib/active_support/core_ext/string/filters.rb +47 -4
  122. data/lib/active_support/core_ext/string/indent.rb +6 -4
  123. data/lib/active_support/core_ext/string/inflections.rb +78 -29
  124. data/lib/active_support/core_ext/string/inquiry.rb +4 -1
  125. data/lib/active_support/core_ext/string/multibyte.rb +10 -5
  126. data/lib/active_support/core_ext/string/output_safety.rb +86 -31
  127. data/lib/active_support/core_ext/string/starts_ends_with.rb +4 -2
  128. data/lib/active_support/core_ext/string/strip.rb +5 -1
  129. data/lib/active_support/core_ext/string/zones.rb +4 -2
  130. data/lib/active_support/core_ext/string.rb +15 -13
  131. data/lib/active_support/core_ext/symbol/starts_ends_with.rb +14 -0
  132. data/lib/active_support/core_ext/symbol.rb +3 -0
  133. data/lib/active_support/core_ext/time/acts_like.rb +3 -1
  134. data/lib/active_support/core_ext/time/calculations.rb +117 -45
  135. data/lib/active_support/core_ext/time/compatibility.rb +13 -2
  136. data/lib/active_support/core_ext/time/conversions.rb +18 -12
  137. data/lib/active_support/core_ext/time/zones.rb +9 -7
  138. data/lib/active_support/core_ext/time.rb +7 -5
  139. data/lib/active_support/core_ext/uri.rb +12 -7
  140. data/lib/active_support/core_ext.rb +3 -2
  141. data/lib/active_support/current_attributes/test_helper.rb +13 -0
  142. data/lib/active_support/current_attributes.rb +208 -0
  143. data/lib/active_support/dependencies/autoload.rb +2 -0
  144. data/lib/active_support/dependencies/interlock.rb +7 -1
  145. data/lib/active_support/dependencies/zeitwerk_integration.rb +117 -0
  146. data/lib/active_support/dependencies.rb +172 -98
  147. data/lib/active_support/deprecation/behaviors.rb +45 -13
  148. data/lib/active_support/deprecation/constant_accessor.rb +52 -0
  149. data/lib/active_support/deprecation/disallowed.rb +56 -0
  150. data/lib/active_support/deprecation/instance_delegator.rb +16 -2
  151. data/lib/active_support/deprecation/method_wrappers.rb +32 -17
  152. data/lib/active_support/deprecation/proxy_wrappers.rb +35 -7
  153. data/lib/active_support/deprecation/reporting.rb +61 -16
  154. data/lib/active_support/deprecation.rb +17 -9
  155. data/lib/active_support/descendants_tracker.rb +61 -9
  156. data/lib/active_support/digest.rb +20 -0
  157. data/lib/active_support/duration/iso8601_parser.rb +67 -66
  158. data/lib/active_support/duration/iso8601_serializer.rb +25 -17
  159. data/lib/active_support/duration.rb +349 -46
  160. data/lib/active_support/encrypted_configuration.rb +45 -0
  161. data/lib/active_support/encrypted_file.rb +117 -0
  162. data/lib/active_support/environment_inquirer.rb +20 -0
  163. data/lib/active_support/evented_file_update_checker.rb +88 -112
  164. data/lib/active_support/execution_wrapper.rb +25 -13
  165. data/lib/active_support/executor.rb +3 -1
  166. data/lib/active_support/file_update_checker.rb +56 -51
  167. data/lib/active_support/fork_tracker.rb +62 -0
  168. data/lib/active_support/gem_version.rb +4 -2
  169. data/lib/active_support/gzip.rb +7 -5
  170. data/lib/active_support/hash_with_indifferent_access.rb +153 -49
  171. data/lib/active_support/i18n.rb +9 -6
  172. data/lib/active_support/i18n_railtie.rb +30 -20
  173. data/lib/active_support/inflections.rb +13 -11
  174. data/lib/active_support/inflector/inflections.rb +28 -15
  175. data/lib/active_support/inflector/methods.rb +120 -109
  176. data/lib/active_support/inflector/transliterate.rb +60 -25
  177. data/lib/active_support/inflector.rb +7 -5
  178. data/lib/active_support/json/decoding.rb +30 -29
  179. data/lib/active_support/json/encoding.rb +22 -11
  180. data/lib/active_support/json.rb +4 -2
  181. data/lib/active_support/key_generator.rb +6 -36
  182. data/lib/active_support/lazy_load_hooks.rb +53 -20
  183. data/lib/active_support/locale/en.rb +33 -0
  184. data/lib/active_support/locale/en.yml +7 -3
  185. data/lib/active_support/log_subscriber/test_helper.rb +11 -9
  186. data/lib/active_support/log_subscriber.rb +51 -18
  187. data/lib/active_support/logger.rb +9 -22
  188. data/lib/active_support/logger_silence.rb +14 -21
  189. data/lib/active_support/logger_thread_safe_level.rb +55 -8
  190. data/lib/active_support/message_encryptor.rb +170 -53
  191. data/lib/active_support/message_verifier.rb +91 -20
  192. data/lib/active_support/messages/metadata.rb +80 -0
  193. data/lib/active_support/messages/rotation_configuration.rb +23 -0
  194. data/lib/active_support/messages/rotator.rb +57 -0
  195. data/lib/active_support/multibyte/chars.rb +24 -78
  196. data/lib/active_support/multibyte/unicode.rb +21 -352
  197. data/lib/active_support/multibyte.rb +4 -2
  198. data/lib/active_support/notifications/fanout.rb +121 -19
  199. data/lib/active_support/notifications/instrumenter.rb +78 -14
  200. data/lib/active_support/notifications.rb +80 -12
  201. data/lib/active_support/number_helper/number_converter.rb +17 -16
  202. data/lib/active_support/number_helper/number_to_currency_converter.rb +6 -9
  203. data/lib/active_support/number_helper/number_to_delimited_converter.rb +5 -3
  204. data/lib/active_support/number_helper/number_to_human_converter.rb +13 -12
  205. data/lib/active_support/number_helper/number_to_human_size_converter.rb +11 -13
  206. data/lib/active_support/number_helper/number_to_percentage_converter.rb +5 -1
  207. data/lib/active_support/number_helper/number_to_phone_converter.rb +5 -4
  208. data/lib/active_support/number_helper/number_to_rounded_converter.rb +18 -55
  209. data/lib/active_support/number_helper/rounding_helper.rb +50 -0
  210. data/lib/active_support/number_helper.rb +45 -16
  211. data/lib/active_support/option_merger.rb +25 -4
  212. data/lib/active_support/ordered_hash.rb +6 -4
  213. data/lib/active_support/ordered_options.rb +23 -9
  214. data/lib/active_support/parameter_filter.rb +133 -0
  215. data/lib/active_support/per_thread_registry.rb +7 -5
  216. data/lib/active_support/proxy_object.rb +2 -0
  217. data/lib/active_support/rails.rb +8 -9
  218. data/lib/active_support/railtie.rb +62 -11
  219. data/lib/active_support/reloader.rb +12 -11
  220. data/lib/active_support/rescuable.rb +20 -11
  221. data/lib/active_support/secure_compare_rotator.rb +51 -0
  222. data/lib/active_support/security_utils.rb +26 -15
  223. data/lib/active_support/string_inquirer.rb +12 -3
  224. data/lib/active_support/subscriber.rb +77 -23
  225. data/lib/active_support/tagged_logging.rb +52 -17
  226. data/lib/active_support/test_case.rb +106 -29
  227. data/lib/active_support/testing/assertions.rb +144 -8
  228. data/lib/active_support/testing/autorun.rb +5 -10
  229. data/lib/active_support/testing/constant_lookup.rb +2 -1
  230. data/lib/active_support/testing/declarative.rb +3 -1
  231. data/lib/active_support/testing/deprecation.rb +4 -2
  232. data/lib/active_support/testing/file_fixtures.rb +4 -0
  233. data/lib/active_support/testing/isolation.rb +19 -24
  234. data/lib/active_support/testing/method_call_assertions.rb +31 -2
  235. data/lib/active_support/testing/parallelization/server.rb +78 -0
  236. data/lib/active_support/testing/parallelization/worker.rb +100 -0
  237. data/lib/active_support/testing/parallelization.rb +51 -0
  238. data/lib/active_support/testing/setup_and_teardown.rb +13 -8
  239. data/lib/active_support/testing/stream.rb +30 -29
  240. data/lib/active_support/testing/tagged_logging.rb +3 -1
  241. data/lib/active_support/testing/time_helpers.rb +125 -24
  242. data/lib/active_support/time.rb +14 -12
  243. data/lib/active_support/time_with_zone.rb +142 -55
  244. data/lib/active_support/values/time_zone.rb +160 -53
  245. data/lib/active_support/version.rb +3 -1
  246. data/lib/active_support/xml_mini/jdom.rb +115 -114
  247. data/lib/active_support/xml_mini/libxml.rb +15 -14
  248. data/lib/active_support/xml_mini/libxmlsax.rb +16 -18
  249. data/lib/active_support/xml_mini/nokogiri.rb +13 -13
  250. data/lib/active_support/xml_mini/nokogirisax.rb +15 -16
  251. data/lib/active_support/xml_mini/rexml.rb +18 -9
  252. data/lib/active_support/xml_mini.rb +44 -42
  253. data/lib/active_support.rb +19 -10
  254. metadata +79 -37
  255. data/lib/active_support/concurrency/latch.rb +0 -19
  256. data/lib/active_support/core_ext/array/prepend_and_append.rb +0 -7
  257. data/lib/active_support/core_ext/hash/compact.rb +0 -20
  258. data/lib/active_support/core_ext/hash/transform_values.rb +0 -29
  259. data/lib/active_support/core_ext/kernel/agnostics.rb +0 -11
  260. data/lib/active_support/core_ext/kernel/debugger.rb +0 -3
  261. data/lib/active_support/core_ext/module/method_transplanting.rb +0 -3
  262. data/lib/active_support/core_ext/module/qualified_const.rb +0 -70
  263. data/lib/active_support/core_ext/module/reachable.rb +0 -8
  264. data/lib/active_support/core_ext/numeric/inquiry.rb +0 -26
  265. data/lib/active_support/core_ext/range/include_range.rb +0 -23
  266. data/lib/active_support/core_ext/struct.rb +0 -3
  267. data/lib/active_support/core_ext/time/marshal.rb +0 -3
  268. data/lib/active_support/values/unicode_tables.dat +0 -0
@@ -1,6 +1,8 @@
1
- require 'libxml'
2
- require 'active_support/core_ext/object/blank'
3
- require 'stringio'
1
+ # frozen_string_literal: true
2
+
3
+ require "libxml"
4
+ require "active_support/core_ext/object/blank"
5
+ require "stringio"
4
6
 
5
7
  module ActiveSupport
6
8
  module XmlMini_LibXML #:nodoc:
@@ -11,18 +13,15 @@ module ActiveSupport
11
13
  # XML Document string or IO to parse
12
14
  def parse(data)
13
15
  if !data.respond_to?(:read)
14
- data = StringIO.new(data || '')
16
+ data = StringIO.new(data || "")
15
17
  end
16
18
 
17
- char = data.getc
18
- if char.nil?
19
+ if data.eof?
19
20
  {}
20
21
  else
21
- data.ungetc(char)
22
22
  LibXML::XML::Parser.io(data).parse.to_hash
23
23
  end
24
24
  end
25
-
26
25
  end
27
26
  end
28
27
 
@@ -35,20 +34,20 @@ module LibXML #:nodoc:
35
34
  end
36
35
 
37
36
  module Node #:nodoc:
38
- CONTENT_ROOT = '__content__'.freeze
37
+ CONTENT_ROOT = "__content__"
39
38
 
40
39
  # Convert XML document to hash.
41
40
  #
42
41
  # hash::
43
42
  # Hash to merge the converted element into.
44
- def to_hash(hash={})
43
+ def to_hash(hash = {})
45
44
  node_hash = {}
46
45
 
47
46
  # Insert node hash into parent hash correctly.
48
47
  case hash[name]
49
- when Array then hash[name] << node_hash
50
- when Hash then hash[name] = [hash[name], node_hash]
51
- when nil then hash[name] = node_hash
48
+ when Array then hash[name] << node_hash
49
+ when Hash then hash[name] = [hash[name], node_hash]
50
+ when nil then hash[name] = node_hash
52
51
  end
53
52
 
54
53
  # Handle child elements
@@ -56,7 +55,7 @@ module LibXML #:nodoc:
56
55
  if c.element?
57
56
  c.to_hash(node_hash)
58
57
  elsif c.text? || c.cdata?
59
- node_hash[CONTENT_ROOT] ||= ''
58
+ node_hash[CONTENT_ROOT] ||= +""
60
59
  node_hash[CONTENT_ROOT] << c.content
61
60
  end
62
61
  end
@@ -75,5 +74,7 @@ module LibXML #:nodoc:
75
74
  end
76
75
  end
77
76
 
77
+ # :enddoc:
78
+
78
79
  LibXML::XML::Document.include(LibXML::Conversions::Document)
79
80
  LibXML::XML::Node.include(LibXML::Conversions::Node)
@@ -1,6 +1,8 @@
1
- require 'libxml'
2
- require 'active_support/core_ext/object/blank'
3
- require 'stringio'
1
+ # frozen_string_literal: true
2
+
3
+ require "libxml"
4
+ require "active_support/core_ext/object/blank"
5
+ require "stringio"
4
6
 
5
7
  module ActiveSupport
6
8
  module XmlMini_LibXMLSAX #:nodoc:
@@ -9,11 +11,10 @@ module ActiveSupport
9
11
  # Class that will build the hash while the XML document
10
12
  # is being parsed using SAX events.
11
13
  class HashBuilder
12
-
13
14
  include LibXML::XML::SaxParser::Callbacks
14
15
 
15
- CONTENT_KEY = '__content__'.freeze
16
- HASH_SIZE_KEY = '__hash_size__'.freeze
16
+ CONTENT_KEY = "__content__"
17
+ HASH_SIZE_KEY = "__hash_size__"
17
18
 
18
19
  attr_reader :hash
19
20
 
@@ -22,7 +23,7 @@ module ActiveSupport
22
23
  end
23
24
 
24
25
  def on_start_document
25
- @hash = { CONTENT_KEY => '' }
26
+ @hash = { CONTENT_KEY => +"" }
26
27
  @hash_stack = [@hash]
27
28
  end
28
29
 
@@ -32,20 +33,20 @@ module ActiveSupport
32
33
  end
33
34
 
34
35
  def on_start_element(name, attrs = {})
35
- new_hash = { CONTENT_KEY => '' }.merge!(attrs)
36
+ new_hash = { CONTENT_KEY => +"" }.merge!(attrs)
36
37
  new_hash[HASH_SIZE_KEY] = new_hash.size + 1
37
38
 
38
39
  case current_hash[name]
39
- when Array then current_hash[name] << new_hash
40
- when Hash then current_hash[name] = [current_hash[name], new_hash]
41
- when nil then current_hash[name] = new_hash
40
+ when Array then current_hash[name] << new_hash
41
+ when Hash then current_hash[name] = [current_hash[name], new_hash]
42
+ when nil then current_hash[name] = new_hash
42
43
  end
43
44
 
44
45
  @hash_stack.push(new_hash)
45
46
  end
46
47
 
47
48
  def on_end_element(name)
48
- if current_hash.length > current_hash.delete(HASH_SIZE_KEY) && current_hash[CONTENT_KEY].blank? || current_hash[CONTENT_KEY] == ''
49
+ if current_hash.length > current_hash.delete(HASH_SIZE_KEY) && current_hash[CONTENT_KEY].blank? || current_hash[CONTENT_KEY] == ""
49
50
  current_hash.delete(CONTENT_KEY)
50
51
  end
51
52
  @hash_stack.pop
@@ -63,18 +64,15 @@ module ActiveSupport
63
64
 
64
65
  def parse(data)
65
66
  if !data.respond_to?(:read)
66
- data = StringIO.new(data || '')
67
+ data = StringIO.new(data || "")
67
68
  end
68
69
 
69
- char = data.getc
70
- if char.nil?
70
+ if data.eof?
71
71
  {}
72
72
  else
73
- data.ungetc(char)
74
-
75
73
  LibXML::XML::Error.set_handler(&LibXML::XML::Error::QUIET_HANDLER)
76
74
  parser = LibXML::XML::SaxParser.io(data)
77
- document = self.document_class.new
75
+ document = document_class.new
78
76
 
79
77
  parser.callbacks = document
80
78
  parser.parse
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
- require 'nokogiri'
4
+ require "nokogiri"
3
5
  rescue LoadError => e
4
6
  $stderr.puts "You don't have nokogiri installed in your application. Please add it to your Gemfile and run bundle install"
5
7
  raise e
6
8
  end
7
- require 'active_support/core_ext/object/blank'
8
- require 'stringio'
9
+ require "active_support/core_ext/object/blank"
10
+ require "stringio"
9
11
 
10
12
  module ActiveSupport
11
13
  module XmlMini_Nokogiri #:nodoc:
@@ -16,14 +18,12 @@ module ActiveSupport
16
18
  # XML Document string or IO to parse
17
19
  def parse(data)
18
20
  if !data.respond_to?(:read)
19
- data = StringIO.new(data || '')
21
+ data = StringIO.new(data || "")
20
22
  end
21
23
 
22
- char = data.getc
23
- if char.nil?
24
+ if data.eof?
24
25
  {}
25
26
  else
26
- data.ungetc(char)
27
27
  doc = Nokogiri::XML(data)
28
28
  raise doc.errors.first if doc.errors.length > 0
29
29
  doc.to_hash
@@ -38,20 +38,20 @@ module ActiveSupport
38
38
  end
39
39
 
40
40
  module Node #:nodoc:
41
- CONTENT_ROOT = '__content__'.freeze
41
+ CONTENT_ROOT = "__content__"
42
42
 
43
43
  # Convert XML document to hash.
44
44
  #
45
45
  # hash::
46
46
  # Hash to merge the converted element into.
47
- def to_hash(hash={})
47
+ def to_hash(hash = {})
48
48
  node_hash = {}
49
49
 
50
50
  # Insert node hash into parent hash correctly.
51
51
  case hash[name]
52
- when Array then hash[name] << node_hash
53
- when Hash then hash[name] = [hash[name], node_hash]
54
- when nil then hash[name] = node_hash
52
+ when Array then hash[name] << node_hash
53
+ when Hash then hash[name] = [hash[name], node_hash]
54
+ when nil then hash[name] = node_hash
55
55
  end
56
56
 
57
57
  # Handle child elements
@@ -59,7 +59,7 @@ module ActiveSupport
59
59
  if c.element?
60
60
  c.to_hash(node_hash)
61
61
  elsif c.text? || c.cdata?
62
- node_hash[CONTENT_ROOT] ||= ''
62
+ node_hash[CONTENT_ROOT] ||= +""
63
63
  node_hash[CONTENT_ROOT] << c.content
64
64
  end
65
65
  end
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
- require 'nokogiri'
4
+ require "nokogiri"
3
5
  rescue LoadError => e
4
6
  $stderr.puts "You don't have nokogiri installed in your application. Please add it to your Gemfile and run bundle install"
5
7
  raise e
6
8
  end
7
- require 'active_support/core_ext/object/blank'
8
- require 'stringio'
9
+ require "active_support/core_ext/object/blank"
10
+ require "stringio"
9
11
 
10
12
  module ActiveSupport
11
13
  module XmlMini_NokogiriSAX #:nodoc:
@@ -14,9 +16,8 @@ module ActiveSupport
14
16
  # Class that will build the hash while the XML document
15
17
  # is being parsed using SAX events.
16
18
  class HashBuilder < Nokogiri::XML::SAX::Document
17
-
18
- CONTENT_KEY = '__content__'.freeze
19
- HASH_SIZE_KEY = '__hash_size__'.freeze
19
+ CONTENT_KEY = "__content__"
20
+ HASH_SIZE_KEY = "__hash_size__"
20
21
 
21
22
  attr_reader :hash
22
23
 
@@ -38,20 +39,20 @@ module ActiveSupport
38
39
  end
39
40
 
40
41
  def start_element(name, attrs = [])
41
- new_hash = { CONTENT_KEY => '' }.merge!(Hash[attrs])
42
+ new_hash = { CONTENT_KEY => +"" }.merge!(Hash[attrs])
42
43
  new_hash[HASH_SIZE_KEY] = new_hash.size + 1
43
44
 
44
45
  case current_hash[name]
45
- when Array then current_hash[name] << new_hash
46
- when Hash then current_hash[name] = [current_hash[name], new_hash]
47
- when nil then current_hash[name] = new_hash
46
+ when Array then current_hash[name] << new_hash
47
+ when Hash then current_hash[name] = [current_hash[name], new_hash]
48
+ when nil then current_hash[name] = new_hash
48
49
  end
49
50
 
50
51
  @hash_stack.push(new_hash)
51
52
  end
52
53
 
53
54
  def end_element(name)
54
- if current_hash.length > current_hash.delete(HASH_SIZE_KEY) && current_hash[CONTENT_KEY].blank? || current_hash[CONTENT_KEY] == ''
55
+ if current_hash.length > current_hash.delete(HASH_SIZE_KEY) && current_hash[CONTENT_KEY].blank? || current_hash[CONTENT_KEY] == ""
55
56
  current_hash.delete(CONTENT_KEY)
56
57
  end
57
58
  @hash_stack.pop
@@ -69,15 +70,13 @@ module ActiveSupport
69
70
 
70
71
  def parse(data)
71
72
  if !data.respond_to?(:read)
72
- data = StringIO.new(data || '')
73
+ data = StringIO.new(data || "")
73
74
  end
74
75
 
75
- char = data.getc
76
- if char.nil?
76
+ if data.eof?
77
77
  {}
78
78
  else
79
- data.ungetc(char)
80
- document = self.document_class.new
79
+ document = document_class.new
81
80
  parser = Nokogiri::XML::SAX::Parser.new(document)
82
81
  parser.parse(data)
83
82
  document.hash
@@ -1,12 +1,14 @@
1
- require 'active_support/core_ext/kernel/reporting'
2
- require 'active_support/core_ext/object/blank'
3
- require 'stringio'
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/kernel/reporting"
4
+ require "active_support/core_ext/object/blank"
5
+ require "stringio"
4
6
 
5
7
  module ActiveSupport
6
8
  module XmlMini_REXML #:nodoc:
7
9
  extend self
8
10
 
9
- CONTENT_KEY = '__content__'.freeze
11
+ CONTENT_KEY = "__content__"
10
12
 
11
13
  # Parse an XML Document string or IO into a simple hash.
12
14
  #
@@ -17,13 +19,13 @@ module ActiveSupport
17
19
  # XML Document string or IO to parse
18
20
  def parse(data)
19
21
  if !data.respond_to?(:read)
20
- data = StringIO.new(data || '')
22
+ data = StringIO.new(data || "")
21
23
  end
22
24
 
23
25
  if data.eof?
24
26
  {}
25
27
  else
26
- silence_warnings { require 'rexml/document' } unless defined?(REXML::Document)
28
+ require_rexml unless defined?(REXML::Document)
27
29
  doc = REXML::Document.new(data)
28
30
 
29
31
  if doc.root
@@ -36,6 +38,13 @@ module ActiveSupport
36
38
  end
37
39
 
38
40
  private
41
+ def require_rexml
42
+ silence_warnings { require "rexml/document" }
43
+ rescue LoadError => e
44
+ $stderr.puts "You don't have rexml installed in your application. Please add it to your Gemfile and run bundle install"
45
+ raise e
46
+ end
47
+
39
48
  # Convert an XML element and merge into the hash
40
49
  #
41
50
  # hash::
@@ -55,7 +64,7 @@ module ActiveSupport
55
64
  hash = get_attributes(element)
56
65
 
57
66
  if element.has_elements?
58
- element.each_element {|child| merge_element!(hash, child, depth - 1) }
67
+ element.each_element { |child| merge_element!(hash, child, depth - 1) }
59
68
  merge_texts!(hash, element) unless empty_content?(element)
60
69
  hash
61
70
  else
@@ -74,7 +83,7 @@ module ActiveSupport
74
83
  hash
75
84
  else
76
85
  # must use value to prevent double-escaping
77
- texts = ''
86
+ texts = +""
78
87
  element.texts.each { |t| texts << t.value }
79
88
  merge!(hash, CONTENT_KEY, texts)
80
89
  end
@@ -113,7 +122,7 @@ module ActiveSupport
113
122
  # XML element to extract attributes from.
114
123
  def get_attributes(element)
115
124
  attributes = {}
116
- element.attributes.each { |n,v| attributes[n] = v }
125
+ element.attributes.each { |n, v| attributes[n] = v }
117
126
  attributes
118
127
  end
119
128
 
@@ -1,9 +1,12 @@
1
- require 'time'
2
- require 'base64'
3
- require 'bigdecimal'
4
- require 'active_support/core_ext/module/delegation'
5
- require 'active_support/core_ext/string/inflections'
6
- require 'active_support/core_ext/date_time/calculations'
1
+ # frozen_string_literal: true
2
+
3
+ require "time"
4
+ require "base64"
5
+ require "bigdecimal"
6
+ require "bigdecimal/util"
7
+ require "active_support/core_ext/module/delegation"
8
+ require "active_support/core_ext/string/inflections"
9
+ require "active_support/core_ext/date_time/calculations"
7
10
 
8
11
  module ActiveSupport
9
12
  # = XmlMini
@@ -20,11 +23,11 @@ module ActiveSupport
20
23
  attr_writer :original_filename, :content_type
21
24
 
22
25
  def original_filename
23
- @original_filename || 'untitled'
26
+ @original_filename || "untitled"
24
27
  end
25
28
 
26
29
  def content_type
27
- @content_type || 'application/octet-stream'
30
+ @content_type || "application/octet-stream"
28
31
  end
29
32
  end
30
33
 
@@ -46,10 +49,6 @@ module ActiveSupport
46
49
  "Array" => "array",
47
50
  "Hash" => "hash"
48
51
  }
49
-
50
- # No need to map these on Ruby 2.4+
51
- TYPE_NAMES["Fixnum"] = "integer" unless Fixnum == Integer
52
- TYPE_NAMES["Bignum"] = "integer" unless Bignum == Integer
53
52
  end
54
53
 
55
54
  FORMATTING = {
@@ -68,10 +67,16 @@ module ActiveSupport
68
67
  "datetime" => Proc.new { |time| Time.xmlschema(time).utc rescue ::DateTime.parse(time).utc },
69
68
  "integer" => Proc.new { |integer| integer.to_i },
70
69
  "float" => Proc.new { |float| float.to_f },
71
- "decimal" => Proc.new { |number| BigDecimal(number) },
70
+ "decimal" => Proc.new do |number|
71
+ if String === number
72
+ number.to_d
73
+ else
74
+ BigDecimal(number)
75
+ end
76
+ end,
72
77
  "boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.to_s.strip) },
73
78
  "string" => Proc.new { |string| string.to_s },
74
- "yaml" => Proc.new { |yaml| YAML::load(yaml) rescue yaml },
79
+ "yaml" => Proc.new { |yaml| YAML.load(yaml) rescue yaml },
75
80
  "base64Binary" => Proc.new { |bin| ::Base64.decode64(bin) },
76
81
  "binary" => Proc.new { |bin, entity| _parse_binary(bin, entity) },
77
82
  "file" => Proc.new { |file, entity| _parse_file(file, entity) }
@@ -86,7 +91,7 @@ module ActiveSupport
86
91
  attr_accessor :depth
87
92
  self.depth = 100
88
93
 
89
- delegate :parse, :to => :backend
94
+ delegate :parse, to: :backend
90
95
 
91
96
  def backend
92
97
  current_thread_backend || @backend
@@ -108,7 +113,7 @@ module ActiveSupport
108
113
 
109
114
  def to_tag(key, value, options)
110
115
  type_name = options.delete(:type)
111
- merged_options = options.merge(:root => key, :skip_instruct => true)
116
+ merged_options = options.merge(root: key, skip_instruct: true)
112
117
 
113
118
  if value.is_a?(::Method) || value.is_a?(::Proc)
114
119
  if value.arity == 1
@@ -126,7 +131,7 @@ module ActiveSupport
126
131
 
127
132
  key = rename_key(key.to_s, options)
128
133
 
129
- attributes = options[:skip_types] || type_name.nil? ? { } : { :type => type_name }
134
+ attributes = options[:skip_types] || type_name.nil? ? {} : { type: type_name }
130
135
  attributes[:nil] = true if value.nil?
131
136
 
132
137
  encoding = options[:encoding] || DEFAULT_ENCODINGS[type_name]
@@ -149,33 +154,30 @@ module ActiveSupport
149
154
  key
150
155
  end
151
156
 
152
- protected
153
-
154
- def _dasherize(key)
155
- # $2 must be a non-greedy regex for this to work
156
- left, middle, right = /\A(_*)(.*?)(_*)\Z/.match(key.strip)[1,3]
157
- "#{left}#{middle.tr('_ ', '--')}#{right}"
158
- end
159
-
160
- # TODO: Add support for other encodings
161
- def _parse_binary(bin, entity) #:nodoc:
162
- case entity['encoding']
163
- when 'base64'
164
- ::Base64.decode64(bin)
165
- else
166
- bin
157
+ private
158
+ def _dasherize(key)
159
+ # $2 must be a non-greedy regex for this to work
160
+ left, middle, right = /\A(_*)(.*?)(_*)\Z/.match(key.strip)[1, 3]
161
+ "#{left}#{middle.tr('_ ', '--')}#{right}"
167
162
  end
168
- end
169
163
 
170
- def _parse_file(file, entity)
171
- f = StringIO.new(::Base64.decode64(file))
172
- f.extend(FileLike)
173
- f.original_filename = entity['name']
174
- f.content_type = entity['content_type']
175
- f
176
- end
164
+ # TODO: Add support for other encodings
165
+ def _parse_binary(bin, entity)
166
+ case entity["encoding"]
167
+ when "base64"
168
+ ::Base64.decode64(bin)
169
+ else
170
+ bin
171
+ end
172
+ end
177
173
 
178
- private
174
+ def _parse_file(file, entity)
175
+ f = StringIO.new(::Base64.decode64(file))
176
+ f.extend(FileLike)
177
+ f.original_filename = entity["name"]
178
+ f.content_type = entity["content_type"]
179
+ f
180
+ end
179
181
 
180
182
  def current_thread_backend
181
183
  Thread.current[:xml_mini_backend]
@@ -195,5 +197,5 @@ module ActiveSupport
195
197
  end
196
198
  end
197
199
 
198
- XmlMini.backend = 'REXML'
200
+ XmlMini.backend = "REXML"
199
201
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
- # Copyright (c) 2005-2016 David Heinemeier Hansson
4
+ # Copyright (c) 2005-2020 David Heinemeier Hansson
3
5
  #
4
6
  # Permission is hereby granted, free of charge, to any person obtaining
5
7
  # a copy of this software and associated documentation files (the
@@ -21,7 +23,7 @@
21
23
  # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
24
  #++
23
25
 
24
- require 'securerandom'
26
+ require "securerandom"
25
27
  require "active_support/dependencies/autoload"
26
28
  require "active_support/version"
27
29
  require "active_support/logger"
@@ -32,15 +34,20 @@ module ActiveSupport
32
34
  extend ActiveSupport::Autoload
33
35
 
34
36
  autoload :Concern
37
+ autoload :ActionableError
38
+ autoload :ConfigurationFile
39
+ autoload :CurrentAttributes
35
40
  autoload :Dependencies
36
41
  autoload :DescendantsTracker
37
42
  autoload :ExecutionWrapper
38
43
  autoload :Executor
39
44
  autoload :FileUpdateChecker
40
45
  autoload :EventedFileUpdateChecker
46
+ autoload :ForkTracker
41
47
  autoload :LogSubscriber
42
48
  autoload :Notifications
43
49
  autoload :Reloader
50
+ autoload :SecureCompareRotator
44
51
 
45
52
  eager_autoload do
46
53
  autoload :BacktraceCleaner
@@ -50,6 +57,7 @@ module ActiveSupport
50
57
  autoload :Callbacks
51
58
  autoload :Configurable
52
59
  autoload :Deprecation
60
+ autoload :Digest
53
61
  autoload :Gzip
54
62
  autoload :Inflector
55
63
  autoload :JSON
@@ -62,6 +70,7 @@ module ActiveSupport
62
70
  autoload :OrderedHash
63
71
  autoload :OrderedOptions
64
72
  autoload :StringInquirer
73
+ autoload :EnvironmentInquirer
65
74
  autoload :TaggedLogging
66
75
  autoload :XmlMini
67
76
  autoload :ArrayInquirer
@@ -79,14 +88,6 @@ module ActiveSupport
79
88
 
80
89
  cattr_accessor :test_order # :nodoc:
81
90
 
82
- def self.halt_callback_chains_on_return_false
83
- Callbacks.halt_and_display_warning_on_return_false
84
- end
85
-
86
- def self.halt_callback_chains_on_return_false=(value)
87
- Callbacks.halt_and_display_warning_on_return_false = value
88
- end
89
-
90
91
  def self.to_time_preserves_timezone
91
92
  DateAndTime::Compatibility.preserve_timezone
92
93
  end
@@ -94,6 +95,14 @@ module ActiveSupport
94
95
  def self.to_time_preserves_timezone=(value)
95
96
  DateAndTime::Compatibility.preserve_timezone = value
96
97
  end
98
+
99
+ def self.utc_to_local_returns_utc_offset_times
100
+ DateAndTime::Compatibility.utc_to_local_returns_utc_offset_times
101
+ end
102
+
103
+ def self.utc_to_local_returns_utc_offset_times=(value)
104
+ DateAndTime::Compatibility.utc_to_local_returns_utc_offset_times = value
105
+ end
97
106
  end
98
107
 
99
108
  autoload :I18n, "active_support/i18n"