activesupport 7.0.0 → 7.2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +156 -255
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +6 -6
  5. data/lib/active_support/actionable_error.rb +3 -1
  6. data/lib/active_support/array_inquirer.rb +3 -1
  7. data/lib/active_support/backtrace_cleaner.rb +41 -9
  8. data/lib/active_support/benchmarkable.rb +1 -0
  9. data/lib/active_support/broadcast_logger.rb +251 -0
  10. data/lib/active_support/builder.rb +1 -1
  11. data/lib/active_support/cache/coder.rb +153 -0
  12. data/lib/active_support/cache/entry.rb +134 -0
  13. data/lib/active_support/cache/file_store.rb +49 -17
  14. data/lib/active_support/cache/mem_cache_store.rb +111 -129
  15. data/lib/active_support/cache/memory_store.rb +81 -26
  16. data/lib/active_support/cache/null_store.rb +6 -0
  17. data/lib/active_support/cache/redis_cache_store.rb +175 -154
  18. data/lib/active_support/cache/serializer_with_fallback.rb +152 -0
  19. data/lib/active_support/cache/strategy/local_cache.rb +31 -13
  20. data/lib/active_support/cache.rb +457 -377
  21. data/lib/active_support/callbacks.rb +123 -139
  22. data/lib/active_support/code_generator.rb +15 -10
  23. data/lib/active_support/concern.rb +4 -2
  24. data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +42 -3
  25. data/lib/active_support/concurrency/null_lock.rb +13 -0
  26. data/lib/active_support/configurable.rb +12 -2
  27. data/lib/active_support/core_ext/array/conversions.rb +7 -9
  28. data/lib/active_support/core_ext/array/inquiry.rb +2 -2
  29. data/lib/active_support/core_ext/array.rb +0 -1
  30. data/lib/active_support/core_ext/class/subclasses.rb +4 -15
  31. data/lib/active_support/core_ext/date/blank.rb +4 -0
  32. data/lib/active_support/core_ext/date/calculations.rb +20 -5
  33. data/lib/active_support/core_ext/date/conversions.rb +15 -16
  34. data/lib/active_support/core_ext/date.rb +0 -1
  35. data/lib/active_support/core_ext/date_and_time/calculations.rb +14 -4
  36. data/lib/active_support/core_ext/date_and_time/compatibility.rb +29 -2
  37. data/lib/active_support/core_ext/date_time/blank.rb +4 -0
  38. data/lib/active_support/core_ext/date_time/calculations.rb +4 -0
  39. data/lib/active_support/core_ext/date_time/conversions.rb +15 -15
  40. data/lib/active_support/core_ext/date_time.rb +0 -1
  41. data/lib/active_support/core_ext/digest/uuid.rb +7 -10
  42. data/lib/active_support/core_ext/enumerable.rb +51 -101
  43. data/lib/active_support/core_ext/erb/util.rb +201 -0
  44. data/lib/active_support/core_ext/file/atomic.rb +2 -0
  45. data/lib/active_support/core_ext/hash/conversions.rb +1 -2
  46. data/lib/active_support/core_ext/hash/deep_merge.rb +22 -14
  47. data/lib/active_support/core_ext/hash/deep_transform_values.rb +3 -3
  48. data/lib/active_support/core_ext/hash/indifferent_access.rb +3 -3
  49. data/lib/active_support/core_ext/hash/keys.rb +7 -7
  50. data/lib/active_support/core_ext/integer/inflections.rb +12 -12
  51. data/lib/active_support/core_ext/kernel/singleton_class.rb +1 -1
  52. data/lib/active_support/core_ext/module/attr_internal.rb +17 -6
  53. data/lib/active_support/core_ext/module/attribute_accessors.rb +6 -0
  54. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +38 -20
  55. data/lib/active_support/core_ext/module/concerning.rb +6 -6
  56. data/lib/active_support/core_ext/module/delegation.rb +20 -119
  57. data/lib/active_support/core_ext/module/deprecation.rb +12 -12
  58. data/lib/active_support/core_ext/module/introspection.rb +0 -1
  59. data/lib/active_support/core_ext/numeric/bytes.rb +9 -0
  60. data/lib/active_support/core_ext/numeric/conversions.rb +77 -75
  61. data/lib/active_support/core_ext/numeric.rb +0 -1
  62. data/lib/active_support/core_ext/object/acts_like.rb +29 -5
  63. data/lib/active_support/core_ext/object/blank.rb +45 -1
  64. data/lib/active_support/core_ext/object/deep_dup.rb +16 -0
  65. data/lib/active_support/core_ext/object/duplicable.rb +25 -16
  66. data/lib/active_support/core_ext/object/inclusion.rb +13 -5
  67. data/lib/active_support/core_ext/object/instance_variables.rb +4 -2
  68. data/lib/active_support/core_ext/object/json.rb +17 -7
  69. data/lib/active_support/core_ext/object/to_query.rb +0 -2
  70. data/lib/active_support/core_ext/object/with.rb +46 -0
  71. data/lib/active_support/core_ext/object/with_options.rb +9 -9
  72. data/lib/active_support/core_ext/object.rb +1 -0
  73. data/lib/active_support/core_ext/pathname/blank.rb +20 -0
  74. data/lib/active_support/core_ext/pathname/existence.rb +2 -0
  75. data/lib/active_support/core_ext/pathname.rb +1 -0
  76. data/lib/active_support/core_ext/range/conversions.rb +32 -11
  77. data/lib/active_support/core_ext/range/overlap.rb +40 -0
  78. data/lib/active_support/core_ext/range.rb +1 -2
  79. data/lib/active_support/core_ext/securerandom.rb +2 -6
  80. data/lib/active_support/core_ext/string/conversions.rb +3 -3
  81. data/lib/active_support/core_ext/string/filters.rb +21 -15
  82. data/lib/active_support/core_ext/string/indent.rb +1 -1
  83. data/lib/active_support/core_ext/string/inflections.rb +16 -9
  84. data/lib/active_support/core_ext/string/inquiry.rb +1 -1
  85. data/lib/active_support/core_ext/string/multibyte.rb +1 -1
  86. data/lib/active_support/core_ext/string/output_safety.rb +39 -150
  87. data/lib/active_support/core_ext/thread/backtrace/location.rb +12 -0
  88. data/lib/active_support/core_ext/time/calculations.rb +42 -32
  89. data/lib/active_support/core_ext/time/compatibility.rb +16 -0
  90. data/lib/active_support/core_ext/time/conversions.rb +13 -15
  91. data/lib/active_support/core_ext/time/zones.rb +8 -9
  92. data/lib/active_support/core_ext/time.rb +0 -1
  93. data/lib/active_support/core_ext.rb +0 -1
  94. data/lib/active_support/current_attributes.rb +53 -46
  95. data/lib/active_support/deep_mergeable.rb +53 -0
  96. data/lib/active_support/delegation.rb +202 -0
  97. data/lib/active_support/dependencies/autoload.rb +9 -16
  98. data/lib/active_support/deprecation/behaviors.rb +65 -42
  99. data/lib/active_support/deprecation/constant_accessor.rb +47 -25
  100. data/lib/active_support/deprecation/deprecators.rb +104 -0
  101. data/lib/active_support/deprecation/disallowed.rb +6 -8
  102. data/lib/active_support/deprecation/method_wrappers.rb +6 -23
  103. data/lib/active_support/deprecation/proxy_wrappers.rb +34 -22
  104. data/lib/active_support/deprecation/reporting.rb +49 -27
  105. data/lib/active_support/deprecation.rb +39 -9
  106. data/lib/active_support/deprecator.rb +7 -0
  107. data/lib/active_support/descendants_tracker.rb +66 -175
  108. data/lib/active_support/duration/iso8601_parser.rb +2 -2
  109. data/lib/active_support/duration/iso8601_serializer.rb +1 -4
  110. data/lib/active_support/duration.rb +13 -7
  111. data/lib/active_support/encrypted_configuration.rb +63 -10
  112. data/lib/active_support/encrypted_file.rb +29 -13
  113. data/lib/active_support/environment_inquirer.rb +22 -2
  114. data/lib/active_support/error_reporter/test_helper.rb +15 -0
  115. data/lib/active_support/error_reporter.rb +160 -36
  116. data/lib/active_support/evented_file_update_checker.rb +19 -7
  117. data/lib/active_support/execution_wrapper.rb +23 -28
  118. data/lib/active_support/file_update_checker.rb +5 -3
  119. data/lib/active_support/fork_tracker.rb +4 -32
  120. data/lib/active_support/gem_version.rb +4 -4
  121. data/lib/active_support/gzip.rb +2 -0
  122. data/lib/active_support/hash_with_indifferent_access.rb +41 -25
  123. data/lib/active_support/html_safe_translation.rb +19 -6
  124. data/lib/active_support/i18n.rb +1 -1
  125. data/lib/active_support/i18n_railtie.rb +20 -13
  126. data/lib/active_support/inflector/inflections.rb +2 -0
  127. data/lib/active_support/inflector/methods.rb +28 -18
  128. data/lib/active_support/inflector/transliterate.rb +4 -2
  129. data/lib/active_support/isolated_execution_state.rb +39 -19
  130. data/lib/active_support/json/decoding.rb +2 -1
  131. data/lib/active_support/json/encoding.rb +25 -43
  132. data/lib/active_support/key_generator.rb +13 -5
  133. data/lib/active_support/lazy_load_hooks.rb +33 -7
  134. data/lib/active_support/locale/en.yml +2 -0
  135. data/lib/active_support/log_subscriber/test_helper.rb +2 -2
  136. data/lib/active_support/log_subscriber.rb +76 -36
  137. data/lib/active_support/logger.rb +22 -60
  138. data/lib/active_support/logger_thread_safe_level.rb +10 -32
  139. data/lib/active_support/message_encryptor.rb +200 -55
  140. data/lib/active_support/message_encryptors.rb +141 -0
  141. data/lib/active_support/message_pack/cache_serializer.rb +23 -0
  142. data/lib/active_support/message_pack/extensions.rb +305 -0
  143. data/lib/active_support/message_pack/serializer.rb +63 -0
  144. data/lib/active_support/message_pack.rb +50 -0
  145. data/lib/active_support/message_verifier.rb +220 -89
  146. data/lib/active_support/message_verifiers.rb +135 -0
  147. data/lib/active_support/messages/codec.rb +65 -0
  148. data/lib/active_support/messages/metadata.rb +111 -45
  149. data/lib/active_support/messages/rotation_coordinator.rb +93 -0
  150. data/lib/active_support/messages/rotator.rb +34 -32
  151. data/lib/active_support/messages/serializer_with_fallback.rb +158 -0
  152. data/lib/active_support/multibyte/chars.rb +4 -2
  153. data/lib/active_support/multibyte/unicode.rb +9 -37
  154. data/lib/active_support/notifications/fanout.rb +248 -87
  155. data/lib/active_support/notifications/instrumenter.rb +93 -25
  156. data/lib/active_support/notifications.rb +38 -31
  157. data/lib/active_support/number_helper/number_converter.rb +16 -7
  158. data/lib/active_support/number_helper/number_to_currency_converter.rb +6 -6
  159. data/lib/active_support/number_helper/number_to_human_size_converter.rb +3 -3
  160. data/lib/active_support/number_helper/number_to_phone_converter.rb +1 -0
  161. data/lib/active_support/number_helper.rb +379 -317
  162. data/lib/active_support/option_merger.rb +4 -4
  163. data/lib/active_support/ordered_hash.rb +3 -3
  164. data/lib/active_support/ordered_options.rb +68 -16
  165. data/lib/active_support/parameter_filter.rb +103 -84
  166. data/lib/active_support/proxy_object.rb +8 -3
  167. data/lib/active_support/railtie.rb +30 -25
  168. data/lib/active_support/reloader.rb +13 -5
  169. data/lib/active_support/rescuable.rb +12 -10
  170. data/lib/active_support/secure_compare_rotator.rb +17 -10
  171. data/lib/active_support/string_inquirer.rb +4 -2
  172. data/lib/active_support/subscriber.rb +10 -27
  173. data/lib/active_support/syntax_error_proxy.rb +60 -0
  174. data/lib/active_support/tagged_logging.rb +64 -25
  175. data/lib/active_support/test_case.rb +160 -7
  176. data/lib/active_support/testing/assertions.rb +29 -13
  177. data/lib/active_support/testing/autorun.rb +0 -2
  178. data/lib/active_support/testing/constant_stubbing.rb +54 -0
  179. data/lib/active_support/testing/deprecation.rb +20 -27
  180. data/lib/active_support/testing/error_reporter_assertions.rb +107 -0
  181. data/lib/active_support/testing/isolation.rb +46 -33
  182. data/lib/active_support/testing/method_call_assertions.rb +7 -8
  183. data/lib/active_support/testing/parallelization/server.rb +3 -0
  184. data/lib/active_support/testing/parallelize_executor.rb +8 -3
  185. data/lib/active_support/testing/setup_and_teardown.rb +2 -0
  186. data/lib/active_support/testing/stream.rb +1 -1
  187. data/lib/active_support/testing/strict_warnings.rb +43 -0
  188. data/lib/active_support/testing/tests_without_assertions.rb +19 -0
  189. data/lib/active_support/testing/time_helpers.rb +38 -16
  190. data/lib/active_support/time_with_zone.rb +28 -54
  191. data/lib/active_support/values/time_zone.rb +26 -15
  192. data/lib/active_support/version.rb +1 -1
  193. data/lib/active_support/xml_mini/jdom.rb +3 -10
  194. data/lib/active_support/xml_mini/nokogiri.rb +1 -1
  195. data/lib/active_support/xml_mini/nokogirisax.rb +1 -1
  196. data/lib/active_support/xml_mini/rexml.rb +1 -1
  197. data/lib/active_support/xml_mini.rb +13 -4
  198. data/lib/active_support.rb +15 -3
  199. metadata +142 -21
  200. data/lib/active_support/core_ext/array/deprecated_conversions.rb +0 -25
  201. data/lib/active_support/core_ext/date/deprecated_conversions.rb +0 -26
  202. data/lib/active_support/core_ext/date_time/deprecated_conversions.rb +0 -22
  203. data/lib/active_support/core_ext/numeric/deprecated_conversions.rb +0 -60
  204. data/lib/active_support/core_ext/range/deprecated_conversions.rb +0 -26
  205. data/lib/active_support/core_ext/range/include_time_with_zone.rb +0 -7
  206. data/lib/active_support/core_ext/range/overlaps.rb +0 -10
  207. data/lib/active_support/core_ext/time/deprecated_conversions.rb +0 -22
  208. data/lib/active_support/core_ext/uri.rb +0 -5
  209. data/lib/active_support/deprecation/instance_delegator.rb +0 -38
  210. data/lib/active_support/per_thread_registry.rb +0 -65
  211. data/lib/active_support/ruby_features.rb +0 -7
@@ -2,7 +2,6 @@
2
2
 
3
3
  require "active_support/core_ext/module/redefine_method"
4
4
  require "active_support/core_ext/time/calculations"
5
- require "concurrent/map"
6
5
 
7
6
  module ActiveSupport
8
7
  module Testing
@@ -11,7 +10,7 @@ module ActiveSupport
11
10
  Stub = Struct.new(:object, :method_name, :original_method)
12
11
 
13
12
  def initialize
14
- @stubs = Concurrent::Map.new { |h, k| h[k] = {} }
13
+ @stubs = Hash.new { |h, k| h[k] = {} }
15
14
  end
16
15
 
17
16
  # Stubs object.method_name with the given block
@@ -26,7 +25,7 @@ module ActiveSupport
26
25
  unstub_object(stub)
27
26
  end
28
27
 
29
- new_name = "__simple_stub__#{method_name}"
28
+ new_name = "__simple_stub__#{method_name}__#{object_id}"
30
29
 
31
30
  @stubs[object.object_id][method_name] = Stub.new(object, method_name, new_name)
32
31
 
@@ -76,6 +75,11 @@ module ActiveSupport
76
75
  # stubbing +Time.now+, +Date.today+, and +DateTime.now+. The stubs are automatically removed
77
76
  # at the end of the test.
78
77
  #
78
+ # Note that the usec for the resulting time will be set to 0 to prevent rounding
79
+ # errors with external services, like MySQL (which will round instead of floor,
80
+ # leading to off-by-one-second errors), unless the <tt>with_usec</tt> argument
81
+ # is set to <tt>true</tt>.
82
+ #
79
83
  # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
80
84
  # travel 1.day
81
85
  # Time.current # => Sun, 10 Nov 2013 15:34:49 EST -05:00
@@ -90,11 +94,11 @@ module ActiveSupport
90
94
  # User.create.created_at # => Sun, 10 Nov 2013 15:34:49 EST -05:00
91
95
  # end
92
96
  # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
93
- def travel(duration, &block)
94
- travel_to Time.now + duration, &block
97
+ def travel(duration, with_usec: false, &block)
98
+ travel_to Time.now + duration, with_usec: with_usec, &block
95
99
  end
96
100
 
97
- # Changes current time to the given time by stubbing +Time.now+,
101
+ # Changes current time to the given time by stubbing +Time.now+, +Time.new+,
98
102
  # +Date.today+, and +DateTime.now+ to return the time or date passed into this method.
99
103
  # The stubs are automatically removed at the end of the test.
100
104
  #
@@ -115,7 +119,8 @@ module ActiveSupport
115
119
  #
116
120
  # Note that the usec for the time passed will be set to 0 to prevent rounding
117
121
  # errors with external services, like MySQL (which will round instead of floor,
118
- # leading to off-by-one-second errors).
122
+ # leading to off-by-one-second errors), unless the <tt>with_usec</tt> argument
123
+ # is set to <tt>true</tt>.
119
124
  #
120
125
  # This method also accepts a block, which will return the current time back to its original
121
126
  # state at the end of the block:
@@ -125,7 +130,7 @@ module ActiveSupport
125
130
  # Time.current # => Wed, 24 Nov 2004 01:04:44 EST -05:00
126
131
  # end
127
132
  # Time.current # => Sat, 09 Nov 2013 15:34:49 EST -05:00
128
- def travel_to(date_or_time)
133
+ def travel_to(date_or_time, with_usec: false)
129
134
  if block_given? && in_block
130
135
  travel_to_nested_block_call = <<~MSG
131
136
 
@@ -159,13 +164,30 @@ module ActiveSupport
159
164
  elsif date_or_time.is_a?(String)
160
165
  now = Time.zone.parse(date_or_time)
161
166
  else
162
- now = date_or_time.to_time.change(usec: 0)
167
+ now = date_or_time
168
+ now = now.to_time unless now.is_a?(Time)
169
+ now = now.change(usec: 0) unless with_usec
170
+ end
171
+
172
+ # +now+ must be in local system timezone, because +Time.at(now)+
173
+ # and +now.to_date+ (see stubs below) will use +now+'s timezone too!
174
+ now = now.getlocal
175
+
176
+ stubs = simple_stubs
177
+ stubbed_time = Time.now if stubs.stubbing(Time, :now)
178
+ stubs.stub_object(Time, :now) { at(now) }
179
+
180
+ stubs.stub_object(Time, :new) do |*args, **options|
181
+ if args.empty? && options.empty?
182
+ at(now)
183
+ else
184
+ stub = stubs.stubbing(Time, :new)
185
+ Time.send(stub.original_method, *args, **options)
186
+ end
163
187
  end
164
188
 
165
- stubbed_time = Time.now if simple_stubs.stubbing(Time, :now)
166
- simple_stubs.stub_object(Time, :now) { at(now.to_i) }
167
- simple_stubs.stub_object(Date, :today) { jd(now.to_date.jd) }
168
- simple_stubs.stub_object(DateTime, :now) { jd(now.to_date.jd, now.hour, now.min, now.sec, Rational(now.utc_offset, 86400)) }
189
+ stubs.stub_object(Date, :today) { jd(now.to_date.jd) }
190
+ stubs.stub_object(DateTime, :now) { jd(now.to_date.jd, now.hour, now.min, now.sec, Rational(now.utc_offset, 86400)) }
169
191
 
170
192
  if block_given?
171
193
  begin
@@ -215,7 +237,7 @@ module ActiveSupport
215
237
  end
216
238
  alias_method :unfreeze_time, :travel_back
217
239
 
218
- # Calls +travel_to+ with +Time.now+.
240
+ # Calls +travel_to+ with +Time.now+. Forwards optional <tt>with_usec</tt> argument.
219
241
  #
220
242
  # Time.current # => Sun, 09 Jul 2017 15:34:49 EST -05:00
221
243
  # freeze_time
@@ -231,8 +253,8 @@ module ActiveSupport
231
253
  # User.create.created_at # => Sun, 09 Jul 2017 15:34:49 EST -05:00
232
254
  # end
233
255
  # Time.current # => Sun, 09 Jul 2017 15:34:50 EST -05:00
234
- def freeze_time(&block)
235
- travel_to Time.now, &block
256
+ def freeze_time(with_usec: false, &block)
257
+ travel_to Time.now, with_usec: with_usec, &block
236
258
  end
237
259
 
238
260
  private
@@ -8,12 +8,14 @@ require "active_support/core_ext/object/acts_like"
8
8
  require "active_support/core_ext/date_and_time/compatibility"
9
9
 
10
10
  module ActiveSupport
11
+ # = Active Support \Time With Zone
12
+ #
11
13
  # A Time-like class that can represent a time in any time zone. Necessary
12
14
  # because standard Ruby Time instances are limited to UTC and the
13
15
  # system's <tt>ENV['TZ']</tt> zone.
14
16
  #
15
17
  # You shouldn't ever need to create a TimeWithZone instance directly via +new+.
16
- # Instead use methods +local+, +parse+, +at+ and +now+ on TimeZone instances,
18
+ # Instead use methods +local+, +parse+, +at+, and +now+ on TimeZone instances,
17
19
  # and +in_time_zone+ on Time and DateTime instances.
18
20
  #
19
21
  # Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
@@ -33,25 +35,13 @@ module ActiveSupport
33
35
  # t.dst? # => true
34
36
  # t.utc_offset # => -14400
35
37
  # t.zone # => "EDT"
36
- # t.to_formatted_s(:rfc822) # => "Sun, 18 May 2008 13:27:25 -0400"
38
+ # t.to_fs(:rfc822) # => "Sun, 18 May 2008 13:27:25 -0400"
37
39
  # t + 1.day # => Mon, 19 May 2008 13:27:25.031505668 EDT -04:00
38
40
  # t.beginning_of_year # => Tue, 01 Jan 2008 00:00:00.000000000 EST -05:00
39
41
  # t > Time.utc(1999) # => true
40
42
  # t.is_a?(Time) # => true
41
43
  # t.is_a?(ActiveSupport::TimeWithZone) # => true
42
44
  class TimeWithZone
43
- # Report class name as 'Time' to thwart type checking.
44
- def self.name
45
- ActiveSupport::Deprecation.warn(<<~EOM)
46
- ActiveSupport::TimeWithZone.name has been deprecated and
47
- from Rails 7.1 will use the default Ruby implementation.
48
- You can set `config.active_support.remove_deprecated_time_with_zone_name = true`
49
- to enable the new behavior now.
50
- EOM
51
-
52
- "Time"
53
- end
54
-
55
45
  PRECISIONS = Hash.new { |h, n| h[n] = "%FT%T.%#{n}N" }
56
46
  PRECISIONS[0] = "%FT%T"
57
47
 
@@ -78,7 +68,7 @@ module ActiveSupport
78
68
  alias_method :getutc, :utc
79
69
  alias_method :gmtime, :utc
80
70
 
81
- # Returns the underlying TZInfo::TimezonePeriod.
71
+ # Returns the underlying +TZInfo::TimezonePeriod+.
82
72
  def period
83
73
  @period ||= time_zone.period_for_utc(@utc)
84
74
  end
@@ -95,7 +85,7 @@ module ActiveSupport
95
85
  end
96
86
  alias_method :getlocal, :localtime
97
87
 
98
- # Returns true if the current time is within Daylight Savings Time for the
88
+ # Returns true if the current time is within Daylight Savings \Time for the
99
89
  # specified time zone.
100
90
  #
101
91
  # Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
@@ -202,45 +192,26 @@ module ActiveSupport
202
192
  #
203
193
  # Time.zone.now.rfc2822 # => "Tue, 01 Jan 2013 04:51:39 +0000"
204
194
  def rfc2822
205
- to_formatted_s(:rfc822)
195
+ to_fs(:rfc822)
206
196
  end
207
197
  alias_method :rfc822, :rfc2822
208
198
 
209
- NOT_SET = Object.new # :nodoc:
210
-
211
199
  # Returns a string of the object's date and time.
212
- def to_s(format = NOT_SET)
213
- if format == :db
214
- ActiveSupport::Deprecation.warn(
215
- "TimeWithZone#to_s(:db) is deprecated. Please use TimeWithZone#to_formatted_s(:db) instead."
216
- )
217
- utc.to_formatted_s(format)
218
- elsif formatter = ::Time::DATE_FORMATS[format]
219
- ActiveSupport::Deprecation.warn(
220
- "TimeWithZone#to_s(#{format.inspect}) is deprecated. Please use TimeWithZone#to_formatted_s(#{format.inspect}) instead."
221
- )
222
- formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
223
- elsif format == NOT_SET
224
- "#{time.strftime("%Y-%m-%d %H:%M:%S")} #{formatted_offset(false, 'UTC')}" # mimicking Ruby Time#to_s format
225
- else
226
- ActiveSupport::Deprecation.warn(
227
- "TimeWithZone#to_s(#{format.inspect}) is deprecated. Please use TimeWithZone#to_formatted_s(#{format.inspect}) instead."
228
- )
229
- "#{time.strftime("%Y-%m-%d %H:%M:%S")} #{formatted_offset(false, 'UTC')}" # mimicking Ruby Time#to_s format
230
- end
200
+ def to_s
201
+ "#{time.strftime("%Y-%m-%d %H:%M:%S")} #{formatted_offset(false, 'UTC')}" # mimicking Ruby Time#to_s format
231
202
  end
232
203
 
233
204
  # Returns a string of the object's date and time.
234
205
  #
235
- # This method is aliased to <tt>to_fs</tt>.
206
+ # This method is aliased to <tt>to_formatted_s</tt>.
236
207
  #
237
208
  # Accepts an optional <tt>format</tt>:
238
209
  # * <tt>:default</tt> - default value, mimics Ruby Time#to_s format.
239
- # * <tt>:db</tt> - format outputs time in UTC :db time. See Time#to_formatted_s(:db).
240
- # * Any key in <tt>Time::DATE_FORMATS</tt> can be used. See active_support/core_ext/time/conversions.rb.
241
- def to_formatted_s(format = :default)
210
+ # * <tt>:db</tt> - format outputs time in UTC :db time. See Time#to_fs(:db).
211
+ # * Any key in +Time::DATE_FORMATS+ can be used. See active_support/core_ext/time/conversions.rb.
212
+ def to_fs(format = :default)
242
213
  if format == :db
243
- utc.to_formatted_s(format)
214
+ utc.to_fs(format)
244
215
  elsif formatter = ::Time::DATE_FORMATS[format]
245
216
  formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
246
217
  else
@@ -248,7 +219,7 @@ module ActiveSupport
248
219
  "#{time.strftime("%Y-%m-%d %H:%M:%S")} #{formatted_offset(false, 'UTC')}"
249
220
  end
250
221
  end
251
- alias_method :to_fs, :to_formatted_s
222
+ alias_method :to_formatted_s, :to_fs
252
223
 
253
224
  # Replaces <tt>%Z</tt> directive with +zone before passing to Time#strftime,
254
225
  # so that zone information is correct.
@@ -337,9 +308,8 @@ module ActiveSupport
337
308
  alias_method :in, :+
338
309
 
339
310
  # Subtracts an interval of time and returns a new TimeWithZone object unless
340
- # the other value +acts_like?+ time. Then it will return a Float of the difference
341
- # between the two times that represents the difference between the current
342
- # object's time and the +other+ time.
311
+ # the other value +acts_like?+ time. In which case, it will subtract the
312
+ # other time and return the difference in seconds as a Float.
343
313
  #
344
314
  # Time.zone = 'Eastern Time (US & Canada)' # => 'Eastern Time (US & Canada)'
345
315
  # now = Time.zone.now # => Mon, 03 Nov 2014 00:26:28.725182881 EST -05:00
@@ -362,7 +332,7 @@ module ActiveSupport
362
332
  #
363
333
  def -(other)
364
334
  if other.acts_like?(:time)
365
- to_time - other.to_time
335
+ getutc - other.getutc
366
336
  elsif duration_of_variable_length?(other)
367
337
  method_missing(:-, other)
368
338
  else
@@ -395,8 +365,8 @@ module ActiveSupport
395
365
  # Returns a new +ActiveSupport::TimeWithZone+ where one or more of the elements have
396
366
  # been changed according to the +options+ parameter. The time options (<tt>:hour</tt>,
397
367
  # <tt>:min</tt>, <tt>:sec</tt>, <tt>:usec</tt>, <tt>:nsec</tt>) reset cascadingly,
398
- # so if only the hour is passed, then minute, sec, usec and nsec is set to 0. If the
399
- # hour and minute is passed, then sec, usec and nsec is set to 0. The +options+
368
+ # so if only the hour is passed, then minute, sec, usec, and nsec is set to 0. If the
369
+ # hour and minute is passed, then sec, usec, and nsec is set to 0. The +options+
400
370
  # parameter takes a hash with any of these keys: <tt>:year</tt>, <tt>:month</tt>,
401
371
  # <tt>:day</tt>, <tt>:hour</tt>, <tt>:min</tt>, <tt>:sec</tt>, <tt>:usec</tt>,
402
372
  # <tt>:nsec</tt>, <tt>:offset</tt>, <tt>:zone</tt>. Pass either <tt>:usec</tt>
@@ -405,8 +375,8 @@ module ActiveSupport
405
375
  #
406
376
  # t = Time.zone.now # => Fri, 14 Apr 2017 11:45:15.116992711 EST -05:00
407
377
  # t.change(year: 2020) # => Tue, 14 Apr 2020 11:45:15.116992711 EST -05:00
408
- # t.change(hour: 12) # => Fri, 14 Apr 2017 12:00:00.116992711 EST -05:00
409
- # t.change(min: 30) # => Fri, 14 Apr 2017 11:30:00.116992711 EST -05:00
378
+ # t.change(hour: 12) # => Fri, 14 Apr 2017 12:00:00.000000000 EST -05:00
379
+ # t.change(min: 30) # => Fri, 14 Apr 2017 11:30:00.000000000 EST -05:00
410
380
  # t.change(offset: "-10:00") # => Fri, 14 Apr 2017 11:45:15.116992711 HST -10:00
411
381
  # t.change(zone: "Hawaii") # => Fri, 14 Apr 2017 11:45:15.116992711 HST -10:00
412
382
  def change(options)
@@ -536,6 +506,10 @@ module ActiveSupport
536
506
  false
537
507
  end
538
508
 
509
+ def present? # :nodoc:
510
+ true
511
+ end
512
+
539
513
  def freeze
540
514
  # preload instance variables before freezing
541
515
  period; utc; time; to_datetime; to_time
@@ -567,8 +541,8 @@ module ActiveSupport
567
541
 
568
542
  # Send the missing method to +time+ instance, and wrap result in a new
569
543
  # TimeWithZone with the existing +time_zone+.
570
- def method_missing(sym, *args, &block)
571
- wrap_with_time_zone time.__send__(sym, *args, &block)
544
+ def method_missing(...)
545
+ wrap_with_time_zone time.__send__(...)
572
546
  rescue NoMethodError => e
573
547
  raise e, e.message.sub(time.inspect, inspect).sub("Time", "ActiveSupport::TimeWithZone"), e.backtrace
574
548
  end
@@ -4,18 +4,20 @@ require "tzinfo"
4
4
  require "concurrent/map"
5
5
 
6
6
  module ActiveSupport
7
- # The TimeZone class serves as a wrapper around TZInfo::Timezone instances.
7
+ # = Active Support \Time Zone
8
+ #
9
+ # The TimeZone class serves as a wrapper around +TZInfo::Timezone+ instances.
8
10
  # It allows us to do the following:
9
11
  #
10
12
  # * Limit the set of zones provided by TZInfo to a meaningful subset of 134
11
13
  # zones.
12
14
  # * Retrieve and display zones with a friendlier name
13
- # (e.g., "Eastern Time (US & Canada)" instead of "America/New_York").
14
- # * Lazily load TZInfo::Timezone instances only when they're needed.
15
+ # (e.g., "Eastern \Time (US & Canada)" instead of "America/New_York").
16
+ # * Lazily load +TZInfo::Timezone+ instances only when they're needed.
15
17
  # * Create ActiveSupport::TimeWithZone instances via TimeZone's +local+,
16
- # +parse+, +at+ and +now+ methods.
18
+ # +parse+, +at+, and +now+ methods.
17
19
  #
18
- # If you set <tt>config.time_zone</tt> in the Rails Application, you can
20
+ # If you set <tt>config.time_zone</tt> in the \Rails Application, you can
19
21
  # access this TimeZone object via <tt>Time.zone</tt>:
20
22
  #
21
23
  # # application.rb:
@@ -27,7 +29,7 @@ module ActiveSupport
27
29
  # Time.zone.name # => "Eastern Time (US & Canada)"
28
30
  # Time.zone.now # => Sun, 18 May 2008 14:30:44 EDT -04:00
29
31
  class TimeZone
30
- # Keys are Rails TimeZone names, values are TZInfo identifiers.
32
+ # Keys are \Rails TimeZone names, values are TZInfo identifiers.
31
33
  MAPPING = {
32
34
  "International Date Line West" => "Etc/GMT+12",
33
35
  "Midway Island" => "Pacific/Midway",
@@ -132,10 +134,10 @@ module ActiveSupport
132
134
  "Mumbai" => "Asia/Kolkata",
133
135
  "New Delhi" => "Asia/Kolkata",
134
136
  "Kathmandu" => "Asia/Kathmandu",
135
- "Astana" => "Asia/Dhaka",
136
137
  "Dhaka" => "Asia/Dhaka",
137
138
  "Sri Jayawardenepura" => "Asia/Colombo",
138
139
  "Almaty" => "Asia/Almaty",
140
+ "Astana" => "Asia/Almaty",
139
141
  "Novosibirsk" => "Asia/Novosibirsk",
140
142
  "Rangoon" => "Asia/Rangoon",
141
143
  "Bangkok" => "Asia/Bangkok",
@@ -159,7 +161,7 @@ module ActiveSupport
159
161
  "Yakutsk" => "Asia/Yakutsk",
160
162
  "Darwin" => "Australia/Darwin",
161
163
  "Adelaide" => "Australia/Adelaide",
162
- "Canberra" => "Australia/Melbourne",
164
+ "Canberra" => "Australia/Canberra",
163
165
  "Melbourne" => "Australia/Melbourne",
164
166
  "Sydney" => "Australia/Sydney",
165
167
  "Brisbane" => "Australia/Brisbane",
@@ -206,7 +208,9 @@ module ActiveSupport
206
208
  TZInfo::Timezone.get(MAPPING[name] || name)
207
209
  end
208
210
 
211
+ # :stopdoc:
209
212
  alias_method :create, :new
213
+ # :startdoc:
210
214
 
211
215
  # Returns a TimeZone instance with the given name, or +nil+ if no
212
216
  # such TimeZone instance exists. (This exists to support the use of
@@ -294,15 +298,22 @@ module ActiveSupport
294
298
  attr_reader :name
295
299
  attr_reader :tzinfo
296
300
 
301
+ ##
302
+ # :singleton-method: create
303
+ # :call-seq: create(name, utc_offset = nil, tzinfo = nil)
304
+ #
297
305
  # Create a new TimeZone object with the given name and offset. The
298
306
  # offset is the number of seconds that this time zone is offset from UTC
299
307
  # (GMT). Seconds were chosen as the offset unit because that is the unit
300
308
  # that Ruby uses to represent time zone offsets (see Time#utc_offset).
309
+
310
+ # :stopdoc:
301
311
  def initialize(name, utc_offset = nil, tzinfo = nil)
302
312
  @name = name
303
313
  @utc_offset = utc_offset
304
314
  @tzinfo = tzinfo || TimeZone.find_tzinfo(name)
305
315
  end
316
+ # :startdoc:
306
317
 
307
318
  # Returns the offset of this time zone from UTC in seconds.
308
319
  def utc_offset
@@ -346,7 +357,7 @@ module ActiveSupport
346
357
  "(GMT#{formatted_offset}) #{name}"
347
358
  end
348
359
 
349
- # Method for creating new ActiveSupport::TimeWithZone instance in time zone
360
+ # \Method for creating new ActiveSupport::TimeWithZone instance in time zone
350
361
  # of +self+ from given values.
351
362
  #
352
363
  # Time.zone = 'Hawaii' # => "Hawaii"
@@ -356,7 +367,7 @@ module ActiveSupport
356
367
  ActiveSupport::TimeWithZone.new(nil, self, time)
357
368
  end
358
369
 
359
- # Method for creating new ActiveSupport::TimeWithZone instance in time zone
370
+ # \Method for creating new ActiveSupport::TimeWithZone instance in time zone
360
371
  # of +self+ from number of seconds since the Unix epoch.
361
372
  #
362
373
  # Time.zone = 'Hawaii' # => "Hawaii"
@@ -371,7 +382,7 @@ module ActiveSupport
371
382
  Time.at(*args).utc.in_time_zone(self)
372
383
  end
373
384
 
374
- # Method for creating new ActiveSupport::TimeWithZone instance in time zone
385
+ # \Method for creating new ActiveSupport::TimeWithZone instance in time zone
375
386
  # of +self+ from an ISO 8601 string.
376
387
  #
377
388
  # Time.zone = 'Hawaii' # => "Hawaii"
@@ -423,7 +434,7 @@ module ActiveSupport
423
434
  raise ArgumentError, "invalid date"
424
435
  end
425
436
 
426
- # Method for creating new ActiveSupport::TimeWithZone instance in time zone
437
+ # \Method for creating new ActiveSupport::TimeWithZone instance in time zone
427
438
  # of +self+ from parsed string.
428
439
  #
429
440
  # Time.zone = 'Hawaii' # => "Hawaii"
@@ -445,7 +456,7 @@ module ActiveSupport
445
456
  parts_to_time(Date._parse(str, false), now)
446
457
  end
447
458
 
448
- # Method for creating new ActiveSupport::TimeWithZone instance in time zone
459
+ # \Method for creating new ActiveSupport::TimeWithZone instance in time zone
449
460
  # of +self+ from an RFC 3339 string.
450
461
  #
451
462
  # Time.zone = 'Hawaii' # => "Hawaii"
@@ -543,13 +554,13 @@ module ActiveSupport
543
554
  tzinfo.local_to_utc(time, dst)
544
555
  end
545
556
 
546
- # Available so that TimeZone instances respond like TZInfo::Timezone
557
+ # Available so that TimeZone instances respond like +TZInfo::Timezone+
547
558
  # instances.
548
559
  def period_for_utc(time)
549
560
  tzinfo.period_for_utc(time)
550
561
  end
551
562
 
552
- # Available so that TimeZone instances respond like TZInfo::Timezone
563
+ # Available so that TimeZone instances respond like +TZInfo::Timezone+
553
564
  # instances.
554
565
  def period_for_local(time, dst = true)
555
566
  tzinfo.period_for_local(time, dst) { |periods| periods.last }
@@ -3,7 +3,7 @@
3
3
  require_relative "gem_version"
4
4
 
5
5
  module ActiveSupport
6
- # Returns the version of the currently loaded ActiveSupport as a <tt>Gem::Version</tt>
6
+ # Returns the currently loaded version of Active Support as a +Gem::Version+.
7
7
  def self.version
8
8
  gem_version
9
9
  end
@@ -20,13 +20,6 @@ module ActiveSupport
20
20
 
21
21
  CONTENT_KEY = "__content__"
22
22
 
23
- NODE_TYPE_NAMES = %w{ATTRIBUTE_NODE CDATA_SECTION_NODE COMMENT_NODE DOCUMENT_FRAGMENT_NODE
24
- DOCUMENT_NODE DOCUMENT_TYPE_NODE ELEMENT_NODE ENTITY_NODE ENTITY_REFERENCE_NODE NOTATION_NODE
25
- PROCESSING_INSTRUCTION_NODE TEXT_NODE}
26
-
27
- node_type_map = {}
28
- NODE_TYPE_NAMES.each { |type| node_type_map[Node.send(type)] = type }
29
-
30
23
  # Parse an XML Document string or IO into a simple hash using Java's jdom.
31
24
  # data::
32
25
  # XML Document string or IO to parse
@@ -80,7 +73,7 @@ module ActiveSupport
80
73
  if child_nodes.length > 0
81
74
  (0...child_nodes.length).each do |i|
82
75
  child = child_nodes.item(i)
83
- merge_element!(hash, child, depth - 1) unless child.node_type == Node.TEXT_NODE
76
+ merge_element!(hash, child, depth - 1) unless child.node_type == Node::TEXT_NODE
84
77
  end
85
78
  merge_texts!(hash, element) unless empty_content?(element)
86
79
  hash
@@ -156,7 +149,7 @@ module ActiveSupport
156
149
  child_nodes = element.child_nodes
157
150
  (0...child_nodes.length).each do |i|
158
151
  item = child_nodes.item(i)
159
- if item.node_type == Node.TEXT_NODE
152
+ if item.node_type == Node::TEXT_NODE
160
153
  texts << item.get_data
161
154
  end
162
155
  end
@@ -172,7 +165,7 @@ module ActiveSupport
172
165
  child_nodes = element.child_nodes
173
166
  (0...child_nodes.length).each do |i|
174
167
  item = child_nodes.item(i)
175
- if item.node_type == Node.TEXT_NODE
168
+ if item.node_type == Node::TEXT_NODE
176
169
  text << item.get_data.strip
177
170
  end
178
171
  end
@@ -3,7 +3,7 @@
3
3
  begin
4
4
  require "nokogiri"
5
5
  rescue LoadError => e
6
- $stderr.puts "You don't have nokogiri installed in your application. Please add it to your Gemfile and run bundle install"
6
+ warn "You don't have nokogiri installed in your application. Please add it to your Gemfile and run bundle install"
7
7
  raise e
8
8
  end
9
9
  require "active_support/core_ext/object/blank"
@@ -3,7 +3,7 @@
3
3
  begin
4
4
  require "nokogiri"
5
5
  rescue LoadError => e
6
- $stderr.puts "You don't have nokogiri installed in your application. Please add it to your Gemfile and run bundle install"
6
+ warn "You don't have nokogiri installed in your application. Please add it to your Gemfile and run bundle install"
7
7
  raise e
8
8
  end
9
9
  require "active_support/core_ext/object/blank"
@@ -41,7 +41,7 @@ module ActiveSupport
41
41
  def require_rexml
42
42
  silence_warnings { require "rexml/document" }
43
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"
44
+ warn "You don't have rexml installed in your application. Please add it to your Gemfile and run bundle install"
45
45
  raise e
46
46
  end
47
47
 
@@ -9,10 +9,10 @@ require "active_support/core_ext/string/inflections"
9
9
  require "active_support/core_ext/date_time/calculations"
10
10
 
11
11
  module ActiveSupport
12
- # = XmlMini
12
+ # = \XmlMini
13
13
  #
14
14
  # To use the much faster libxml parser:
15
- # gem 'libxml-ruby', '=0.9.7'
15
+ # gem "libxml-ruby"
16
16
  # XmlMini.backend = 'LibXML'
17
17
  module XmlMini
18
18
  extend self
@@ -46,6 +46,7 @@ module ActiveSupport
46
46
  "Date" => "date",
47
47
  "DateTime" => "dateTime",
48
48
  "Time" => "dateTime",
49
+ "ActiveSupport::Duration" => "duration",
49
50
  "Array" => "array",
50
51
  "Hash" => "hash"
51
52
  }
@@ -54,8 +55,9 @@ module ActiveSupport
54
55
 
55
56
  FORMATTING = {
56
57
  "symbol" => Proc.new { |symbol| symbol.to_s },
57
- "date" => Proc.new { |date| date.to_formatted_s(:db) },
58
+ "date" => Proc.new { |date| date.to_fs(:db) },
58
59
  "dateTime" => Proc.new { |time| time.xmlschema },
60
+ "duration" => Proc.new { |duration| duration.iso8601 },
59
61
  "binary" => Proc.new { |binary| ::Base64.encode64(binary) },
60
62
  "yaml" => Proc.new { |yaml| yaml.to_yaml }
61
63
  } unless defined?(FORMATTING)
@@ -66,6 +68,7 @@ module ActiveSupport
66
68
  "symbol" => Proc.new { |symbol| symbol.to_s.to_sym },
67
69
  "date" => Proc.new { |date| ::Date.parse(date) },
68
70
  "datetime" => Proc.new { |time| Time.xmlschema(time).utc rescue ::DateTime.parse(time).utc },
71
+ "duration" => Proc.new { |duration| Duration.parse(duration) },
69
72
  "integer" => Proc.new { |integer| integer.to_i },
70
73
  "float" => Proc.new { |float| float.to_f },
71
74
  "decimal" => Proc.new do |number|
@@ -79,6 +82,7 @@ module ActiveSupport
79
82
  "string" => Proc.new { |string| string.to_s },
80
83
  "yaml" => Proc.new { |yaml| YAML.load(yaml) rescue yaml },
81
84
  "base64Binary" => Proc.new { |bin| ::Base64.decode64(bin) },
85
+ "hexBinary" => Proc.new { |bin| _parse_hex_binary(bin) },
82
86
  "binary" => Proc.new { |bin, entity| _parse_binary(bin, entity) },
83
87
  "file" => Proc.new { |file, entity| _parse_file(file, entity) }
84
88
  }
@@ -162,11 +166,12 @@ module ActiveSupport
162
166
  "#{left}#{middle.tr('_ ', '--')}#{right}"
163
167
  end
164
168
 
165
- # TODO: Add support for other encodings
166
169
  def _parse_binary(bin, entity)
167
170
  case entity["encoding"]
168
171
  when "base64"
169
172
  ::Base64.decode64(bin)
173
+ when "hex", "hexBinary"
174
+ _parse_hex_binary(bin)
170
175
  else
171
176
  bin
172
177
  end
@@ -180,6 +185,10 @@ module ActiveSupport
180
185
  f
181
186
  end
182
187
 
188
+ def _parse_hex_binary(bin)
189
+ [bin].pack("H*")
190
+ end
191
+
183
192
  def current_thread_backend
184
193
  IsolatedExecutionState[:xml_mini_backend]
185
194
  end