activesupport 5.1.1 → 6.1.1

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

Potentially problematic release.


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

Files changed (262) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +360 -442
  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 +2 -0
  7. data/lib/active_support/array_inquirer.rb +6 -2
  8. data/lib/active_support/backtrace_cleaner.rb +31 -3
  9. data/lib/active_support/benchmarkable.rb +3 -1
  10. data/lib/active_support/builder.rb +2 -0
  11. data/lib/active_support/cache/file_store.rb +37 -36
  12. data/lib/active_support/cache/mem_cache_store.rb +65 -53
  13. data/lib/active_support/cache/memory_store.rb +61 -33
  14. data/lib/active_support/cache/null_store.rb +10 -3
  15. data/lib/active_support/cache/redis_cache_store.rb +493 -0
  16. data/lib/active_support/cache/strategy/local_cache.rb +68 -22
  17. data/lib/active_support/cache/strategy/local_cache_middleware.rb +2 -0
  18. data/lib/active_support/cache.rb +305 -127
  19. data/lib/active_support/callbacks.rb +106 -98
  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 +2 -1
  23. data/lib/active_support/configurable.rb +12 -14
  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 +7 -5
  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 +2 -0
  30. data/lib/active_support/core_ext/array/inquiry.rb +2 -0
  31. data/lib/active_support/core_ext/array/wrap.rb +2 -0
  32. data/lib/active_support/core_ext/array.rb +3 -1
  33. data/lib/active_support/core_ext/benchmark.rb +4 -2
  34. data/lib/active_support/core_ext/big_decimal/conversions.rb +2 -0
  35. data/lib/active_support/core_ext/big_decimal.rb +2 -0
  36. data/lib/active_support/core_ext/class/attribute.rb +50 -47
  37. data/lib/active_support/core_ext/class/attribute_accessors.rb +2 -0
  38. data/lib/active_support/core_ext/class/subclasses.rb +18 -40
  39. data/lib/active_support/core_ext/class.rb +2 -0
  40. data/lib/active_support/core_ext/date/acts_like.rb +2 -0
  41. data/lib/active_support/core_ext/date/blank.rb +2 -0
  42. data/lib/active_support/core_ext/date/calculations.rb +8 -5
  43. data/lib/active_support/core_ext/date/conversions.rb +12 -10
  44. data/lib/active_support/core_ext/date/zones.rb +2 -0
  45. data/lib/active_support/core_ext/date.rb +2 -0
  46. data/lib/active_support/core_ext/date_and_time/calculations.rb +61 -37
  47. data/lib/active_support/core_ext/date_and_time/compatibility.rb +18 -1
  48. data/lib/active_support/core_ext/date_and_time/zones.rb +2 -1
  49. data/lib/active_support/core_ext/date_time/acts_like.rb +2 -0
  50. data/lib/active_support/core_ext/date_time/blank.rb +2 -0
  51. data/lib/active_support/core_ext/date_time/calculations.rb +3 -1
  52. data/lib/active_support/core_ext/date_time/compatibility.rb +7 -5
  53. data/lib/active_support/core_ext/date_time/conversions.rb +2 -1
  54. data/lib/active_support/core_ext/date_time.rb +2 -0
  55. data/lib/active_support/core_ext/digest/uuid.rb +3 -1
  56. data/lib/active_support/core_ext/digest.rb +3 -0
  57. data/lib/active_support/core_ext/enumerable.rb +174 -71
  58. data/lib/active_support/core_ext/file/atomic.rb +3 -1
  59. data/lib/active_support/core_ext/file.rb +2 -0
  60. data/lib/active_support/core_ext/hash/conversions.rb +7 -5
  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 +2 -0
  65. data/lib/active_support/core_ext/hash/keys.rb +3 -30
  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 +3 -2
  69. data/lib/active_support/core_ext/integer/inflections.rb +2 -0
  70. data/lib/active_support/core_ext/integer/multiple.rb +3 -1
  71. data/lib/active_support/core_ext/integer/time.rb +7 -14
  72. data/lib/active_support/core_ext/integer.rb +2 -0
  73. data/lib/active_support/core_ext/kernel/concern.rb +2 -0
  74. data/lib/active_support/core_ext/kernel/reporting.rb +2 -0
  75. data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
  76. data/lib/active_support/core_ext/kernel.rb +2 -1
  77. data/lib/active_support/core_ext/load_error.rb +3 -8
  78. data/lib/active_support/core_ext/marshal.rb +4 -0
  79. data/lib/active_support/core_ext/module/aliasing.rb +2 -0
  80. data/lib/active_support/core_ext/module/anonymous.rb +2 -0
  81. data/lib/active_support/core_ext/module/attr_internal.rb +4 -2
  82. data/lib/active_support/core_ext/module/attribute_accessors.rb +44 -56
  83. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +18 -18
  84. data/lib/active_support/core_ext/module/concerning.rb +15 -10
  85. data/lib/active_support/core_ext/module/delegation.rb +103 -58
  86. data/lib/active_support/core_ext/module/deprecation.rb +2 -0
  87. data/lib/active_support/core_ext/module/introspection.rb +18 -15
  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 +3 -1
  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 +131 -129
  94. data/lib/active_support/core_ext/numeric/time.rb +7 -15
  95. data/lib/active_support/core_ext/numeric.rb +2 -1
  96. data/lib/active_support/core_ext/object/acts_like.rb +12 -1
  97. data/lib/active_support/core_ext/object/blank.rb +13 -3
  98. data/lib/active_support/core_ext/object/conversions.rb +2 -0
  99. data/lib/active_support/core_ext/object/deep_dup.rb +3 -1
  100. data/lib/active_support/core_ext/object/duplicable.rb +6 -101
  101. data/lib/active_support/core_ext/object/inclusion.rb +2 -0
  102. data/lib/active_support/core_ext/object/instance_variables.rb +2 -0
  103. data/lib/active_support/core_ext/object/json.rb +22 -2
  104. data/lib/active_support/core_ext/object/to_param.rb +2 -0
  105. data/lib/active_support/core_ext/object/to_query.rb +7 -2
  106. data/lib/active_support/core_ext/object/try.rb +19 -7
  107. data/lib/active_support/core_ext/object/with_options.rb +4 -2
  108. data/lib/active_support/core_ext/object.rb +2 -0
  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 +4 -1
  115. data/lib/active_support/core_ext/regexp.rb +10 -5
  116. data/lib/active_support/core_ext/securerandom.rb +25 -3
  117. data/lib/active_support/core_ext/string/access.rb +7 -16
  118. data/lib/active_support/core_ext/string/behavior.rb +2 -0
  119. data/lib/active_support/core_ext/string/conversions.rb +3 -0
  120. data/lib/active_support/core_ext/string/exclude.rb +2 -0
  121. data/lib/active_support/core_ext/string/filters.rb +44 -1
  122. data/lib/active_support/core_ext/string/indent.rb +2 -0
  123. data/lib/active_support/core_ext/string/inflections.rb +69 -16
  124. data/lib/active_support/core_ext/string/inquiry.rb +3 -0
  125. data/lib/active_support/core_ext/string/multibyte.rb +9 -4
  126. data/lib/active_support/core_ext/string/output_safety.rb +76 -20
  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 +2 -0
  130. data/lib/active_support/core_ext/string.rb +2 -0
  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 +2 -0
  134. data/lib/active_support/core_ext/time/calculations.rb +73 -18
  135. data/lib/active_support/core_ext/time/compatibility.rb +4 -2
  136. data/lib/active_support/core_ext/time/conversions.rb +4 -0
  137. data/lib/active_support/core_ext/time/zones.rb +6 -4
  138. data/lib/active_support/core_ext/time.rb +2 -0
  139. data/lib/active_support/core_ext/uri.rb +11 -6
  140. data/lib/active_support/core_ext.rb +3 -1
  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 +2 -0
  145. data/lib/active_support/dependencies/zeitwerk_integration.rb +117 -0
  146. data/lib/active_support/dependencies.rb +135 -60
  147. data/lib/active_support/deprecation/behaviors.rb +43 -11
  148. data/lib/active_support/deprecation/constant_accessor.rb +4 -2
  149. data/lib/active_support/deprecation/disallowed.rb +56 -0
  150. data/lib/active_support/deprecation/instance_delegator.rb +2 -1
  151. data/lib/active_support/deprecation/method_wrappers.rb +30 -15
  152. data/lib/active_support/deprecation/proxy_wrappers.rb +32 -6
  153. data/lib/active_support/deprecation/reporting.rb +54 -9
  154. data/lib/active_support/deprecation.rb +9 -2
  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 +6 -6
  158. data/lib/active_support/duration/iso8601_serializer.rb +20 -14
  159. data/lib/active_support/duration.rb +179 -41
  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 +84 -117
  164. data/lib/active_support/execution_wrapper.rb +3 -0
  165. data/lib/active_support/executor.rb +2 -0
  166. data/lib/active_support/file_update_checker.rb +2 -1
  167. data/lib/active_support/fork_tracker.rb +62 -0
  168. data/lib/active_support/gem_version.rb +3 -1
  169. data/lib/active_support/gzip.rb +2 -0
  170. data/lib/active_support/hash_with_indifferent_access.rb +134 -37
  171. data/lib/active_support/i18n.rb +4 -1
  172. data/lib/active_support/i18n_railtie.rb +20 -11
  173. data/lib/active_support/inflections.rb +2 -0
  174. data/lib/active_support/inflector/inflections.rb +19 -8
  175. data/lib/active_support/inflector/methods.rb +87 -77
  176. data/lib/active_support/inflector/transliterate.rb +56 -18
  177. data/lib/active_support/inflector.rb +2 -0
  178. data/lib/active_support/json/decoding.rb +27 -26
  179. data/lib/active_support/json/encoding.rb +13 -3
  180. data/lib/active_support/json.rb +2 -0
  181. data/lib/active_support/key_generator.rb +3 -33
  182. data/lib/active_support/lazy_load_hooks.rb +33 -10
  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 +2 -0
  186. data/lib/active_support/log_subscriber.rb +46 -13
  187. data/lib/active_support/logger.rb +4 -17
  188. data/lib/active_support/logger_silence.rb +13 -20
  189. data/lib/active_support/logger_thread_safe_level.rb +54 -7
  190. data/lib/active_support/message_encryptor.rb +101 -33
  191. data/lib/active_support/message_verifier.rb +85 -14
  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 +12 -68
  196. data/lib/active_support/multibyte/unicode.rb +17 -327
  197. data/lib/active_support/multibyte.rb +2 -0
  198. data/lib/active_support/notifications/fanout.rb +118 -16
  199. data/lib/active_support/notifications/instrumenter.rb +73 -9
  200. data/lib/active_support/notifications.rb +74 -8
  201. data/lib/active_support/number_helper/number_converter.rb +7 -6
  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 -2
  204. data/lib/active_support/number_helper/number_to_human_converter.rb +8 -7
  205. data/lib/active_support/number_helper/number_to_human_size_converter.rb +6 -3
  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 -2
  208. data/lib/active_support/number_helper/number_to_rounded_converter.rb +16 -53
  209. data/lib/active_support/number_helper/rounding_helper.rb +50 -0
  210. data/lib/active_support/number_helper.rb +41 -12
  211. data/lib/active_support/option_merger.rb +24 -3
  212. data/lib/active_support/ordered_hash.rb +3 -1
  213. data/lib/active_support/ordered_options.rb +17 -5
  214. data/lib/active_support/parameter_filter.rb +133 -0
  215. data/lib/active_support/per_thread_registry.rb +3 -1
  216. data/lib/active_support/proxy_object.rb +2 -0
  217. data/lib/active_support/rails.rb +3 -10
  218. data/lib/active_support/railtie.rb +60 -9
  219. data/lib/active_support/reloader.rb +11 -10
  220. data/lib/active_support/rescuable.rb +7 -6
  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 +6 -3
  224. data/lib/active_support/subscriber.rb +74 -24
  225. data/lib/active_support/tagged_logging.rb +44 -8
  226. data/lib/active_support/test_case.rb +94 -2
  227. data/lib/active_support/testing/assertions.rb +58 -20
  228. data/lib/active_support/testing/autorun.rb +2 -4
  229. data/lib/active_support/testing/constant_lookup.rb +2 -0
  230. data/lib/active_support/testing/declarative.rb +2 -0
  231. data/lib/active_support/testing/deprecation.rb +2 -1
  232. data/lib/active_support/testing/file_fixtures.rb +4 -0
  233. data/lib/active_support/testing/isolation.rb +8 -4
  234. data/lib/active_support/testing/method_call_assertions.rb +30 -1
  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 +12 -7
  239. data/lib/active_support/testing/stream.rb +3 -2
  240. data/lib/active_support/testing/tagged_logging.rb +2 -0
  241. data/lib/active_support/testing/time_helpers.rb +78 -13
  242. data/lib/active_support/time.rb +2 -0
  243. data/lib/active_support/time_with_zone.rb +113 -41
  244. data/lib/active_support/values/time_zone.rb +55 -25
  245. data/lib/active_support/version.rb +2 -0
  246. data/lib/active_support/xml_mini/jdom.rb +5 -4
  247. data/lib/active_support/xml_mini/libxml.rb +4 -2
  248. data/lib/active_support/xml_mini/libxmlsax.rb +6 -4
  249. data/lib/active_support/xml_mini/nokogiri.rb +4 -2
  250. data/lib/active_support/xml_mini/nokogirisax.rb +5 -3
  251. data/lib/active_support/xml_mini/rexml.rb +12 -3
  252. data/lib/active_support/xml_mini.rb +5 -11
  253. data/lib/active_support.rb +18 -13
  254. metadata +81 -35
  255. data/lib/active_support/core_ext/array/prepend_and_append.rb +0 -7
  256. data/lib/active_support/core_ext/hash/compact.rb +0 -27
  257. data/lib/active_support/core_ext/hash/transform_values.rb +0 -30
  258. data/lib/active_support/core_ext/kernel/agnostics.rb +0 -11
  259. data/lib/active_support/core_ext/module/reachable.rb +0 -8
  260. data/lib/active_support/core_ext/numeric/inquiry.rb +0 -26
  261. data/lib/active_support/core_ext/range/include_range.rb +0 -23
  262. data/lib/active_support/values/unicode_tables.dat +0 -0
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "active_support/duration"
2
4
  require "active_support/values/time_zone"
3
5
  require "active_support/core_ext/object/acts_like"
@@ -13,25 +15,25 @@ module ActiveSupport
13
15
  # and +in_time_zone+ on Time and DateTime instances.
14
16
  #
15
17
  # Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
16
- # Time.zone.local(2007, 2, 10, 15, 30, 45) # => Sat, 10 Feb 2007 15:30:45 EST -05:00
17
- # Time.zone.parse('2007-02-10 15:30:45') # => Sat, 10 Feb 2007 15:30:45 EST -05:00
18
- # Time.zone.at(1171139445) # => Sat, 10 Feb 2007 15:30:45 EST -05:00
19
- # Time.zone.now # => Sun, 18 May 2008 13:07:55 EDT -04:00
20
- # Time.utc(2007, 2, 10, 20, 30, 45).in_time_zone # => Sat, 10 Feb 2007 15:30:45 EST -05:00
18
+ # Time.zone.local(2007, 2, 10, 15, 30, 45) # => Sat, 10 Feb 2007 15:30:45.000000000 EST -05:00
19
+ # Time.zone.parse('2007-02-10 15:30:45') # => Sat, 10 Feb 2007 15:30:45.000000000 EST -05:00
20
+ # Time.zone.at(1171139445) # => Sat, 10 Feb 2007 15:30:45.000000000 EST -05:00
21
+ # Time.zone.now # => Sun, 18 May 2008 13:07:55.754107581 EDT -04:00
22
+ # Time.utc(2007, 2, 10, 20, 30, 45).in_time_zone # => Sat, 10 Feb 2007 15:30:45.000000000 EST -05:00
21
23
  #
22
24
  # See Time and TimeZone for further documentation of these methods.
23
25
  #
24
26
  # TimeWithZone instances implement the same API as Ruby Time instances, so
25
27
  # that Time and TimeWithZone instances are interchangeable.
26
28
  #
27
- # t = Time.zone.now # => Sun, 18 May 2008 13:27:25 EDT -04:00
29
+ # t = Time.zone.now # => Sun, 18 May 2008 13:27:25.031505668 EDT -04:00
28
30
  # t.hour # => 13
29
31
  # t.dst? # => true
30
32
  # t.utc_offset # => -14400
31
33
  # t.zone # => "EDT"
32
34
  # t.to_s(:rfc822) # => "Sun, 18 May 2008 13:27:25 -0400"
33
- # t + 1.day # => Mon, 19 May 2008 13:27:25 EDT -04:00
34
- # t.beginning_of_year # => Tue, 01 Jan 2008 00:00:00 EST -05:00
35
+ # t + 1.day # => Mon, 19 May 2008 13:27:25.031505668 EDT -04:00
36
+ # t.beginning_of_year # => Tue, 01 Jan 2008 00:00:00.000000000 EST -05:00
35
37
  # t > Time.utc(1999) # => true
36
38
  # t.is_a?(Time) # => true
37
39
  # t.is_a?(ActiveSupport::TimeWithZone) # => true
@@ -41,8 +43,8 @@ module ActiveSupport
41
43
  "Time"
42
44
  end
43
45
 
44
- PRECISIONS = Hash.new { |h, n| h[n] = "%FT%T.%#{n}N".freeze }
45
- PRECISIONS[0] = "%FT%T".freeze
46
+ PRECISIONS = Hash.new { |h, n| h[n] = "%FT%T.%#{n}N" }
47
+ PRECISIONS[0] = "%FT%T"
46
48
 
47
49
  include Comparable, DateAndTime::Compatibility
48
50
  attr_reader :time_zone
@@ -55,12 +57,12 @@ module ActiveSupport
55
57
 
56
58
  # Returns a <tt>Time</tt> instance that represents the time in +time_zone+.
57
59
  def time
58
- @time ||= period.to_local(@utc)
60
+ @time ||= incorporate_utc_offset(@utc, utc_offset)
59
61
  end
60
62
 
61
63
  # Returns a <tt>Time</tt> instance of the simultaneous time in the UTC timezone.
62
64
  def utc
63
- @utc ||= period.to_utc(@time)
65
+ @utc ||= incorporate_utc_offset(@time, -utc_offset)
64
66
  end
65
67
  alias_method :comparable_time, :utc
66
68
  alias_method :getgm, :utc
@@ -102,13 +104,13 @@ module ActiveSupport
102
104
  # Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
103
105
  # Time.zone.now.utc? # => false
104
106
  def utc?
105
- period.offset.abbreviation == :UTC || period.offset.abbreviation == :UCT
107
+ zone == "UTC" || zone == "UCT"
106
108
  end
107
109
  alias_method :gmt?, :utc?
108
110
 
109
111
  # Returns the offset from current time to UTC time in seconds.
110
112
  def utc_offset
111
- period.utc_total_offset
113
+ period.observed_utc_offset
112
114
  end
113
115
  alias_method :gmt_offset, :utc_offset
114
116
  alias_method :gmtoff, :utc_offset
@@ -130,14 +132,14 @@ module ActiveSupport
130
132
  # Time.zone = 'Eastern Time (US & Canada)' # => "Eastern Time (US & Canada)"
131
133
  # Time.zone.now.zone # => "EST"
132
134
  def zone
133
- period.zone_identifier.to_s
135
+ period.abbreviation
134
136
  end
135
137
 
136
138
  # Returns a string of the object's date, time, zone, and offset from UTC.
137
139
  #
138
- # Time.zone.now.inspect # => "Thu, 04 Dec 2014 11:00:25 EST -05:00"
140
+ # Time.zone.now.inspect # => "Thu, 04 Dec 2014 11:00:25.624541392 EST -05:00"
139
141
  def inspect
140
- "#{time.strftime('%a, %d %b %Y %H:%M:%S')} #{zone} #{formatted_offset}"
142
+ "#{time.strftime('%a, %d %b %Y %H:%M:%S.%9N')} #{zone} #{formatted_offset}"
141
143
  end
142
144
 
143
145
  # Returns a string of the object's date and time in the ISO 8601 standard
@@ -145,7 +147,7 @@ module ActiveSupport
145
147
  #
146
148
  # Time.zone.now.xmlschema # => "2014-12-04T11:02:37-05:00"
147
149
  def xmlschema(fraction_digits = 0)
148
- "#{time.strftime(PRECISIONS[fraction_digits.to_i])}#{formatted_offset(true, 'Z'.freeze)}"
150
+ "#{time.strftime(PRECISIONS[fraction_digits.to_i])}#{formatted_offset(true, 'Z')}"
149
151
  end
150
152
  alias_method :iso8601, :xmlschema
151
153
  alias_method :rfc3339, :xmlschema
@@ -223,6 +225,8 @@ module ActiveSupport
223
225
  def <=>(other)
224
226
  utc <=> other
225
227
  end
228
+ alias_method :before?, :<
229
+ alias_method :after?, :>
226
230
 
227
231
  # Returns true if the current object's time is within the specified
228
232
  # +min+ and +max+ time.
@@ -241,6 +245,20 @@ module ActiveSupport
241
245
  time.today?
242
246
  end
243
247
 
248
+ # Returns true if the current object's time falls within
249
+ # the next day (tomorrow).
250
+ def tomorrow?
251
+ time.tomorrow?
252
+ end
253
+ alias :next_day? :tomorrow?
254
+
255
+ # Returns true if the current object's time falls within
256
+ # the previous day (yesterday).
257
+ def yesterday?
258
+ time.yesterday?
259
+ end
260
+ alias :prev_day? :yesterday?
261
+
244
262
  # Returns true if the current object's time is in the future.
245
263
  def future?
246
264
  utc.future?
@@ -259,8 +277,8 @@ module ActiveSupport
259
277
  # value as a new TimeWithZone object.
260
278
  #
261
279
  # Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
262
- # now = Time.zone.now # => Sun, 02 Nov 2014 01:26:28 EDT -04:00
263
- # now + 1000 # => Sun, 02 Nov 2014 01:43:08 EDT -04:00
280
+ # now = Time.zone.now # => Sun, 02 Nov 2014 01:26:28.725182881 EDT -04:00
281
+ # now + 1000 # => Sun, 02 Nov 2014 01:43:08.725182881 EDT -04:00
264
282
  #
265
283
  # If we're adding a Duration of variable length (i.e., years, months, days),
266
284
  # move forward from #time, otherwise move forward from #utc, for accuracy
@@ -269,8 +287,8 @@ module ActiveSupport
269
287
  # For instance, a time + 24.hours will advance exactly 24 hours, while a
270
288
  # time + 1.day will advance 23-25 hours, depending on the day.
271
289
  #
272
- # now + 24.hours # => Mon, 03 Nov 2014 00:26:28 EST -05:00
273
- # now + 1.day # => Mon, 03 Nov 2014 01:26:28 EST -05:00
290
+ # now + 24.hours # => Mon, 03 Nov 2014 00:26:28.725182881 EST -05:00
291
+ # now + 1.day # => Mon, 03 Nov 2014 01:26:28.725182881 EST -05:00
274
292
  def +(other)
275
293
  if duration_of_variable_length?(other)
276
294
  method_missing(:+, other)
@@ -282,12 +300,14 @@ module ActiveSupport
282
300
  alias_method :since, :+
283
301
  alias_method :in, :+
284
302
 
285
- # Returns a new TimeWithZone object that represents the difference between
286
- # the current object's time and the +other+ time.
303
+ # Subtracts an interval of time and returns a new TimeWithZone object unless
304
+ # the other value `acts_like?` time. Then it will return a Float of the difference
305
+ # between the two times that represents the difference between the current
306
+ # object's time and the +other+ time.
287
307
  #
288
308
  # Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
289
- # now = Time.zone.now # => Mon, 03 Nov 2014 00:26:28 EST -05:00
290
- # now - 1000 # => Mon, 03 Nov 2014 00:09:48 EST -05:00
309
+ # now = Time.zone.now # => Mon, 03 Nov 2014 00:26:28.725182881 EST -05:00
310
+ # now - 1000 # => Mon, 03 Nov 2014 00:09:48.725182881 EST -05:00
291
311
  #
292
312
  # If subtracting a Duration of variable length (i.e., years, months, days),
293
313
  # move backward from #time, otherwise move backward from #utc, for accuracy
@@ -296,8 +316,14 @@ module ActiveSupport
296
316
  # For instance, a time - 24.hours will go subtract exactly 24 hours, while a
297
317
  # time - 1.day will subtract 23-25 hours, depending on the day.
298
318
  #
299
- # now - 24.hours # => Sun, 02 Nov 2014 01:26:28 EDT -04:00
300
- # now - 1.day # => Sun, 02 Nov 2014 00:26:28 EDT -04:00
319
+ # now - 24.hours # => Sun, 02 Nov 2014 01:26:28.725182881 EDT -04:00
320
+ # now - 1.day # => Sun, 02 Nov 2014 00:26:28.725182881 EDT -04:00
321
+ #
322
+ # If both the TimeWithZone object and the other value act like Time, a Float
323
+ # will be returned.
324
+ #
325
+ # Time.zone.now - 1.day.ago # => 86399.999967
326
+ #
301
327
  def -(other)
302
328
  if other.acts_like?(:time)
303
329
  to_time - other.to_time
@@ -313,8 +339,8 @@ module ActiveSupport
313
339
  # the result as a new TimeWithZone object.
314
340
  #
315
341
  # Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
316
- # now = Time.zone.now # => Mon, 03 Nov 2014 00:26:28 EST -05:00
317
- # now.ago(1000) # => Mon, 03 Nov 2014 00:09:48 EST -05:00
342
+ # now = Time.zone.now # => Mon, 03 Nov 2014 00:26:28.725182881 EST -05:00
343
+ # now.ago(1000) # => Mon, 03 Nov 2014 00:09:48.725182881 EST -05:00
318
344
  #
319
345
  # If we're subtracting a Duration of variable length (i.e., years, months,
320
346
  # days), move backward from #time, otherwise move backward from #utc, for
@@ -324,12 +350,48 @@ module ActiveSupport
324
350
  # while <tt>time.ago(1.day)</tt> will move back 23-25 hours, depending on
325
351
  # the day.
326
352
  #
327
- # now.ago(24.hours) # => Sun, 02 Nov 2014 01:26:28 EDT -04:00
328
- # now.ago(1.day) # => Sun, 02 Nov 2014 00:26:28 EDT -04:00
353
+ # now.ago(24.hours) # => Sun, 02 Nov 2014 01:26:28.725182881 EDT -04:00
354
+ # now.ago(1.day) # => Sun, 02 Nov 2014 00:26:28.725182881 EDT -04:00
329
355
  def ago(other)
330
356
  since(-other)
331
357
  end
332
358
 
359
+ # Returns a new +ActiveSupport::TimeWithZone+ where one or more of the elements have
360
+ # been changed according to the +options+ parameter. The time options (<tt>:hour</tt>,
361
+ # <tt>:min</tt>, <tt>:sec</tt>, <tt>:usec</tt>, <tt>:nsec</tt>) reset cascadingly,
362
+ # so if only the hour is passed, then minute, sec, usec and nsec is set to 0. If the
363
+ # hour and minute is passed, then sec, usec and nsec is set to 0. The +options+
364
+ # parameter takes a hash with any of these keys: <tt>:year</tt>, <tt>:month</tt>,
365
+ # <tt>:day</tt>, <tt>:hour</tt>, <tt>:min</tt>, <tt>:sec</tt>, <tt>:usec</tt>,
366
+ # <tt>:nsec</tt>, <tt>:offset</tt>, <tt>:zone</tt>. Pass either <tt>:usec</tt>
367
+ # or <tt>:nsec</tt>, not both. Similarly, pass either <tt>:zone</tt> or
368
+ # <tt>:offset</tt>, not both.
369
+ #
370
+ # t = Time.zone.now # => Fri, 14 Apr 2017 11:45:15.116992711 EST -05:00
371
+ # t.change(year: 2020) # => Tue, 14 Apr 2020 11:45:15.116992711 EST -05:00
372
+ # t.change(hour: 12) # => Fri, 14 Apr 2017 12:00:00.116992711 EST -05:00
373
+ # t.change(min: 30) # => Fri, 14 Apr 2017 11:30:00.116992711 EST -05:00
374
+ # t.change(offset: "-10:00") # => Fri, 14 Apr 2017 11:45:15.116992711 HST -10:00
375
+ # t.change(zone: "Hawaii") # => Fri, 14 Apr 2017 11:45:15.116992711 HST -10:00
376
+ def change(options)
377
+ if options[:zone] && options[:offset]
378
+ raise ArgumentError, "Can't change both :offset and :zone at the same time: #{options.inspect}"
379
+ end
380
+
381
+ new_time = time.change(options)
382
+
383
+ if options[:zone]
384
+ new_zone = ::Time.find_zone(options[:zone])
385
+ elsif options[:offset]
386
+ new_zone = ::Time.find_zone(new_time.utc_offset)
387
+ end
388
+
389
+ new_zone ||= time_zone
390
+ periods = new_zone.periods_for_local(new_time)
391
+
392
+ self.class.new(nil, new_zone, new_time, periods.include?(period) ? period : nil)
393
+ end
394
+
333
395
  # Uses Date to provide precise Time calculations for years, months, and days
334
396
  # according to the proleptic Gregorian calendar. The result is returned as a
335
397
  # new TimeWithZone object.
@@ -343,14 +405,14 @@ module ActiveSupport
343
405
  # accuracy when moving across DST boundaries.
344
406
  #
345
407
  # Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
346
- # now = Time.zone.now # => Sun, 02 Nov 2014 01:26:28 EDT -04:00
347
- # now.advance(seconds: 1) # => Sun, 02 Nov 2014 01:26:29 EDT -04:00
348
- # now.advance(minutes: 1) # => Sun, 02 Nov 2014 01:27:28 EDT -04:00
349
- # now.advance(hours: 1) # => Sun, 02 Nov 2014 01:26:28 EST -05:00
350
- # now.advance(days: 1) # => Mon, 03 Nov 2014 01:26:28 EST -05:00
351
- # now.advance(weeks: 1) # => Sun, 09 Nov 2014 01:26:28 EST -05:00
352
- # now.advance(months: 1) # => Tue, 02 Dec 2014 01:26:28 EST -05:00
353
- # now.advance(years: 1) # => Mon, 02 Nov 2015 01:26:28 EST -05:00
408
+ # now = Time.zone.now # => Sun, 02 Nov 2014 01:26:28.558049687 EDT -04:00
409
+ # now.advance(seconds: 1) # => Sun, 02 Nov 2014 01:26:29.558049687 EDT -04:00
410
+ # now.advance(minutes: 1) # => Sun, 02 Nov 2014 01:27:28.558049687 EDT -04:00
411
+ # now.advance(hours: 1) # => Sun, 02 Nov 2014 01:26:28.558049687 EST -05:00
412
+ # now.advance(days: 1) # => Mon, 03 Nov 2014 01:26:28.558049687 EST -05:00
413
+ # now.advance(weeks: 1) # => Sun, 09 Nov 2014 01:26:28.558049687 EST -05:00
414
+ # now.advance(months: 1) # => Tue, 02 Dec 2014 01:26:28.558049687 EST -05:00
415
+ # now.advance(years: 1) # => Mon, 02 Nov 2015 01:26:28.558049687 EST -05:00
354
416
  def advance(options)
355
417
  # If we're advancing a value of variable length (i.e., years, weeks, months, days), advance from #time,
356
418
  # otherwise advance from #utc, for accuracy when moving across DST boundaries
@@ -372,7 +434,7 @@ module ActiveSupport
372
434
  # Returns Array of parts of Time in sequence of
373
435
  # [seconds, minutes, hours, day, month, year, weekday, yearday, dst?, zone].
374
436
  #
375
- # now = Time.zone.now # => Tue, 18 Aug 2015 02:29:27 UTC +00:00
437
+ # now = Time.zone.now # => Tue, 18 Aug 2015 02:29:27.485278555 UTC +00:00
376
438
  # now.to_a # => [27, 29, 2, 18, 8, 2015, 2, 230, false, "UTC"]
377
439
  def to_a
378
440
  [time.sec, time.min, time.hour, time.day, time.mon, time.year, time.wday, time.yday, dst?, zone]
@@ -476,6 +538,16 @@ module ActiveSupport
476
538
  end
477
539
 
478
540
  private
541
+ SECONDS_PER_DAY = 86400
542
+
543
+ def incorporate_utc_offset(time, offset)
544
+ if time.kind_of?(Date)
545
+ time + Rational(offset, SECONDS_PER_DAY)
546
+ else
547
+ time + offset
548
+ end
549
+ end
550
+
479
551
  def get_period_and_ensure_valid_local_time(period)
480
552
  # we don't want a Time.local instance enforcing its own DST rules as well,
481
553
  # so transfer time values to a utc constructor if necessary
@@ -1,12 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "tzinfo"
2
4
  require "concurrent/map"
3
- require "active_support/core_ext/object/blank"
4
5
 
5
6
  module ActiveSupport
6
7
  # The TimeZone class serves as a wrapper around TZInfo::Timezone instances.
7
8
  # It allows us to do the following:
8
9
  #
9
- # * Limit the set of zones provided by TZInfo to a meaningful subset of 146
10
+ # * Limit the set of zones provided by TZInfo to a meaningful subset of 134
10
11
  # zones.
11
12
  # * Retrieve and display zones with a friendlier name
12
13
  # (e.g., "Eastern Time (US & Canada)" instead of "America/New_York").
@@ -28,7 +29,7 @@ module ActiveSupport
28
29
  class TimeZone
29
30
  # Keys are Rails TimeZone names, values are TZInfo identifiers.
30
31
  MAPPING = {
31
- "International Date Line West" => "Pacific/Midway",
32
+ "International Date Line West" => "Etc/GMT+12",
32
33
  "Midway Island" => "Pacific/Midway",
33
34
  "American Samoa" => "Pacific/Pago_Pago",
34
35
  "Hawaii" => "Pacific/Honolulu",
@@ -59,6 +60,7 @@ module ActiveSupport
59
60
  "Buenos Aires" => "America/Argentina/Buenos_Aires",
60
61
  "Montevideo" => "America/Montevideo",
61
62
  "Georgetown" => "America/Guyana",
63
+ "Puerto Rico" => "America/Puerto_Rico",
62
64
  "Greenland" => "America/Godthab",
63
65
  "Mid-Atlantic" => "Atlantic/South_Georgia",
64
66
  "Azores" => "Atlantic/Azores",
@@ -180,8 +182,9 @@ module ActiveSupport
180
182
  "Samoa" => "Pacific/Apia"
181
183
  }
182
184
 
183
- UTC_OFFSET_WITH_COLON = "%s%02d:%02d"
184
- UTC_OFFSET_WITHOUT_COLON = UTC_OFFSET_WITH_COLON.tr(":", "")
185
+ UTC_OFFSET_WITH_COLON = "%s%02d:%02d" # :nodoc:
186
+ UTC_OFFSET_WITHOUT_COLON = UTC_OFFSET_WITH_COLON.tr(":", "") # :nodoc:
187
+ private_constant :UTC_OFFSET_WITH_COLON, :UTC_OFFSET_WITHOUT_COLON
185
188
 
186
189
  @lazy_zones_map = Concurrent::Map.new
187
190
  @country_zones = Concurrent::Map.new
@@ -200,7 +203,7 @@ module ActiveSupport
200
203
  end
201
204
 
202
205
  def find_tzinfo(name)
203
- TZInfo::Timezone.new(MAPPING[name] || name)
206
+ TZInfo::Timezone.get(MAPPING[name] || name)
204
207
  end
205
208
 
206
209
  alias_method :create, :new
@@ -235,7 +238,7 @@ module ActiveSupport
235
238
  when Numeric, ActiveSupport::Duration
236
239
  arg *= 3600 if arg.abs <= 13
237
240
  all.find { |z| z.utc_offset == arg.to_i }
238
- else
241
+ else
239
242
  raise ArgumentError, "invalid argument to TimeZone[]: #{arg.inspect}"
240
243
  end
241
244
  end
@@ -253,22 +256,32 @@ module ActiveSupport
253
256
  @country_zones[code] ||= load_country_zones(code)
254
257
  end
255
258
 
259
+ def clear #:nodoc:
260
+ @lazy_zones_map = Concurrent::Map.new
261
+ @country_zones = Concurrent::Map.new
262
+ @zones = nil
263
+ @zones_map = nil
264
+ end
265
+
256
266
  private
257
267
  def load_country_zones(code)
258
268
  country = TZInfo::Country.get(code)
259
- country.zone_identifiers.map do |tz_id|
269
+ country.zone_identifiers.flat_map do |tz_id|
260
270
  if MAPPING.value?(tz_id)
261
- self[MAPPING.key(tz_id)]
271
+ MAPPING.inject([]) do |memo, (key, value)|
272
+ memo << self[key] if value == tz_id
273
+ memo
274
+ end
262
275
  else
263
- create(tz_id, nil, TZInfo::Timezone.new(tz_id))
276
+ create(tz_id, nil, TZInfo::Timezone.get(tz_id))
264
277
  end
265
278
  end.sort!
266
279
  end
267
280
 
268
281
  def zones_map
269
- @zones_map ||= begin
270
- MAPPING.each_key { |place| self[place] } # load all the zones
271
- @lazy_zones_map
282
+ @zones_map ||= MAPPING.each_with_object({}) do |(name, _), zones|
283
+ timezone = self[name]
284
+ zones[name] = timezone if timezone
272
285
  end
273
286
  end
274
287
  end
@@ -289,11 +302,7 @@ module ActiveSupport
289
302
 
290
303
  # Returns the offset of this time zone from UTC in seconds.
291
304
  def utc_offset
292
- if @utc_offset
293
- @utc_offset
294
- else
295
- tzinfo.current_period.utc_offset if tzinfo && tzinfo.current_period
296
- end
305
+ @utc_offset || tzinfo&.current_period&.base_utc_offset
297
306
  end
298
307
 
299
308
  # Returns a formatted string of the offset from UTC, or an alternative
@@ -321,6 +330,13 @@ module ActiveSupport
321
330
  re === name || re === MAPPING[name]
322
331
  end
323
332
 
333
+ # Compare #name and TZInfo identifier to a supplied regexp, returning +true+
334
+ # if a match is found.
335
+ def match?(re)
336
+ (re == name) || (re == MAPPING[name]) ||
337
+ ((Regexp === re) && (re.match?(name) || re.match?(MAPPING[name])))
338
+ end
339
+
324
340
  # Returns a textual representation of this time zone.
325
341
  def to_s
326
342
  "(GMT#{formatted_offset}) #{name}"
@@ -342,8 +358,13 @@ module ActiveSupport
342
358
  # Time.zone = 'Hawaii' # => "Hawaii"
343
359
  # Time.utc(2000).to_f # => 946684800.0
344
360
  # Time.zone.at(946684800.0) # => Fri, 31 Dec 1999 14:00:00 HST -10:00
345
- def at(secs)
346
- Time.at(secs).utc.in_time_zone(self)
361
+ #
362
+ # A second argument can be supplied to specify sub-second precision.
363
+ #
364
+ # Time.zone = 'Hawaii' # => "Hawaii"
365
+ # Time.at(946684800, 123456.789).nsec # => 123456789
366
+ def at(*args)
367
+ Time.at(*args).utc.in_time_zone(self)
347
368
  end
348
369
 
349
370
  # Method for creating new ActiveSupport::TimeWithZone instance in time zone
@@ -358,7 +379,7 @@ module ActiveSupport
358
379
  # Time.zone.iso8601('1999-12-31') # => Fri, 31 Dec 1999 00:00:00 HST -10:00
359
380
  #
360
381
  # If the string is invalid then an +ArgumentError+ will be raised unlike +parse+
361
- # which returns +nil+ when given an invalid date string.
382
+ # which usually returns +nil+ when given an invalid date string.
362
383
  def iso8601(str)
363
384
  parts = Date._iso8601(str)
364
385
 
@@ -397,6 +418,8 @@ module ActiveSupport
397
418
  # components are supplied, then the day of the month defaults to 1:
398
419
  #
399
420
  # Time.zone.parse('Mar 2000') # => Wed, 01 Mar 2000 00:00:00 HST -10:00
421
+ #
422
+ # If the string is invalid then an +ArgumentError+ could be raised.
400
423
  def parse(str, now = now())
401
424
  parts_to_time(Date._parse(str, false), now)
402
425
  end
@@ -480,10 +503,17 @@ module ActiveSupport
480
503
  end
481
504
 
482
505
  # Adjust the given time to the simultaneous time in the time zone
483
- # represented by +self+. Returns a Time.utc() instance -- if you want an
484
- # ActiveSupport::TimeWithZone instance, use Time#in_time_zone() instead.
506
+ # represented by +self+. Returns a local time with the appropriate offset
507
+ # -- if you want an ActiveSupport::TimeWithZone instance, use
508
+ # Time#in_time_zone() instead.
509
+ #
510
+ # As of tzinfo 2, utc_to_local returns a Time with a non-zero utc_offset.
511
+ # See the `utc_to_local_returns_utc_offset_times` config for more info.
485
512
  def utc_to_local(time)
486
- tzinfo.utc_to_local(time)
513
+ tzinfo.utc_to_local(time).yield_self do |t|
514
+ ActiveSupport.utc_to_local_returns_utc_offset_times ?
515
+ t : Time.utc(t.year, t.month, t.day, t.hour, t.min, t.sec, t.sec_fraction)
516
+ end
487
517
  end
488
518
 
489
519
  # Adjust the given time to the simultaneous time in UTC. Returns a
@@ -501,7 +531,7 @@ module ActiveSupport
501
531
  # Available so that TimeZone instances respond like TZInfo::Timezone
502
532
  # instances.
503
533
  def period_for_local(time, dst = true)
504
- tzinfo.period_for_local(time, dst)
534
+ tzinfo.period_for_local(time, dst) { |periods| periods.last }
505
535
  end
506
536
 
507
537
  def periods_for_local(time) #:nodoc:
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "gem_version"
2
4
 
3
5
  module ActiveSupport
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  raise "JRuby is required to use the JDOM backend for XmlMini" unless RUBY_PLATFORM.include?("java")
2
4
 
3
5
  require "jruby"
@@ -16,7 +18,7 @@ module ActiveSupport
16
18
  module XmlMini_JDOM #:nodoc:
17
19
  extend self
18
20
 
19
- CONTENT_KEY = "__content__".freeze
21
+ CONTENT_KEY = "__content__"
20
22
 
21
23
  NODE_TYPE_NAMES = %w{ATTRIBUTE_NODE CDATA_SECTION_NODE COMMENT_NODE DOCUMENT_FRAGMENT_NODE
22
24
  DOCUMENT_NODE DOCUMENT_TYPE_NODE ELEMENT_NODE ENTITY_NODE ENTITY_REFERENCE_NODE NOTATION_NODE
@@ -38,7 +40,7 @@ module ActiveSupport
38
40
  else
39
41
  @dbf = DocumentBuilderFactory.new_instance
40
42
  # secure processing of java xml
41
- # http://www.ibm.com/developerworks/xml/library/x-tipcfsx/index.html
43
+ # https://archive.is/9xcQQ
42
44
  @dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)
43
45
  @dbf.setFeature("http://xml.org/sax/features/external-general-entities", false)
44
46
  @dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false)
@@ -51,7 +53,6 @@ module ActiveSupport
51
53
  end
52
54
 
53
55
  private
54
-
55
56
  # Convert an XML element and merge into the hash
56
57
  #
57
58
  # hash::
@@ -167,7 +168,7 @@ module ActiveSupport
167
168
  # element::
168
169
  # XML element to be checked.
169
170
  def empty_content?(element)
170
- text = ""
171
+ text = +""
171
172
  child_nodes = element.child_nodes
172
173
  (0...child_nodes.length).each do |i|
173
174
  item = child_nodes.item(i)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "libxml"
2
4
  require "active_support/core_ext/object/blank"
3
5
  require "stringio"
@@ -32,7 +34,7 @@ module LibXML #:nodoc:
32
34
  end
33
35
 
34
36
  module Node #:nodoc:
35
- CONTENT_ROOT = "__content__".freeze
37
+ CONTENT_ROOT = "__content__"
36
38
 
37
39
  # Convert XML document to hash.
38
40
  #
@@ -53,7 +55,7 @@ module LibXML #:nodoc:
53
55
  if c.element?
54
56
  c.to_hash(node_hash)
55
57
  elsif c.text? || c.cdata?
56
- node_hash[CONTENT_ROOT] ||= ""
58
+ node_hash[CONTENT_ROOT] ||= +""
57
59
  node_hash[CONTENT_ROOT] << c.content
58
60
  end
59
61
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "libxml"
2
4
  require "active_support/core_ext/object/blank"
3
5
  require "stringio"
@@ -11,8 +13,8 @@ module ActiveSupport
11
13
  class HashBuilder
12
14
  include LibXML::XML::SaxParser::Callbacks
13
15
 
14
- CONTENT_KEY = "__content__".freeze
15
- HASH_SIZE_KEY = "__hash_size__".freeze
16
+ CONTENT_KEY = "__content__"
17
+ HASH_SIZE_KEY = "__hash_size__"
16
18
 
17
19
  attr_reader :hash
18
20
 
@@ -21,7 +23,7 @@ module ActiveSupport
21
23
  end
22
24
 
23
25
  def on_start_document
24
- @hash = { CONTENT_KEY => "" }
26
+ @hash = { CONTENT_KEY => +"" }
25
27
  @hash_stack = [@hash]
26
28
  end
27
29
 
@@ -31,7 +33,7 @@ module ActiveSupport
31
33
  end
32
34
 
33
35
  def on_start_element(name, attrs = {})
34
- new_hash = { CONTENT_KEY => "" }.merge!(attrs)
36
+ new_hash = { CONTENT_KEY => +"" }.merge!(attrs)
35
37
  new_hash[HASH_SIZE_KEY] = new_hash.size + 1
36
38
 
37
39
  case current_hash[name]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require "nokogiri"
3
5
  rescue LoadError => e
@@ -36,7 +38,7 @@ module ActiveSupport
36
38
  end
37
39
 
38
40
  module Node #:nodoc:
39
- CONTENT_ROOT = "__content__".freeze
41
+ CONTENT_ROOT = "__content__"
40
42
 
41
43
  # Convert XML document to hash.
42
44
  #
@@ -57,7 +59,7 @@ module ActiveSupport
57
59
  if c.element?
58
60
  c.to_hash(node_hash)
59
61
  elsif c.text? || c.cdata?
60
- node_hash[CONTENT_ROOT] ||= ""
62
+ node_hash[CONTENT_ROOT] ||= +""
61
63
  node_hash[CONTENT_ROOT] << c.content
62
64
  end
63
65
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  begin
2
4
  require "nokogiri"
3
5
  rescue LoadError => e
@@ -14,8 +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
- CONTENT_KEY = "__content__".freeze
18
- HASH_SIZE_KEY = "__hash_size__".freeze
19
+ CONTENT_KEY = "__content__"
20
+ HASH_SIZE_KEY = "__hash_size__"
19
21
 
20
22
  attr_reader :hash
21
23
 
@@ -37,7 +39,7 @@ module ActiveSupport
37
39
  end
38
40
 
39
41
  def start_element(name, attrs = [])
40
- new_hash = { CONTENT_KEY => "" }.merge!(Hash[attrs])
42
+ new_hash = { CONTENT_KEY => +"" }.merge!(Hash[attrs])
41
43
  new_hash[HASH_SIZE_KEY] = new_hash.size + 1
42
44
 
43
45
  case current_hash[name]