activesupport 4.0.12 → 7.0.2.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activesupport might be problematic. Click here for more details.

Files changed (295) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +249 -501
  3. data/MIT-LICENSE +2 -2
  4. data/README.rdoc +10 -5
  5. data/lib/active_support/actionable_error.rb +48 -0
  6. data/lib/active_support/all.rb +5 -3
  7. data/lib/active_support/array_inquirer.rb +48 -0
  8. data/lib/active_support/backtrace_cleaner.rb +41 -13
  9. data/lib/active_support/benchmarkable.rb +7 -15
  10. data/lib/active_support/builder.rb +3 -1
  11. data/lib/active_support/cache/file_store.rb +96 -74
  12. data/lib/active_support/cache/mem_cache_store.rb +211 -103
  13. data/lib/active_support/cache/memory_store.rb +90 -58
  14. data/lib/active_support/cache/null_store.rb +19 -7
  15. data/lib/active_support/cache/redis_cache_store.rb +468 -0
  16. data/lib/active_support/cache/strategy/local_cache.rb +86 -83
  17. data/lib/active_support/cache/strategy/local_cache_middleware.rb +45 -0
  18. data/lib/active_support/cache.rb +580 -241
  19. data/lib/active_support/callbacks.rb +812 -425
  20. data/lib/active_support/code_generator.rb +65 -0
  21. data/lib/active_support/concern.rb +103 -14
  22. data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +33 -0
  23. data/lib/active_support/concurrency/share_lock.rb +226 -0
  24. data/lib/active_support/configurable.rb +21 -19
  25. data/lib/active_support/configuration_file.rb +51 -0
  26. data/lib/active_support/core_ext/array/access.rb +47 -1
  27. data/lib/active_support/core_ext/array/conversions.rb +35 -44
  28. data/lib/active_support/core_ext/array/deprecated_conversions.rb +25 -0
  29. data/lib/active_support/core_ext/array/extract.rb +21 -0
  30. data/lib/active_support/core_ext/array/extract_options.rb +2 -0
  31. data/lib/active_support/core_ext/array/grouping.rb +26 -16
  32. data/lib/active_support/core_ext/array/inquiry.rb +19 -0
  33. data/lib/active_support/core_ext/array/wrap.rb +7 -4
  34. data/lib/active_support/core_ext/array.rb +10 -7
  35. data/lib/active_support/core_ext/benchmark.rb +5 -3
  36. data/lib/active_support/core_ext/big_decimal/conversions.rb +9 -26
  37. data/lib/active_support/core_ext/big_decimal.rb +3 -1
  38. data/lib/active_support/core_ext/class/attribute.rb +52 -49
  39. data/lib/active_support/core_ext/class/attribute_accessors.rb +5 -169
  40. data/lib/active_support/core_ext/class/subclasses.rb +25 -26
  41. data/lib/active_support/core_ext/class.rb +4 -4
  42. data/lib/active_support/core_ext/date/acts_like.rb +3 -1
  43. data/lib/active_support/core_ext/date/blank.rb +14 -0
  44. data/lib/active_support/core_ext/date/calculations.rb +31 -18
  45. data/lib/active_support/core_ext/date/conversions.rb +43 -32
  46. data/lib/active_support/core_ext/date/deprecated_conversions.rb +26 -0
  47. data/lib/active_support/core_ext/date/zones.rb +5 -34
  48. data/lib/active_support/core_ext/date.rb +7 -4
  49. data/lib/active_support/core_ext/date_and_time/calculations.rb +198 -66
  50. data/lib/active_support/core_ext/date_and_time/compatibility.rb +31 -0
  51. data/lib/active_support/core_ext/date_and_time/zones.rb +40 -0
  52. data/lib/active_support/core_ext/date_time/acts_like.rb +4 -2
  53. data/lib/active_support/core_ext/date_time/blank.rb +14 -0
  54. data/lib/active_support/core_ext/date_time/calculations.rb +79 -38
  55. data/lib/active_support/core_ext/date_time/compatibility.rb +18 -0
  56. data/lib/active_support/core_ext/date_time/conversions.rb +31 -26
  57. data/lib/active_support/core_ext/date_time/deprecated_conversions.rb +22 -0
  58. data/lib/active_support/core_ext/date_time.rb +8 -4
  59. data/lib/active_support/core_ext/digest/uuid.rb +79 -0
  60. data/lib/active_support/core_ext/digest.rb +3 -0
  61. data/lib/active_support/core_ext/enumerable.rb +249 -17
  62. data/lib/active_support/core_ext/file/atomic.rb +41 -32
  63. data/lib/active_support/core_ext/file.rb +3 -1
  64. data/lib/active_support/core_ext/hash/conversions.rb +71 -49
  65. data/lib/active_support/core_ext/hash/deep_merge.rb +9 -13
  66. data/lib/active_support/core_ext/hash/deep_transform_values.rb +46 -0
  67. data/lib/active_support/core_ext/hash/except.rb +14 -5
  68. data/lib/active_support/core_ext/hash/indifferent_access.rb +5 -3
  69. data/lib/active_support/core_ext/hash/keys.rb +39 -56
  70. data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
  71. data/lib/active_support/core_ext/hash/slice.rb +8 -23
  72. data/lib/active_support/core_ext/hash.rb +10 -8
  73. data/lib/active_support/core_ext/integer/inflections.rb +3 -1
  74. data/lib/active_support/core_ext/integer/multiple.rb +3 -1
  75. data/lib/active_support/core_ext/integer/time.rb +11 -33
  76. data/lib/active_support/core_ext/integer.rb +5 -3
  77. data/lib/active_support/core_ext/kernel/concern.rb +14 -0
  78. data/lib/active_support/core_ext/kernel/reporting.rb +9 -78
  79. data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
  80. data/lib/active_support/core_ext/kernel.rb +5 -4
  81. data/lib/active_support/core_ext/load_error.rb +5 -21
  82. data/lib/active_support/core_ext/module/aliasing.rb +6 -44
  83. data/lib/active_support/core_ext/module/anonymous.rb +12 -1
  84. data/lib/active_support/core_ext/module/attr_internal.rb +8 -8
  85. data/lib/active_support/core_ext/module/attribute_accessors.rb +186 -44
  86. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +157 -0
  87. data/lib/active_support/core_ext/module/concerning.rb +140 -0
  88. data/lib/active_support/core_ext/module/delegation.rb +172 -45
  89. data/lib/active_support/core_ext/module/deprecation.rb +3 -3
  90. data/lib/active_support/core_ext/module/introspection.rb +23 -38
  91. data/lib/active_support/core_ext/module/redefine_method.rb +40 -0
  92. data/lib/active_support/core_ext/module/remove_method.rb +8 -3
  93. data/lib/active_support/core_ext/module.rb +13 -10
  94. data/lib/active_support/core_ext/name_error.rb +45 -4
  95. data/lib/active_support/core_ext/numeric/bytes.rb +22 -0
  96. data/lib/active_support/core_ext/numeric/conversions.rb +135 -127
  97. data/lib/active_support/core_ext/numeric/deprecated_conversions.rb +60 -0
  98. data/lib/active_support/core_ext/numeric/time.rb +37 -50
  99. data/lib/active_support/core_ext/numeric.rb +6 -3
  100. data/lib/active_support/core_ext/object/acts_like.rb +41 -6
  101. data/lib/active_support/core_ext/object/blank.rb +70 -20
  102. data/lib/active_support/core_ext/object/conversions.rb +6 -4
  103. data/lib/active_support/core_ext/object/deep_dup.rb +19 -10
  104. data/lib/active_support/core_ext/object/duplicable.rb +17 -47
  105. data/lib/active_support/core_ext/object/inclusion.rb +18 -15
  106. data/lib/active_support/core_ext/object/instance_variables.rb +3 -1
  107. data/lib/active_support/core_ext/object/json.rb +244 -0
  108. data/lib/active_support/core_ext/object/to_param.rb +3 -1
  109. data/lib/active_support/core_ext/object/to_query.rb +21 -8
  110. data/lib/active_support/core_ext/object/try.rb +106 -26
  111. data/lib/active_support/core_ext/object/with_options.rb +64 -5
  112. data/lib/active_support/core_ext/object.rb +14 -12
  113. data/lib/active_support/core_ext/pathname/existence.rb +21 -0
  114. data/lib/active_support/core_ext/pathname.rb +3 -0
  115. data/lib/active_support/core_ext/range/compare_range.rb +57 -0
  116. data/lib/active_support/core_ext/range/conversions.rb +37 -15
  117. data/lib/active_support/core_ext/range/deprecated_conversions.rb +26 -0
  118. data/lib/active_support/core_ext/range/each.rb +18 -17
  119. data/lib/active_support/core_ext/range/include_time_with_zone.rb +7 -0
  120. data/lib/active_support/core_ext/range/overlaps.rb +2 -0
  121. data/lib/active_support/core_ext/range.rb +7 -4
  122. data/lib/active_support/core_ext/regexp.rb +10 -1
  123. data/lib/active_support/core_ext/securerandom.rb +45 -0
  124. data/lib/active_support/core_ext/string/access.rb +42 -51
  125. data/lib/active_support/core_ext/string/behavior.rb +3 -1
  126. data/lib/active_support/core_ext/string/conversions.rb +18 -13
  127. data/lib/active_support/core_ext/string/exclude.rb +5 -3
  128. data/lib/active_support/core_ext/string/filters.rb +97 -7
  129. data/lib/active_support/core_ext/string/indent.rb +6 -4
  130. data/lib/active_support/core_ext/string/inflections.rb +106 -25
  131. data/lib/active_support/core_ext/string/inquiry.rb +4 -1
  132. data/lib/active_support/core_ext/string/multibyte.rb +18 -9
  133. data/lib/active_support/core_ext/string/output_safety.rb +227 -54
  134. data/lib/active_support/core_ext/string/starts_ends_with.rb +4 -2
  135. data/lib/active_support/core_ext/string/strip.rb +6 -5
  136. data/lib/active_support/core_ext/string/zones.rb +4 -1
  137. data/lib/active_support/core_ext/string.rb +15 -13
  138. data/lib/active_support/core_ext/symbol/starts_ends_with.rb +6 -0
  139. data/lib/active_support/core_ext/symbol.rb +3 -0
  140. data/lib/active_support/core_ext/time/acts_like.rb +3 -1
  141. data/lib/active_support/core_ext/time/calculations.rb +178 -116
  142. data/lib/active_support/core_ext/time/compatibility.rb +16 -0
  143. data/lib/active_support/core_ext/time/conversions.rb +37 -25
  144. data/lib/active_support/core_ext/time/deprecated_conversions.rb +22 -0
  145. data/lib/active_support/core_ext/time/zones.rb +44 -42
  146. data/lib/active_support/core_ext/time.rb +8 -5
  147. data/lib/active_support/core_ext/uri.rb +4 -25
  148. data/lib/active_support/core_ext.rb +4 -2
  149. data/lib/active_support/current_attributes/test_helper.rb +13 -0
  150. data/lib/active_support/current_attributes.rb +226 -0
  151. data/lib/active_support/dependencies/autoload.rb +3 -1
  152. data/lib/active_support/dependencies/interlock.rb +49 -0
  153. data/lib/active_support/dependencies/require_dependency.rb +28 -0
  154. data/lib/active_support/dependencies.rb +71 -696
  155. data/lib/active_support/deprecation/behaviors.rb +65 -16
  156. data/lib/active_support/deprecation/constant_accessor.rb +52 -0
  157. data/lib/active_support/deprecation/disallowed.rb +56 -0
  158. data/lib/active_support/deprecation/instance_delegator.rb +16 -2
  159. data/lib/active_support/deprecation/method_wrappers.rb +62 -21
  160. data/lib/active_support/deprecation/proxy_wrappers.rb +82 -31
  161. data/lib/active_support/deprecation/reporting.rb +81 -18
  162. data/lib/active_support/deprecation.rb +19 -11
  163. data/lib/active_support/descendants_tracker.rb +192 -34
  164. data/lib/active_support/digest.rb +22 -0
  165. data/lib/active_support/duration/iso8601_parser.rb +123 -0
  166. data/lib/active_support/duration/iso8601_serializer.rb +67 -0
  167. data/lib/active_support/duration.rb +437 -39
  168. data/lib/active_support/encrypted_configuration.rb +56 -0
  169. data/lib/active_support/encrypted_file.rb +117 -0
  170. data/lib/active_support/environment_inquirer.rb +20 -0
  171. data/lib/active_support/error_reporter.rb +117 -0
  172. data/lib/active_support/evented_file_update_checker.rb +170 -0
  173. data/lib/active_support/execution_context/test_helper.rb +13 -0
  174. data/lib/active_support/execution_context.rb +53 -0
  175. data/lib/active_support/execution_wrapper.rb +151 -0
  176. data/lib/active_support/executor/test_helper.rb +7 -0
  177. data/lib/active_support/executor.rb +8 -0
  178. data/lib/active_support/file_update_checker.rb +62 -37
  179. data/lib/active_support/fork_tracker.rb +71 -0
  180. data/lib/active_support/gem_version.rb +17 -0
  181. data/lib/active_support/gzip.rb +7 -5
  182. data/lib/active_support/hash_with_indifferent_access.rb +207 -54
  183. data/lib/active_support/html_safe_translation.rb +43 -0
  184. data/lib/active_support/i18n.rb +10 -6
  185. data/lib/active_support/i18n_railtie.rb +48 -19
  186. data/lib/active_support/inflections.rb +19 -12
  187. data/lib/active_support/inflector/inflections.rb +97 -37
  188. data/lib/active_support/inflector/methods.rb +192 -157
  189. data/lib/active_support/inflector/transliterate.rb +83 -33
  190. data/lib/active_support/inflector.rb +7 -5
  191. data/lib/active_support/isolated_execution_state.rb +64 -0
  192. data/lib/active_support/json/decoding.rb +37 -42
  193. data/lib/active_support/json/encoding.rb +93 -293
  194. data/lib/active_support/json.rb +4 -2
  195. data/lib/active_support/key_generator.rb +30 -47
  196. data/lib/active_support/lazy_load_hooks.rb +54 -21
  197. data/lib/active_support/locale/en.rb +33 -0
  198. data/lib/active_support/locale/en.yml +10 -4
  199. data/lib/active_support/log_subscriber/test_helper.rb +14 -12
  200. data/lib/active_support/log_subscriber.rb +61 -18
  201. data/lib/active_support/logger.rb +40 -4
  202. data/lib/active_support/logger_silence.rb +17 -20
  203. data/lib/active_support/logger_thread_safe_level.rb +69 -0
  204. data/lib/active_support/message_encryptor.rb +178 -55
  205. data/lib/active_support/message_verifier.rb +195 -26
  206. data/lib/active_support/messages/metadata.rb +80 -0
  207. data/lib/active_support/messages/rotation_configuration.rb +23 -0
  208. data/lib/active_support/messages/rotator.rb +57 -0
  209. data/lib/active_support/multibyte/chars.rb +45 -92
  210. data/lib/active_support/multibyte/unicode.rb +44 -377
  211. data/lib/active_support/multibyte.rb +5 -3
  212. data/lib/active_support/notifications/fanout.rb +177 -44
  213. data/lib/active_support/notifications/instrumenter.rb +117 -17
  214. data/lib/active_support/notifications.rb +106 -39
  215. data/lib/active_support/number_helper/number_converter.rb +181 -0
  216. data/lib/active_support/number_helper/number_to_currency_converter.rb +46 -0
  217. data/lib/active_support/number_helper/number_to_delimited_converter.rb +30 -0
  218. data/lib/active_support/number_helper/number_to_human_converter.rb +69 -0
  219. data/lib/active_support/number_helper/number_to_human_size_converter.rb +60 -0
  220. data/lib/active_support/number_helper/number_to_percentage_converter.rb +16 -0
  221. data/lib/active_support/number_helper/number_to_phone_converter.rb +59 -0
  222. data/lib/active_support/number_helper/number_to_rounded_converter.rb +59 -0
  223. data/lib/active_support/number_helper/rounding_helper.rb +46 -0
  224. data/lib/active_support/number_helper.rb +152 -394
  225. data/lib/active_support/option_merger.rb +18 -5
  226. data/lib/active_support/ordered_hash.rb +8 -6
  227. data/lib/active_support/ordered_options.rb +43 -7
  228. data/lib/active_support/parameter_filter.rb +138 -0
  229. data/lib/active_support/per_thread_registry.rb +24 -11
  230. data/lib/active_support/proxy_object.rb +2 -0
  231. data/lib/active_support/rails.rb +10 -11
  232. data/lib/active_support/railtie.rb +118 -12
  233. data/lib/active_support/reloader.rb +130 -0
  234. data/lib/active_support/rescuable.rb +112 -57
  235. data/lib/active_support/ruby_features.rb +7 -0
  236. data/lib/active_support/secure_compare_rotator.rb +51 -0
  237. data/lib/active_support/security_utils.rb +38 -0
  238. data/lib/active_support/string_inquirer.rb +11 -4
  239. data/lib/active_support/subscriber.rb +109 -39
  240. data/lib/active_support/tagged_logging.rb +54 -17
  241. data/lib/active_support/test_case.rb +121 -37
  242. data/lib/active_support/testing/assertions.rb +177 -39
  243. data/lib/active_support/testing/autorun.rb +5 -3
  244. data/lib/active_support/testing/constant_lookup.rb +3 -6
  245. data/lib/active_support/testing/declarative.rb +10 -22
  246. data/lib/active_support/testing/deprecation.rb +65 -11
  247. data/lib/active_support/testing/file_fixtures.rb +38 -0
  248. data/lib/active_support/testing/isolation.rb +56 -87
  249. data/lib/active_support/testing/method_call_assertions.rb +70 -0
  250. data/lib/active_support/testing/parallelization/server.rb +82 -0
  251. data/lib/active_support/testing/parallelization/worker.rb +103 -0
  252. data/lib/active_support/testing/parallelization.rb +55 -0
  253. data/lib/active_support/testing/parallelize_executor.rb +76 -0
  254. data/lib/active_support/testing/setup_and_teardown.rb +30 -10
  255. data/lib/active_support/testing/stream.rb +41 -0
  256. data/lib/active_support/testing/tagged_logging.rb +6 -4
  257. data/lib/active_support/testing/time_helpers.rb +246 -0
  258. data/lib/active_support/time.rb +13 -13
  259. data/lib/active_support/time_with_zone.rb +315 -90
  260. data/lib/active_support/values/time_zone.rb +306 -135
  261. data/lib/active_support/version.rb +6 -7
  262. data/lib/active_support/xml_mini/jdom.rb +117 -115
  263. data/lib/active_support/xml_mini/libxml.rb +22 -21
  264. data/lib/active_support/xml_mini/libxmlsax.rb +17 -19
  265. data/lib/active_support/xml_mini/nokogiri.rb +19 -19
  266. data/lib/active_support/xml_mini/nokogirisax.rb +16 -17
  267. data/lib/active_support/xml_mini/rexml.rb +25 -17
  268. data/lib/active_support/xml_mini.rb +67 -56
  269. data/lib/active_support.rb +58 -3
  270. metadata +125 -66
  271. data/lib/active_support/basic_object.rb +0 -11
  272. data/lib/active_support/buffered_logger.rb +0 -21
  273. data/lib/active_support/concurrency/latch.rb +0 -27
  274. data/lib/active_support/core_ext/array/prepend_and_append.rb +0 -7
  275. data/lib/active_support/core_ext/array/uniq_by.rb +0 -19
  276. data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -40
  277. data/lib/active_support/core_ext/date_time/zones.rb +0 -24
  278. data/lib/active_support/core_ext/hash/diff.rb +0 -14
  279. data/lib/active_support/core_ext/kernel/agnostics.rb +0 -11
  280. data/lib/active_support/core_ext/kernel/debugger.rb +0 -10
  281. data/lib/active_support/core_ext/logger.rb +0 -67
  282. data/lib/active_support/core_ext/marshal.rb +0 -21
  283. data/lib/active_support/core_ext/module/qualified_const.rb +0 -52
  284. data/lib/active_support/core_ext/module/reachable.rb +0 -8
  285. data/lib/active_support/core_ext/object/to_json.rb +0 -27
  286. data/lib/active_support/core_ext/proc.rb +0 -17
  287. data/lib/active_support/core_ext/range/include_range.rb +0 -23
  288. data/lib/active_support/core_ext/string/encoding.rb +0 -8
  289. data/lib/active_support/core_ext/struct.rb +0 -6
  290. data/lib/active_support/core_ext/thread.rb +0 -79
  291. data/lib/active_support/core_ext/time/marshal.rb +0 -30
  292. data/lib/active_support/file_watcher.rb +0 -36
  293. data/lib/active_support/json/variable.rb +0 -18
  294. data/lib/active_support/testing/pending.rb +0 -14
  295. data/lib/active_support/values/unicode_tables.dat +0 -0
@@ -1,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
- module XmlMini_REXML #:nodoc:
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,19 +19,17 @@ 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
- char = data.getc
24
- if char.nil?
25
+ if data.eof?
25
26
  {}
26
27
  else
27
- data.ungetc(char)
28
- silence_warnings { require 'rexml/document' } unless defined?(REXML::Document)
28
+ require_rexml unless defined?(REXML::Document)
29
29
  doc = REXML::Document.new(data)
30
30
 
31
31
  if doc.root
32
- merge_element!({}, doc.root)
32
+ merge_element!({}, doc.root, XmlMini.depth)
33
33
  else
34
34
  raise REXML::ParseException,
35
35
  "The document #{doc.to_s.inspect} does not have a valid root"
@@ -38,25 +38,33 @@ module ActiveSupport
38
38
  end
39
39
 
40
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
+
41
48
  # Convert an XML element and merge into the hash
42
49
  #
43
50
  # hash::
44
51
  # Hash to merge the converted element into.
45
52
  # element::
46
53
  # XML element to merge into hash
47
- def merge_element!(hash, element)
48
- merge!(hash, element.name, collapse(element))
54
+ def merge_element!(hash, element, depth)
55
+ raise REXML::ParseException, "The document is too deep" if depth == 0
56
+ merge!(hash, element.name, collapse(element, depth))
49
57
  end
50
58
 
51
59
  # Actually converts an XML document element into a data structure.
52
60
  #
53
61
  # element::
54
62
  # The document element to be collapsed.
55
- def collapse(element)
63
+ def collapse(element, depth)
56
64
  hash = get_attributes(element)
57
65
 
58
66
  if element.has_elements?
59
- element.each_element {|child| merge_element!(hash, child) }
67
+ element.each_element { |child| merge_element!(hash, child, depth - 1) }
60
68
  merge_texts!(hash, element) unless empty_content?(element)
61
69
  hash
62
70
  else
@@ -75,7 +83,7 @@ module ActiveSupport
75
83
  hash
76
84
  else
77
85
  # must use value to prevent double-escaping
78
- texts = ''
86
+ texts = +""
79
87
  element.texts.each { |t| texts << t.value }
80
88
  merge!(hash, CONTENT_KEY, texts)
81
89
  end
@@ -114,7 +122,7 @@ module ActiveSupport
114
122
  # XML element to extract attributes from.
115
123
  def get_attributes(element)
116
124
  attributes = {}
117
- element.attributes.each { |n,v| attributes[n] = v }
125
+ element.attributes.each { |n, v| attributes[n] = v }
118
126
  attributes
119
127
  end
120
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
@@ -16,15 +19,15 @@ module ActiveSupport
16
19
 
17
20
  # This module decorates files deserialized using Hash.from_xml with
18
21
  # the <tt>original_filename</tt> and <tt>content_type</tt> methods.
19
- module FileLike #:nodoc:
22
+ module FileLike # :nodoc:
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
 
@@ -32,24 +35,26 @@ module ActiveSupport
32
35
  "binary" => "base64"
33
36
  } unless defined?(DEFAULT_ENCODINGS)
34
37
 
35
- TYPE_NAMES = {
36
- "Symbol" => "symbol",
37
- "Fixnum" => "integer",
38
- "Bignum" => "integer",
39
- "BigDecimal" => "decimal",
40
- "Float" => "float",
41
- "TrueClass" => "boolean",
42
- "FalseClass" => "boolean",
43
- "Date" => "date",
44
- "DateTime" => "dateTime",
45
- "Time" => "dateTime",
46
- "Array" => "array",
47
- "Hash" => "hash"
48
- } unless defined?(TYPE_NAMES)
38
+ unless defined?(TYPE_NAMES)
39
+ TYPE_NAMES = {
40
+ "Symbol" => "symbol",
41
+ "Integer" => "integer",
42
+ "BigDecimal" => "decimal",
43
+ "Float" => "float",
44
+ "TrueClass" => "boolean",
45
+ "FalseClass" => "boolean",
46
+ "Date" => "date",
47
+ "DateTime" => "dateTime",
48
+ "Time" => "dateTime",
49
+ "Array" => "array",
50
+ "Hash" => "hash"
51
+ }
52
+ end
53
+ TYPE_NAMES["ActiveSupport::TimeWithZone"] = TYPE_NAMES["Time"]
49
54
 
50
55
  FORMATTING = {
51
56
  "symbol" => Proc.new { |symbol| symbol.to_s },
52
- "date" => Proc.new { |date| date.to_s(:db) },
57
+ "date" => Proc.new { |date| date.to_fs(:db) },
53
58
  "dateTime" => Proc.new { |time| time.xmlschema },
54
59
  "binary" => Proc.new { |binary| ::Base64.encode64(binary) },
55
60
  "yaml" => Proc.new { |yaml| yaml.to_yaml }
@@ -63,10 +68,16 @@ module ActiveSupport
63
68
  "datetime" => Proc.new { |time| Time.xmlschema(time).utc rescue ::DateTime.parse(time).utc },
64
69
  "integer" => Proc.new { |integer| integer.to_i },
65
70
  "float" => Proc.new { |float| float.to_f },
66
- "decimal" => Proc.new { |number| BigDecimal(number) },
71
+ "decimal" => Proc.new do |number|
72
+ if String === number
73
+ number.to_d
74
+ else
75
+ BigDecimal(number)
76
+ end
77
+ end,
67
78
  "boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.to_s.strip) },
68
79
  "string" => Proc.new { |string| string.to_s },
69
- "yaml" => Proc.new { |yaml| YAML::load(yaml) rescue yaml },
80
+ "yaml" => Proc.new { |yaml| YAML.load(yaml) rescue yaml },
70
81
  "base64Binary" => Proc.new { |bin| ::Base64.decode64(bin) },
71
82
  "binary" => Proc.new { |bin, entity| _parse_binary(bin, entity) },
72
83
  "file" => Proc.new { |file, entity| _parse_file(file, entity) }
@@ -78,7 +89,10 @@ module ActiveSupport
78
89
  )
79
90
  end
80
91
 
81
- delegate :parse, :to => :backend
92
+ attr_accessor :depth
93
+ self.depth = 100
94
+
95
+ delegate :parse, to: :backend
82
96
 
83
97
  def backend
84
98
  current_thread_backend || @backend
@@ -100,7 +114,7 @@ module ActiveSupport
100
114
 
101
115
  def to_tag(key, value, options)
102
116
  type_name = options.delete(:type)
103
- merged_options = options.merge(:root => key, :skip_instruct => true)
117
+ merged_options = options.merge(root: key, skip_instruct: true)
104
118
 
105
119
  if value.is_a?(::Method) || value.is_a?(::Proc)
106
120
  if value.arity == 1
@@ -118,7 +132,7 @@ module ActiveSupport
118
132
 
119
133
  key = rename_key(key.to_s, options)
120
134
 
121
- attributes = options[:skip_types] || type_name.nil? ? { } : { :type => type_name }
135
+ attributes = options[:skip_types] || type_name.nil? ? {} : { type: type_name }
122
136
  attributes[:nil] = true if value.nil?
123
137
 
124
138
  encoding = options[:encoding] || DEFAULT_ENCODINGS[type_name]
@@ -141,40 +155,37 @@ module ActiveSupport
141
155
  key
142
156
  end
143
157
 
144
- protected
145
-
146
- def _dasherize(key)
147
- # $2 must be a non-greedy regex for this to work
148
- left, middle, right = /\A(_*)(.*?)(_*)\Z/.match(key.strip)[1,3]
149
- "#{left}#{middle.tr('_ ', '--')}#{right}"
150
- end
151
-
152
- # TODO: Add support for other encodings
153
- def _parse_binary(bin, entity) #:nodoc:
154
- case entity['encoding']
155
- when 'base64'
156
- ::Base64.decode64(bin)
157
- else
158
- bin
158
+ private
159
+ def _dasherize(key)
160
+ # $2 must be a non-greedy regex for this to work
161
+ left, middle, right = /\A(_*)(.*?)(_*)\Z/.match(key.strip)[1, 3]
162
+ "#{left}#{middle.tr('_ ', '--')}#{right}"
159
163
  end
160
- end
161
164
 
162
- def _parse_file(file, entity)
163
- f = StringIO.new(::Base64.decode64(file))
164
- f.extend(FileLike)
165
- f.original_filename = entity['name']
166
- f.content_type = entity['content_type']
167
- f
168
- end
165
+ # TODO: Add support for other encodings
166
+ def _parse_binary(bin, entity)
167
+ case entity["encoding"]
168
+ when "base64"
169
+ ::Base64.decode64(bin)
170
+ else
171
+ bin
172
+ end
173
+ end
169
174
 
170
- private
175
+ def _parse_file(file, entity)
176
+ f = StringIO.new(::Base64.decode64(file))
177
+ f.extend(FileLike)
178
+ f.original_filename = entity["name"]
179
+ f.content_type = entity["content_type"]
180
+ f
181
+ end
171
182
 
172
183
  def current_thread_backend
173
- Thread.current[:xml_mini_backend]
184
+ IsolatedExecutionState[:xml_mini_backend]
174
185
  end
175
186
 
176
187
  def current_thread_backend=(name)
177
- Thread.current[:xml_mini_backend] = name && cast_backend_name_to_module(name)
188
+ IsolatedExecutionState[:xml_mini_backend] = name && cast_backend_name_to_module(name)
178
189
  end
179
190
 
180
191
  def cast_backend_name_to_module(name)
@@ -187,5 +198,5 @@ module ActiveSupport
187
198
  end
188
199
  end
189
200
 
190
- XmlMini.backend = 'REXML'
201
+ XmlMini.backend = "REXML"
191
202
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  #--
2
- # Copyright (c) 2005-2013 David Heinemeier Hansson
4
+ # Copyright (c) 2005-2022 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,31 +23,46 @@
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"
28
30
  require "active_support/lazy_load_hooks"
31
+ require "active_support/core_ext/date_and_time/compatibility"
29
32
 
30
33
  module ActiveSupport
31
34
  extend ActiveSupport::Autoload
32
35
 
33
36
  autoload :Concern
37
+ autoload :CodeGenerator
38
+ autoload :ActionableError
39
+ autoload :ConfigurationFile
40
+ autoload :CurrentAttributes
34
41
  autoload :Dependencies
35
42
  autoload :DescendantsTracker
43
+ autoload :ExecutionContext
44
+ autoload :ExecutionWrapper
45
+ autoload :Executor
46
+ autoload :ErrorReporter
36
47
  autoload :FileUpdateChecker
48
+ autoload :EventedFileUpdateChecker
49
+ autoload :ForkTracker
37
50
  autoload :LogSubscriber
51
+ autoload :IsolatedExecutionState
38
52
  autoload :Notifications
53
+ autoload :Reloader
54
+ autoload :PerThreadRegistry
55
+ autoload :SecureCompareRotator
39
56
 
40
57
  eager_autoload do
41
58
  autoload :BacktraceCleaner
42
- autoload :BasicObject
43
59
  autoload :ProxyObject
44
60
  autoload :Benchmarkable
45
61
  autoload :Cache
46
62
  autoload :Callbacks
47
63
  autoload :Configurable
48
64
  autoload :Deprecation
65
+ autoload :Digest
49
66
  autoload :Gzip
50
67
  autoload :Inflector
51
68
  autoload :JSON
@@ -53,17 +70,55 @@ module ActiveSupport
53
70
  autoload :MessageEncryptor
54
71
  autoload :MessageVerifier
55
72
  autoload :Multibyte
73
+ autoload :NumberHelper
56
74
  autoload :OptionMerger
57
75
  autoload :OrderedHash
58
76
  autoload :OrderedOptions
59
77
  autoload :StringInquirer
78
+ autoload :EnvironmentInquirer
60
79
  autoload :TaggedLogging
61
80
  autoload :XmlMini
81
+ autoload :ArrayInquirer
62
82
  end
63
83
 
64
84
  autoload :Rescuable
65
85
  autoload :SafeBuffer, "active_support/core_ext/string/output_safety"
66
86
  autoload :TestCase
87
+
88
+ def self.eager_load!
89
+ super
90
+
91
+ NumberHelper.eager_load!
92
+ end
93
+
94
+ cattr_accessor :test_order # :nodoc:
95
+ cattr_accessor :test_parallelization_threshold, default: 50 # :nodoc:
96
+
97
+ singleton_class.attr_accessor :error_reporter # :nodoc:
98
+
99
+ def self.cache_format_version
100
+ Cache.format_version
101
+ end
102
+
103
+ def self.cache_format_version=(value)
104
+ Cache.format_version = value
105
+ end
106
+
107
+ def self.to_time_preserves_timezone
108
+ DateAndTime::Compatibility.preserve_timezone
109
+ end
110
+
111
+ def self.to_time_preserves_timezone=(value)
112
+ DateAndTime::Compatibility.preserve_timezone = value
113
+ end
114
+
115
+ def self.utc_to_local_returns_utc_offset_times
116
+ DateAndTime::Compatibility.utc_to_local_returns_utc_offset_times
117
+ end
118
+
119
+ def self.utc_to_local_returns_utc_offset_times=(value)
120
+ DateAndTime::Compatibility.utc_to_local_returns_utc_offset_times = value
121
+ end
67
122
  end
68
123
 
69
124
  autoload :I18n, "active_support/i18n"