activesupport 7.0.0 → 7.0.2.2

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 (29) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +31 -0
  3. data/MIT-LICENSE +1 -1
  4. data/lib/active_support/core_ext/array/conversions.rb +6 -6
  5. data/lib/active_support/core_ext/array/deprecated_conversions.rb +2 -2
  6. data/lib/active_support/core_ext/class/subclasses.rb +23 -17
  7. data/lib/active_support/core_ext/date/conversions.rb +11 -11
  8. data/lib/active_support/core_ext/date/deprecated_conversions.rb +2 -2
  9. data/lib/active_support/core_ext/date_time/conversions.rb +13 -13
  10. data/lib/active_support/core_ext/date_time/deprecated_conversions.rb +2 -2
  11. data/lib/active_support/core_ext/enumerable.rb +24 -24
  12. data/lib/active_support/core_ext/file/atomic.rb +2 -0
  13. data/lib/active_support/core_ext/numeric/conversions.rb +71 -71
  14. data/lib/active_support/core_ext/numeric/deprecated_conversions.rb +8 -8
  15. data/lib/active_support/core_ext/object/acts_like.rb +29 -5
  16. data/lib/active_support/core_ext/range/conversions.rb +6 -6
  17. data/lib/active_support/core_ext/range/deprecated_conversions.rb +2 -2
  18. data/lib/active_support/core_ext/time/conversions.rb +12 -12
  19. data/lib/active_support/core_ext/time/deprecated_conversions.rb +2 -2
  20. data/lib/active_support/descendants_tracker.rb +1 -4
  21. data/lib/active_support/encrypted_configuration.rb +2 -1
  22. data/lib/active_support/execution_wrapper.rb +19 -23
  23. data/lib/active_support/gem_version.rb +2 -2
  24. data/lib/active_support/isolated_execution_state.rb +8 -0
  25. data/lib/active_support/reloader.rb +1 -1
  26. data/lib/active_support/time_with_zone.rb +11 -11
  27. data/lib/active_support/xml_mini.rb +1 -1
  28. data/lib/active_support.rb +1 -1
  29. metadata +9 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa0345240163d6b0d98012c437fc988d7c6b957264b42be1c095cb759ed0b102
4
- data.tar.gz: 3533cafb988ce3d2ace9b21f2a78d8bb76aeb6524ecc8b0d71743ee3af64c3c4
3
+ metadata.gz: 480bb0a63a96ae3fb951d8cabf2d012331916489f6c2d8a7fff8c04dfee378d5
4
+ data.tar.gz: 611b1c0a39cbea9edae09e3d129d0c7bff941d431cb98e1e236907929b7a4610
5
5
  SHA512:
6
- metadata.gz: 5e84aa52f105e68d791fc59101c3f288c86d21a0e26eccd5b3ef9643b82205811f0116055675dffa23c22f9ef126e5c3e52b6113332fd9b3540d90e80afca6a0
7
- data.tar.gz: bd68dd8c4eeebf5c956bb32e6617c2821dba0abdd344aa1f0b8e4f5f3674b1a5d1c3ea19d4b29f99222388ddeef164fcb2183c440af8bc1cab8a86e39aede24a
6
+ metadata.gz: 45da4b770dbca53981ffee48b8a0eac44015df8bedb4bf302ee9453479ce0ed9a8de16eeb51da2a5d35c3d19a8cafcb01910c9b6d2d70627de19092eded8aad3
7
+ data.tar.gz: babc18127ee0c122ccd757a25c5653737dda1d6af6059f58bcbee985113505e4b6e088c8e097684eacdb8b38c4af4d49d00c306d26711983b78d7b21bf6294d0
data/CHANGELOG.md CHANGED
@@ -1,3 +1,34 @@
1
+ ## Rails 7.0.2.2 (February 11, 2022) ##
2
+
3
+ * Fix Reloader method signature to work with the new Executor signature
4
+
5
+
6
+ ## Rails 7.0.2.1 (February 11, 2022) ##
7
+
8
+ * No changes.
9
+
10
+
11
+ ## Rails 7.0.2 (February 08, 2022) ##
12
+
13
+ * Fix `ActiveSupport::EncryptedConfiguration` to be compatible with Psych 4
14
+
15
+ *Stephen Sugden*
16
+
17
+ * Improve `File.atomic_write` error handling.
18
+
19
+ *Daniel Pepper*
20
+
21
+
22
+ ## Rails 7.0.1 (January 06, 2022) ##
23
+
24
+ * Fix `Class#descendants` and `DescendantsTracker#descendants` compatibility with Ruby 3.1.
25
+
26
+ [The native `Class#descendants` was reverted prior to Ruby 3.1 release](https://bugs.ruby-lang.org/issues/14394#note-33),
27
+ but `Class#subclasses` was kept, breaking the feature detection.
28
+
29
+ *Jean Boussier*
30
+
31
+
1
32
  ## Rails 7.0.0 (December 15, 2021) ##
2
33
 
3
34
  * Fix `ActiveSupport::Duration.build` to support negative values.
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2005-2021 David Heinemeier Hansson
1
+ Copyright (c) 2005-2022 David Heinemeier Hansson
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -87,12 +87,12 @@ class Array
87
87
  # Extends <tt>Array#to_s</tt> to convert a collection of elements into a
88
88
  # comma separated id list if <tt>:db</tt> argument is given as the format.
89
89
  #
90
- # This method is aliased to <tt>to_fs</tt>.
90
+ # This method is aliased to <tt>to_formatted_s</tt>.
91
91
  #
92
- # Blog.all.to_formatted_s(:db) # => "1,2,3"
93
- # Blog.none.to_formatted_s(:db) # => "null"
94
- # [1,2].to_formatted_s # => "[1, 2]"
95
- def to_formatted_s(format = :default)
92
+ # Blog.all.to_fs(:db) # => "1,2,3"
93
+ # Blog.none.to_fs(:db) # => "null"
94
+ # [1,2].to_fs # => "[1, 2]"
95
+ def to_fs(format = :default)
96
96
  case format
97
97
  when :db
98
98
  if empty?
@@ -104,7 +104,7 @@ class Array
104
104
  to_default_s
105
105
  end
106
106
  end
107
- alias_method :to_fs, :to_formatted_s
107
+ alias_method :to_formatted_s, :to_fs
108
108
  alias_method :to_default_s, :to_s
109
109
 
110
110
  # Returns a string that represents the array in XML by invoking +to_xml+
@@ -6,7 +6,7 @@ class Array
6
6
  case format
7
7
  when :db
8
8
  ActiveSupport::Deprecation.warn(
9
- "Array#to_s(#{format.inspect}) is deprecated. Please use Array#to_formatted_s(#{format.inspect}) instead."
9
+ "Array#to_s(#{format.inspect}) is deprecated. Please use Array#to_fs(#{format.inspect}) instead."
10
10
  )
11
11
  if empty?
12
12
  "null"
@@ -17,7 +17,7 @@ class Array
17
17
  to_default_s
18
18
  else
19
19
  ActiveSupport::Deprecation.warn(
20
- "Array#to_s(#{format.inspect}) is deprecated. Please use Array#to_formatted_s(#{format.inspect}) instead."
20
+ "Array#to_s(#{format.inspect}) is deprecated. Please use Array#to_fs(#{format.inspect}) instead."
21
21
  )
22
22
  to_default_s
23
23
  end
@@ -3,24 +3,30 @@
3
3
  require "active_support/ruby_features"
4
4
 
5
5
  class Class
6
- # Returns an array with all classes that are < than its receiver.
7
- #
8
- # class C; end
9
- # C.descendants # => []
10
- #
11
- # class B < C; end
12
- # C.descendants # => [B]
13
- #
14
- # class A < B; end
15
- # C.descendants # => [B, A]
16
- #
17
- # class D < C; end
18
- # C.descendants # => [B, A, D]
19
- def descendants
20
- ObjectSpace.each_object(singleton_class).reject do |k|
21
- k.singleton_class? || k == self
6
+ if ActiveSupport::RubyFeatures::CLASS_SUBCLASSES
7
+ # Returns an array with all classes that are < than its receiver.
8
+ #
9
+ # class C; end
10
+ # C.descendants # => []
11
+ #
12
+ # class B < C; end
13
+ # C.descendants # => [B]
14
+ #
15
+ # class A < B; end
16
+ # C.descendants # => [B, A]
17
+ #
18
+ # class D < C; end
19
+ # C.descendants # => [B, A, D]
20
+ def descendants
21
+ subclasses.concat(subclasses.flat_map(&:descendants))
22
22
  end
23
- end unless ActiveSupport::RubyFeatures::CLASS_SUBCLASSES
23
+ else
24
+ def descendants
25
+ ObjectSpace.each_object(singleton_class).reject do |k|
26
+ k.singleton_class? || k == self
27
+ end
28
+ end
29
+ end
24
30
 
25
31
  # Returns an array with the direct children of +self+.
26
32
  #
@@ -22,21 +22,21 @@ class Date
22
22
 
23
23
  # Convert to a formatted string. See DATE_FORMATS for predefined formats.
24
24
  #
25
- # This method is aliased to <tt>to_fs</tt>.
25
+ # This method is aliased to <tt>to_formatted_s</tt>.
26
26
  #
27
27
  # date = Date.new(2007, 11, 10) # => Sat, 10 Nov 2007
28
28
  #
29
- # date.to_formatted_s(:db) # => "2007-11-10"
30
29
  # date.to_fs(:db) # => "2007-11-10"
30
+ # date.to_formatted_s(:db) # => "2007-11-10"
31
31
  #
32
- # date.to_formatted_s(:short) # => "10 Nov"
33
- # date.to_formatted_s(:number) # => "20071110"
34
- # date.to_formatted_s(:long) # => "November 10, 2007"
35
- # date.to_formatted_s(:long_ordinal) # => "November 10th, 2007"
36
- # date.to_formatted_s(:rfc822) # => "10 Nov 2007"
37
- # date.to_formatted_s(:iso8601) # => "2007-11-10"
32
+ # date.to_fs(:short) # => "10 Nov"
33
+ # date.to_fs(:number) # => "20071110"
34
+ # date.to_fs(:long) # => "November 10, 2007"
35
+ # date.to_fs(:long_ordinal) # => "November 10th, 2007"
36
+ # date.to_fs(:rfc822) # => "10 Nov 2007"
37
+ # date.to_fs(:iso8601) # => "2007-11-10"
38
38
  #
39
- # == Adding your own date formats to to_formatted_s
39
+ # == Adding your own date formats to to_fs
40
40
  # You can add your own formats to the Date::DATE_FORMATS hash.
41
41
  # Use the format name as the hash key and either a strftime string
42
42
  # or Proc instance that takes a date argument as the value.
@@ -44,7 +44,7 @@ class Date
44
44
  # # config/initializers/date_formats.rb
45
45
  # Date::DATE_FORMATS[:month_and_year] = '%B %Y'
46
46
  # Date::DATE_FORMATS[:short_ordinal] = ->(date) { date.strftime("%B #{date.day.ordinalize}") }
47
- def to_formatted_s(format = :default)
47
+ def to_fs(format = :default)
48
48
  if formatter = DATE_FORMATS[format]
49
49
  if formatter.respond_to?(:call)
50
50
  formatter.call(self).to_s
@@ -55,7 +55,7 @@ class Date
55
55
  to_default_s
56
56
  end
57
57
  end
58
- alias_method :to_fs, :to_formatted_s
58
+ alias_method :to_formatted_s, :to_fs
59
59
  alias_method :to_default_s, :to_s
60
60
 
61
61
  # Overrides the default inspect method with a human readable one, e.g., "Mon, 21 Feb 2005"
@@ -7,7 +7,7 @@ class Date
7
7
  def to_s(format = NOT_SET) # :nodoc:
8
8
  if formatter = DATE_FORMATS[format]
9
9
  ActiveSupport::Deprecation.warn(
10
- "Date#to_s(#{format.inspect}) is deprecated. Please use Date#to_formatted_s(#{format.inspect}) instead."
10
+ "Date#to_s(#{format.inspect}) is deprecated. Please use Date#to_fs(#{format.inspect}) instead."
11
11
  )
12
12
  if formatter.respond_to?(:call)
13
13
  formatter.call(self).to_s
@@ -18,7 +18,7 @@ class Date
18
18
  to_default_s
19
19
  else
20
20
  ActiveSupport::Deprecation.warn(
21
- "Date#to_s(#{format.inspect}) is deprecated. Please use Date#to_formatted_s(#{format.inspect}) instead."
21
+ "Date#to_s(#{format.inspect}) is deprecated. Please use Date#to_fs(#{format.inspect}) instead."
22
22
  )
23
23
  to_default_s
24
24
  end
@@ -9,21 +9,21 @@ require "active_support/values/time_zone"
9
9
  class DateTime
10
10
  # Convert to a formatted string. See Time::DATE_FORMATS for predefined formats.
11
11
  #
12
- # This method is aliased to <tt>to_fs</tt>.
12
+ # This method is aliased to <tt>to_formatted_s</tt>.
13
13
  #
14
14
  # === Examples
15
15
  # datetime = DateTime.civil(2007, 12, 4, 0, 0, 0, 0) # => Tue, 04 Dec 2007 00:00:00 +0000
16
16
  #
17
- # datetime.to_formatted_s(:db) # => "2007-12-04 00:00:00"
18
- # datetime.to_fs(:db) # => "2007-12-04 00:00:00"
19
- # datetime.to_formatted_s(:number) # => "20071204000000"
20
- # datetime.to_formatted_s(:short) # => "04 Dec 00:00"
21
- # datetime.to_formatted_s(:long) # => "December 04, 2007 00:00"
22
- # datetime.to_formatted_s(:long_ordinal) # => "December 4th, 2007 00:00"
23
- # datetime.to_formatted_s(:rfc822) # => "Tue, 04 Dec 2007 00:00:00 +0000"
24
- # datetime.to_formatted_s(:iso8601) # => "2007-12-04T00:00:00+00:00"
17
+ # datetime.to_fs(:db) # => "2007-12-04 00:00:00"
18
+ # datetime.to_formatted_s(:db) # => "2007-12-04 00:00:00"
19
+ # datetime.to_fs(:number) # => "20071204000000"
20
+ # datetime.to_fs(:short) # => "04 Dec 00:00"
21
+ # datetime.to_fs(:long) # => "December 04, 2007 00:00"
22
+ # datetime.to_fs(:long_ordinal) # => "December 4th, 2007 00:00"
23
+ # datetime.to_fs(:rfc822) # => "Tue, 04 Dec 2007 00:00:00 +0000"
24
+ # datetime.to_fs(:iso8601) # => "2007-12-04T00:00:00+00:00"
25
25
  #
26
- # == Adding your own datetime formats to to_formatted_s
26
+ # == Adding your own datetime formats to to_fs
27
27
  # DateTime formats are shared with Time. You can add your own to the
28
28
  # Time::DATE_FORMATS hash. Use the format name as the hash key and
29
29
  # either a strftime string or Proc instance that takes a time or
@@ -32,14 +32,14 @@ class DateTime
32
32
  # # config/initializers/time_formats.rb
33
33
  # Time::DATE_FORMATS[:month_and_year] = '%B %Y'
34
34
  # Time::DATE_FORMATS[:short_ordinal] = lambda { |time| time.strftime("%B #{time.day.ordinalize}") }
35
- def to_formatted_s(format = :default)
35
+ def to_fs(format = :default)
36
36
  if formatter = ::Time::DATE_FORMATS[format]
37
37
  formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
38
38
  else
39
39
  to_default_s
40
40
  end
41
41
  end
42
- alias_method :to_fs, :to_formatted_s
42
+ alias_method :to_formatted_s, :to_fs
43
43
  alias_method :to_default_s, :to_s if instance_methods(false).include?(:to_s)
44
44
 
45
45
  # Returns a formatted string of the offset from UTC, or an alternative
@@ -54,7 +54,7 @@ class DateTime
54
54
 
55
55
  # Overrides the default inspect method with a human readable one, e.g., "Mon, 21 Feb 2005 14:30:00 +0000".
56
56
  def readable_inspect
57
- to_formatted_s(:rfc822)
57
+ to_fs(:rfc822)
58
58
  end
59
59
  alias_method :default_inspect, :inspect
60
60
  alias_method :inspect, :readable_inspect
@@ -7,14 +7,14 @@ class DateTime
7
7
  def to_s(format = NOT_SET) # :nodoc:
8
8
  if formatter = ::Time::DATE_FORMATS[format]
9
9
  ActiveSupport::Deprecation.warn(
10
- "DateTime#to_s(#{format.inspect}) is deprecated. Please use DateTime#to_formatted_s(#{format.inspect}) instead."
10
+ "DateTime#to_s(#{format.inspect}) is deprecated. Please use DateTime#to_fs(#{format.inspect}) instead."
11
11
  )
12
12
  formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
13
13
  elsif format == NOT_SET
14
14
  to_default_s
15
15
  else
16
16
  ActiveSupport::Deprecation.warn(
17
- "DateTime#to_s(#{format.inspect}) is deprecated. Please use DateTime#to_formatted_s(#{format.inspect}) instead."
17
+ "DateTime#to_s(#{format.inspect}) is deprecated. Please use DateTime#to_fs(#{format.inspect}) instead."
18
18
  )
19
19
  to_default_s
20
20
  end
@@ -22,16 +22,16 @@ module Enumerable
22
22
 
23
23
  # Calculates the minimum from the extracted elements.
24
24
  #
25
- # payments = [Payment.new(5), Payment.new(15), Payment.new(10)]
26
- # payments.minimum(:price) # => 5
25
+ # payments = [Payment.new(5), Payment.new(15), Payment.new(10)]
26
+ # payments.minimum(:price) # => 5
27
27
  def minimum(key)
28
28
  map(&key).min
29
29
  end
30
30
 
31
31
  # Calculates the maximum from the extracted elements.
32
32
  #
33
- # payments = [Payment.new(5), Payment.new(15), Payment.new(10)]
34
- # payments.maximum(:price) # => 15
33
+ # payments = [Payment.new(5), Payment.new(15), Payment.new(10)]
34
+ # payments.maximum(:price) # => 15
35
35
  def maximum(key)
36
36
  map(&key).max
37
37
  end
@@ -47,13 +47,13 @@ module Enumerable
47
47
  #
48
48
  # It can also calculate the sum without the use of a block.
49
49
  #
50
- # [5, 15, 10].sum # => 30
51
- # ['foo', 'bar'].sum('') # => "foobar"
52
- # [[1, 2], [3, 1, 5]].sum([]) # => [1, 2, 3, 1, 5]
50
+ # [5, 15, 10].sum # => 30
51
+ # ['foo', 'bar'].sum('') # => "foobar"
52
+ # [[1, 2], [3, 1, 5]].sum([]) # => [1, 2, 3, 1, 5]
53
53
  #
54
54
  # The default sum of an empty list is zero. You can override this default:
55
55
  #
56
- # [].sum(Payment.new(0)) { |i| i.amount } # => Payment.new(0)
56
+ # [].sum(Payment.new(0)) { |i| i.amount } # => Payment.new(0)
57
57
  def sum(identity = nil, &block)
58
58
  if identity
59
59
  _original_sum_with_required_identity(identity, &block)
@@ -205,16 +205,16 @@ module Enumerable
205
205
  # Returns a new +Array+ without the blank items.
206
206
  # Uses Object#blank? for determining if an item is blank.
207
207
  #
208
- # [1, "", nil, 2, " ", [], {}, false, true].compact_blank
209
- # # => [1, 2, true]
208
+ # [1, "", nil, 2, " ", [], {}, false, true].compact_blank
209
+ # # => [1, 2, true]
210
210
  #
211
- # Set.new([nil, "", 1, 2])
212
- # # => [2, 1] (or [1, 2])
211
+ # Set.new([nil, "", 1, 2])
212
+ # # => [2, 1] (or [1, 2])
213
213
  #
214
214
  # When called on a +Hash+, returns a new +Hash+ without the blank values.
215
215
  #
216
- # { a: "", b: 1, c: nil, d: [], e: false, f: true }.compact_blank
217
- # #=> { b: 1, f: true }
216
+ # { a: "", b: 1, c: nil, d: [], e: false, f: true }.compact_blank
217
+ # # => { b: 1, f: true }
218
218
  def compact_blank
219
219
  reject(&:blank?)
220
220
  end
@@ -223,7 +223,7 @@ module Enumerable
223
223
  # objects in the original enumerable.
224
224
  #
225
225
  # [ Person.find(5), Person.find(3), Person.find(1) ].in_order_of(:id, [ 1, 5, 3 ])
226
- # => [ Person.find(1), Person.find(5), Person.find(3) ]
226
+ # # => [ Person.find(1), Person.find(5), Person.find(3) ]
227
227
  #
228
228
  # If the +series+ include keys that have no corresponding element in the Enumerable, these are ignored.
229
229
  # If the Enumerable has additional elements that aren't named in the +series+, these are not included in the result.
@@ -234,9 +234,9 @@ module Enumerable
234
234
  # Returns the sole item in the enumerable. If there are no items, or more
235
235
  # than one item, raises +Enumerable::SoleItemExpectedError+.
236
236
  #
237
- # ["x"].sole # => "x"
238
- # Set.new.sole # => Enumerable::SoleItemExpectedError: no item found
239
- # { a: 1, b: 2 }.sole # => Enumerable::SoleItemExpectedError: multiple items found
237
+ # ["x"].sole # => "x"
238
+ # Set.new.sole # => Enumerable::SoleItemExpectedError: no item found
239
+ # { a: 1, b: 2 }.sole # => Enumerable::SoleItemExpectedError: multiple items found
240
240
  def sole
241
241
  case count
242
242
  when 1 then return first # rubocop:disable Style/RedundantReturn
@@ -255,9 +255,9 @@ class Hash
255
255
  # Removes all blank values from the +Hash+ in place and returns self.
256
256
  # Uses Object#blank? for determining if a value is blank.
257
257
  #
258
- # h = { a: "", b: 1, c: nil, d: [], e: false, f: true }
259
- # h.compact_blank!
260
- # # => { b: 1, f: true }
258
+ # h = { a: "", b: 1, c: nil, d: [], e: false, f: true }
259
+ # h.compact_blank!
260
+ # # => { b: 1, f: true }
261
261
  def compact_blank!
262
262
  # use delete_if rather than reject! because it always returns self even if nothing changed
263
263
  delete_if { |_k, v| v.blank? }
@@ -302,9 +302,9 @@ class Array # :nodoc:
302
302
  # Removes all blank elements from the +Array+ in place and returns self.
303
303
  # Uses Object#blank? for determining if an item is blank.
304
304
  #
305
- # a = [1, "", nil, 2, " ", [], {}, false, true]
306
- # a.compact_blank!
307
- # # => [1, 2, true]
305
+ # a = [1, "", nil, 2, " ", [], {}, false, true]
306
+ # a.compact_blank!
307
+ # # => [1, 2, true]
308
308
  def compact_blank!
309
309
  # use delete_if rather than reject! because it always returns self even if nothing changed
310
310
  delete_if(&:blank?)
@@ -64,6 +64,8 @@ class File
64
64
  file_name = join(dir, basename)
65
65
  FileUtils.touch(file_name)
66
66
  stat(file_name)
67
+ rescue Errno::ENOENT
68
+ file_name = nil
67
69
  ensure
68
70
  FileUtils.rm_f(file_name) if file_name
69
71
  end
@@ -9,7 +9,7 @@ module ActiveSupport
9
9
  # Options are provided for phone numbers, currency, percentage,
10
10
  # precision, positional notation, file size and pretty printing.
11
11
  #
12
- # This method is aliased to <tt>to_fs</tt>.
12
+ # This method is aliased to <tt>to_formatted_s</tt>.
13
13
  #
14
14
  # ==== Options
15
15
  #
@@ -18,97 +18,97 @@ module ActiveSupport
18
18
  # ==== Examples
19
19
  #
20
20
  # Phone Numbers:
21
- # 5551234.to_formatted_s(:phone) # => "555-1234"
22
- # 1235551234.to_formatted_s(:phone) # => "123-555-1234"
23
- # 1235551234.to_formatted_s(:phone, area_code: true) # => "(123) 555-1234"
24
- # 1235551234.to_formatted_s(:phone, delimiter: ' ') # => "123 555 1234"
25
- # 1235551234.to_formatted_s(:phone, area_code: true, extension: 555) # => "(123) 555-1234 x 555"
26
- # 1235551234.to_formatted_s(:phone, country_code: 1) # => "+1-123-555-1234"
27
- # 1235551234.to_formatted_s(:phone, country_code: 1, extension: 1343, delimiter: '.')
21
+ # 5551234.to_fs(:phone) # => "555-1234"
22
+ # 1235551234.to_fs(:phone) # => "123-555-1234"
23
+ # 1235551234.to_fs(:phone, area_code: true) # => "(123) 555-1234"
24
+ # 1235551234.to_fs(:phone, delimiter: ' ') # => "123 555 1234"
25
+ # 1235551234.to_fs(:phone, area_code: true, extension: 555) # => "(123) 555-1234 x 555"
26
+ # 1235551234.to_fs(:phone, country_code: 1) # => "+1-123-555-1234"
27
+ # 1235551234.to_fs(:phone, country_code: 1, extension: 1343, delimiter: '.')
28
28
  # # => "+1.123.555.1234 x 1343"
29
29
  #
30
30
  # Currency:
31
- # 1234567890.50.to_formatted_s(:currency) # => "$1,234,567,890.50"
32
- # 1234567890.506.to_formatted_s(:currency) # => "$1,234,567,890.51"
33
- # 1234567890.506.to_formatted_s(:currency, precision: 3) # => "$1,234,567,890.506"
34
- # 1234567890.506.to_formatted_s(:currency, round_mode: :down) # => "$1,234,567,890.50"
35
- # 1234567890.506.to_formatted_s(:currency, locale: :fr) # => "1 234 567 890,51 €"
36
- # -1234567890.50.to_formatted_s(:currency, negative_format: '(%u%n)')
31
+ # 1234567890.50.to_fs(:currency) # => "$1,234,567,890.50"
32
+ # 1234567890.506.to_fs(:currency) # => "$1,234,567,890.51"
33
+ # 1234567890.506.to_fs(:currency, precision: 3) # => "$1,234,567,890.506"
34
+ # 1234567890.506.to_fs(:currency, round_mode: :down) # => "$1,234,567,890.50"
35
+ # 1234567890.506.to_fs(:currency, locale: :fr) # => "1 234 567 890,51 €"
36
+ # -1234567890.50.to_fs(:currency, negative_format: '(%u%n)')
37
37
  # # => "($1,234,567,890.50)"
38
- # 1234567890.50.to_formatted_s(:currency, unit: '&pound;', separator: ',', delimiter: '')
38
+ # 1234567890.50.to_fs(:currency, unit: '&pound;', separator: ',', delimiter: '')
39
39
  # # => "&pound;1234567890,50"
40
- # 1234567890.50.to_formatted_s(:currency, unit: '&pound;', separator: ',', delimiter: '', format: '%n %u')
40
+ # 1234567890.50.to_fs(:currency, unit: '&pound;', separator: ',', delimiter: '', format: '%n %u')
41
41
  # # => "1234567890,50 &pound;"
42
42
  #
43
43
  # Percentage:
44
- # 100.to_formatted_s(:percentage) # => "100.000%"
45
- # 100.to_formatted_s(:percentage, precision: 0) # => "100%"
46
- # 1000.to_formatted_s(:percentage, delimiter: '.', separator: ',') # => "1.000,000%"
47
- # 302.24398923423.to_formatted_s(:percentage, precision: 5) # => "302.24399%"
48
- # 302.24398923423.to_formatted_s(:percentage, round_mode: :down) # => "302.243%"
49
- # 1000.to_formatted_s(:percentage, locale: :fr) # => "1 000,000%"
50
- # 100.to_formatted_s(:percentage, format: '%n %') # => "100.000 %"
44
+ # 100.to_fs(:percentage) # => "100.000%"
45
+ # 100.to_fs(:percentage, precision: 0) # => "100%"
46
+ # 1000.to_fs(:percentage, delimiter: '.', separator: ',') # => "1.000,000%"
47
+ # 302.24398923423.to_fs(:percentage, precision: 5) # => "302.24399%"
48
+ # 302.24398923423.to_fs(:percentage, round_mode: :down) # => "302.243%"
49
+ # 1000.to_fs(:percentage, locale: :fr) # => "1 000,000%"
50
+ # 100.to_fs(:percentage, format: '%n %') # => "100.000 %"
51
51
  #
52
52
  # Delimited:
53
- # 12345678.to_formatted_s(:delimited) # => "12,345,678"
54
- # 12345678.05.to_formatted_s(:delimited) # => "12,345,678.05"
55
- # 12345678.to_formatted_s(:delimited, delimiter: '.') # => "12.345.678"
56
- # 12345678.to_formatted_s(:delimited, delimiter: ',') # => "12,345,678"
57
- # 12345678.05.to_formatted_s(:delimited, separator: ' ') # => "12,345,678 05"
58
- # 12345678.05.to_formatted_s(:delimited, locale: :fr) # => "12 345 678,05"
59
- # 98765432.98.to_formatted_s(:delimited, delimiter: ' ', separator: ',')
53
+ # 12345678.to_fs(:delimited) # => "12,345,678"
54
+ # 12345678.05.to_fs(:delimited) # => "12,345,678.05"
55
+ # 12345678.to_fs(:delimited, delimiter: '.') # => "12.345.678"
56
+ # 12345678.to_fs(:delimited, delimiter: ',') # => "12,345,678"
57
+ # 12345678.05.to_fs(:delimited, separator: ' ') # => "12,345,678 05"
58
+ # 12345678.05.to_fs(:delimited, locale: :fr) # => "12 345 678,05"
59
+ # 98765432.98.to_fs(:delimited, delimiter: ' ', separator: ',')
60
60
  # # => "98 765 432,98"
61
61
  #
62
62
  # Rounded:
63
- # 111.2345.to_formatted_s(:rounded) # => "111.235"
64
- # 111.2345.to_formatted_s(:rounded, precision: 2) # => "111.23"
65
- # 111.2345.to_formatted_s(:rounded, precision: 2, round_mode: :up) # => "111.24"
66
- # 13.to_formatted_s(:rounded, precision: 5) # => "13.00000"
67
- # 389.32314.to_formatted_s(:rounded, precision: 0) # => "389"
68
- # 111.2345.to_formatted_s(:rounded, significant: true) # => "111"
69
- # 111.2345.to_formatted_s(:rounded, precision: 1, significant: true) # => "100"
70
- # 13.to_formatted_s(:rounded, precision: 5, significant: true) # => "13.000"
71
- # 111.234.to_formatted_s(:rounded, locale: :fr) # => "111,234"
72
- # 13.to_formatted_s(:rounded, precision: 5, significant: true, strip_insignificant_zeros: true)
63
+ # 111.2345.to_fs(:rounded) # => "111.235"
64
+ # 111.2345.to_fs(:rounded, precision: 2) # => "111.23"
65
+ # 111.2345.to_fs(:rounded, precision: 2, round_mode: :up) # => "111.24"
66
+ # 13.to_fs(:rounded, precision: 5) # => "13.00000"
67
+ # 389.32314.to_fs(:rounded, precision: 0) # => "389"
68
+ # 111.2345.to_fs(:rounded, significant: true) # => "111"
69
+ # 111.2345.to_fs(:rounded, precision: 1, significant: true) # => "100"
70
+ # 13.to_fs(:rounded, precision: 5, significant: true) # => "13.000"
71
+ # 111.234.to_fs(:rounded, locale: :fr) # => "111,234"
72
+ # 13.to_fs(:rounded, precision: 5, significant: true, strip_insignificant_zeros: true)
73
73
  # # => "13"
74
- # 389.32314.to_formatted_s(:rounded, precision: 4, significant: true) # => "389.3"
75
- # 1111.2345.to_formatted_s(:rounded, precision: 2, separator: ',', delimiter: '.')
74
+ # 389.32314.to_fs(:rounded, precision: 4, significant: true) # => "389.3"
75
+ # 1111.2345.to_fs(:rounded, precision: 2, separator: ',', delimiter: '.')
76
76
  # # => "1.111,23"
77
77
  #
78
78
  # Human-friendly size in Bytes:
79
- # 123.to_formatted_s(:human_size) # => "123 Bytes"
80
- # 1234.to_formatted_s(:human_size) # => "1.21 KB"
81
- # 12345.to_formatted_s(:human_size) # => "12.1 KB"
82
- # 1234567.to_formatted_s(:human_size) # => "1.18 MB"
83
- # 1234567890.to_formatted_s(:human_size) # => "1.15 GB"
84
- # 1234567890123.to_formatted_s(:human_size) # => "1.12 TB"
85
- # 1234567890123456.to_formatted_s(:human_size) # => "1.1 PB"
86
- # 1234567890123456789.to_formatted_s(:human_size) # => "1.07 EB"
87
- # 1234567.to_formatted_s(:human_size, precision: 2) # => "1.2 MB"
88
- # 1234567.to_formatted_s(:human_size, precision: 2, round_mode: :up) # => "1.3 MB"
89
- # 483989.to_formatted_s(:human_size, precision: 2) # => "470 KB"
90
- # 1234567.to_formatted_s(:human_size, precision: 2, separator: ',') # => "1,2 MB"
91
- # 1234567890123.to_formatted_s(:human_size, precision: 5) # => "1.1228 TB"
92
- # 524288000.to_formatted_s(:human_size, precision: 5) # => "500 MB"
79
+ # 123.to_fs(:human_size) # => "123 Bytes"
80
+ # 1234.to_fs(:human_size) # => "1.21 KB"
81
+ # 12345.to_fs(:human_size) # => "12.1 KB"
82
+ # 1234567.to_fs(:human_size) # => "1.18 MB"
83
+ # 1234567890.to_fs(:human_size) # => "1.15 GB"
84
+ # 1234567890123.to_fs(:human_size) # => "1.12 TB"
85
+ # 1234567890123456.to_fs(:human_size) # => "1.1 PB"
86
+ # 1234567890123456789.to_fs(:human_size) # => "1.07 EB"
87
+ # 1234567.to_fs(:human_size, precision: 2) # => "1.2 MB"
88
+ # 1234567.to_fs(:human_size, precision: 2, round_mode: :up) # => "1.3 MB"
89
+ # 483989.to_fs(:human_size, precision: 2) # => "470 KB"
90
+ # 1234567.to_fs(:human_size, precision: 2, separator: ',') # => "1,2 MB"
91
+ # 1234567890123.to_fs(:human_size, precision: 5) # => "1.1228 TB"
92
+ # 524288000.to_fs(:human_size, precision: 5) # => "500 MB"
93
93
  #
94
94
  # Human-friendly format:
95
- # 123.to_formatted_s(:human) # => "123"
96
- # 1234.to_formatted_s(:human) # => "1.23 Thousand"
97
- # 12345.to_formatted_s(:human) # => "12.3 Thousand"
98
- # 1234567.to_formatted_s(:human) # => "1.23 Million"
99
- # 1234567890.to_formatted_s(:human) # => "1.23 Billion"
100
- # 1234567890123.to_formatted_s(:human) # => "1.23 Trillion"
101
- # 1234567890123456.to_formatted_s(:human) # => "1.23 Quadrillion"
102
- # 1234567890123456789.to_formatted_s(:human) # => "1230 Quadrillion"
103
- # 489939.to_formatted_s(:human, precision: 2) # => "490 Thousand"
104
- # 489939.to_formatted_s(:human, precision: 2, round_mode: :down) # => "480 Thousand"
105
- # 489939.to_formatted_s(:human, precision: 4) # => "489.9 Thousand"
106
- # 1234567.to_formatted_s(:human, precision: 4,
95
+ # 123.to_fs(:human) # => "123"
96
+ # 1234.to_fs(:human) # => "1.23 Thousand"
97
+ # 12345.to_fs(:human) # => "12.3 Thousand"
98
+ # 1234567.to_fs(:human) # => "1.23 Million"
99
+ # 1234567890.to_fs(:human) # => "1.23 Billion"
100
+ # 1234567890123.to_fs(:human) # => "1.23 Trillion"
101
+ # 1234567890123456.to_fs(:human) # => "1.23 Quadrillion"
102
+ # 1234567890123456789.to_fs(:human) # => "1230 Quadrillion"
103
+ # 489939.to_fs(:human, precision: 2) # => "490 Thousand"
104
+ # 489939.to_fs(:human, precision: 2, round_mode: :down) # => "480 Thousand"
105
+ # 489939.to_fs(:human, precision: 4) # => "489.9 Thousand"
106
+ # 1234567.to_fs(:human, precision: 4,
107
107
  # significant: false) # => "1.2346 Million"
108
- # 1234567.to_formatted_s(:human, precision: 1,
108
+ # 1234567.to_fs(:human, precision: 1,
109
109
  # separator: ',',
110
110
  # significant: false) # => "1,2 Million"
111
- def to_formatted_s(format = nil, options = nil)
111
+ def to_fs(format = nil, options = nil)
112
112
  return to_s if format.nil?
113
113
 
114
114
  case format
@@ -134,7 +134,7 @@ module ActiveSupport
134
134
  to_s(format)
135
135
  end
136
136
  end
137
- alias_method :to_fs, :to_formatted_s
137
+ alias_method :to_formatted_s, :to_fs
138
138
  end
139
139
  end
140
140
 
@@ -10,42 +10,42 @@ module ActiveSupport
10
10
  super(format)
11
11
  when :phone
12
12
  ActiveSupport::Deprecation.warn(
13
- "#{self.class}#to_s(#{format.inspect}) is deprecated. Please use #{self.class}#to_formatted_s(#{format.inspect}) instead."
13
+ "#{self.class}#to_s(#{format.inspect}) is deprecated. Please use #{self.class}#to_fs(#{format.inspect}) instead."
14
14
  )
15
15
  ActiveSupport::NumberHelper.number_to_phone(self, options || {})
16
16
  when :currency
17
17
  ActiveSupport::Deprecation.warn(
18
- "#{self.class}#to_s(#{format.inspect}) is deprecated. Please use #{self.class}#to_formatted_s(#{format.inspect}) instead."
18
+ "#{self.class}#to_s(#{format.inspect}) is deprecated. Please use #{self.class}#to_fs(#{format.inspect}) instead."
19
19
  )
20
20
  ActiveSupport::NumberHelper.number_to_currency(self, options || {})
21
21
  when :percentage
22
22
  ActiveSupport::Deprecation.warn(
23
- "#{self.class}#to_s(#{format.inspect}) is deprecated. Please use #{self.class}#to_formatted_s(#{format.inspect}) instead."
23
+ "#{self.class}#to_s(#{format.inspect}) is deprecated. Please use #{self.class}#to_fs(#{format.inspect}) instead."
24
24
  )
25
25
  ActiveSupport::NumberHelper.number_to_percentage(self, options || {})
26
26
  when :delimited
27
27
  ActiveSupport::Deprecation.warn(
28
- "#{self.class}#to_s(#{format.inspect}) is deprecated. Please use #{self.class}#to_formatted_s(#{format.inspect}) instead."
28
+ "#{self.class}#to_s(#{format.inspect}) is deprecated. Please use #{self.class}#to_fs(#{format.inspect}) instead."
29
29
  )
30
30
  ActiveSupport::NumberHelper.number_to_delimited(self, options || {})
31
31
  when :rounded
32
32
  ActiveSupport::Deprecation.warn(
33
- "#{self.class}#to_s(#{format.inspect}) is deprecated. Please use #{self.class}#to_formatted_s(#{format.inspect}) instead."
33
+ "#{self.class}#to_s(#{format.inspect}) is deprecated. Please use #{self.class}#to_fs(#{format.inspect}) instead."
34
34
  )
35
35
  ActiveSupport::NumberHelper.number_to_rounded(self, options || {})
36
36
  when :human
37
37
  ActiveSupport::Deprecation.warn(
38
- "#{self.class}#to_s(#{format.inspect}) is deprecated. Please use #{self.class}#to_formatted_s(#{format.inspect}) instead."
38
+ "#{self.class}#to_s(#{format.inspect}) is deprecated. Please use #{self.class}#to_fs(#{format.inspect}) instead."
39
39
  )
40
40
  ActiveSupport::NumberHelper.number_to_human(self, options || {})
41
41
  when :human_size
42
42
  ActiveSupport::Deprecation.warn(
43
- "#{self.class}#to_s(#{format.inspect}) is deprecated. Please use #{self.class}#to_formatted_s(#{format.inspect}) instead."
43
+ "#{self.class}#to_s(#{format.inspect}) is deprecated. Please use #{self.class}#to_fs(#{format.inspect}) instead."
44
44
  )
45
45
  ActiveSupport::NumberHelper.number_to_human_size(self, options || {})
46
46
  when Symbol
47
47
  ActiveSupport::Deprecation.warn(
48
- "#{self.class}#to_s(#{format.inspect}) is deprecated. Please use #{self.class}#to_formatted_s(#{format.inspect}) instead."
48
+ "#{self.class}#to_s(#{format.inspect}) is deprecated. Please use #{self.class}#to_fs(#{format.inspect}) instead."
49
49
  )
50
50
  super()
51
51
  else
@@ -1,11 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Object
4
- # A duck-type assistant method. For example, Active Support extends Date
5
- # to define an <tt>acts_like_date?</tt> method, and extends Time to define
6
- # <tt>acts_like_time?</tt>. As a result, we can do <tt>x.acts_like?(:time)</tt> and
7
- # <tt>x.acts_like?(:date)</tt> to do duck-type-safe comparisons, since classes that
8
- # we want to act like Time simply need to define an <tt>acts_like_time?</tt> method.
4
+ # Provides a way to check whether some class acts like some other class based on the existence of
5
+ # an appropriately-named marker method.
6
+ #
7
+ # A class that provides the same interface as <tt>SomeClass</tt> may define a marker method named
8
+ # <tt>acts_like_some_class?</tt> to signal its compatibility to callers of
9
+ # <tt>acts_like?(:some_class)</tt>.
10
+ #
11
+ # For example, Active Support extends <tt>Date</tt> to define an <tt>acts_like_date?</tt> method,
12
+ # and extends <tt>Time</tt> to define <tt>acts_like_time?</tt>. As a result, developers can call
13
+ # <tt>x.acts_like?(:time)</tt> and <tt>x.acts_like?(:date)</tt> to test duck-type compatibility,
14
+ # and classes that are able to act like <tt>Time</tt> can also define an <tt>acts_like_time?</tt>
15
+ # method to interoperate.
16
+ #
17
+ # Note that the marker method is only expected to exist. It isn't called, so its body or return
18
+ # value are irrelevant.
19
+ #
20
+ # ==== Example: A class that provides the same interface as <tt>String</tt>
21
+ #
22
+ # This class may define:
23
+ #
24
+ # class Stringish
25
+ # def acts_like_string?
26
+ # end
27
+ # end
28
+ #
29
+ # Then client code can query for duck-type-safeness this way:
30
+ #
31
+ # Stringish.new.acts_like?(:string) # => true
32
+ #
9
33
  def acts_like?(duck)
10
34
  case duck
11
35
  when :time
@@ -7,34 +7,34 @@ module ActiveSupport
7
7
  case start
8
8
  when String then "BETWEEN '#{start}' AND '#{stop}'"
9
9
  else
10
- "BETWEEN '#{start.to_formatted_s(:db)}' AND '#{stop.to_formatted_s(:db)}'"
10
+ "BETWEEN '#{start.to_fs(:db)}' AND '#{stop.to_fs(:db)}'"
11
11
  end
12
12
  end
13
13
  }
14
14
 
15
15
  # Convert range to a formatted string. See RANGE_FORMATS for predefined formats.
16
16
  #
17
- # This method is aliased to <tt>to_fs</tt>.
17
+ # This method is aliased to <tt>to_formatted_s</tt>.
18
18
  #
19
19
  # range = (1..100) # => 1..100
20
20
  #
21
21
  # range.to_s # => "1..100"
22
- # range.to_formatted_s(:db) # => "BETWEEN '1' AND '100'"
22
+ # range.to_fs(:db) # => "BETWEEN '1' AND '100'"
23
23
  #
24
24
  # == Adding your own range formats to to_s
25
25
  # You can add your own formats to the Range::RANGE_FORMATS hash.
26
26
  # Use the format name as the hash key and a Proc instance.
27
27
  #
28
28
  # # config/initializers/range_formats.rb
29
- # Range::RANGE_FORMATS[:short] = ->(start, stop) { "Between #{start.to_formatted_s(:db)} and #{stop.to_formatted_s(:db)}" }
30
- def to_formatted_s(format = :default)
29
+ # Range::RANGE_FORMATS[:short] = ->(start, stop) { "Between #{start.to_fs(:db)} and #{stop.to_fs(:db)}" }
30
+ def to_fs(format = :default)
31
31
  if formatter = RANGE_FORMATS[format]
32
32
  formatter.call(first, last)
33
33
  else
34
34
  to_s
35
35
  end
36
36
  end
37
- alias_method :to_fs, :to_formatted_s
37
+ alias_method :to_formatted_s, :to_fs
38
38
  end
39
39
  end
40
40
 
@@ -6,14 +6,14 @@ module ActiveSupport
6
6
  def to_s(format = NOT_SET)
7
7
  if formatter = RangeWithFormat::RANGE_FORMATS[format]
8
8
  ActiveSupport::Deprecation.warn(
9
- "Range#to_s(#{format.inspect}) is deprecated. Please use Range#to_formatted_s(#{format.inspect}) instead."
9
+ "Range#to_s(#{format.inspect}) is deprecated. Please use Range#to_fs(#{format.inspect}) instead."
10
10
  )
11
11
  formatter.call(first, last)
12
12
  elsif format == NOT_SET
13
13
  super()
14
14
  else
15
15
  ActiveSupport::Deprecation.warn(
16
- "Range#to_s(#{format.inspect}) is deprecated. Please use Range#to_formatted_s(#{format.inspect}) instead."
16
+ "Range#to_s(#{format.inspect}) is deprecated. Please use Range#to_fs(#{format.inspect}) instead."
17
17
  )
18
18
  super()
19
19
  end
@@ -27,22 +27,22 @@ class Time
27
27
 
28
28
  # Converts to a formatted string. See DATE_FORMATS for built-in formats.
29
29
  #
30
- # This method is aliased to <tt>to_fs</tt>.
30
+ # This method is aliased to <tt>to_formatted_s</tt>.
31
31
  #
32
32
  # time = Time.now # => 2007-01-18 06:10:17 -06:00
33
33
  #
34
- # time.to_formatted_s(:time) # => "06:10"
35
34
  # time.to_fs(:time) # => "06:10"
35
+ # time.to_formatted_s(:time) # => "06:10"
36
36
  #
37
- # time.to_formatted_s(:db) # => "2007-01-18 06:10:17"
38
- # time.to_formatted_s(:number) # => "20070118061017"
39
- # time.to_formatted_s(:short) # => "18 Jan 06:10"
40
- # time.to_formatted_s(:long) # => "January 18, 2007 06:10"
41
- # time.to_formatted_s(:long_ordinal) # => "January 18th, 2007 06:10"
42
- # time.to_formatted_s(:rfc822) # => "Thu, 18 Jan 2007 06:10:17 -0600"
43
- # time.to_formatted_s(:iso8601) # => "2007-01-18T06:10:17-06:00"
37
+ # time.to_fs(:db) # => "2007-01-18 06:10:17"
38
+ # time.to_fs(:number) # => "20070118061017"
39
+ # time.to_fs(:short) # => "18 Jan 06:10"
40
+ # time.to_fs(:long) # => "January 18, 2007 06:10"
41
+ # time.to_fs(:long_ordinal) # => "January 18th, 2007 06:10"
42
+ # time.to_fs(:rfc822) # => "Thu, 18 Jan 2007 06:10:17 -0600"
43
+ # time.to_fs(:iso8601) # => "2007-01-18T06:10:17-06:00"
44
44
  #
45
- # == Adding your own time formats to +to_formatted_s+
45
+ # == Adding your own time formats to +to_fs+
46
46
  # You can add your own formats to the Time::DATE_FORMATS hash.
47
47
  # Use the format name as the hash key and either a strftime string
48
48
  # or Proc instance that takes a time argument as the value.
@@ -50,7 +50,7 @@ class Time
50
50
  # # config/initializers/time_formats.rb
51
51
  # Time::DATE_FORMATS[:month_and_year] = '%B %Y'
52
52
  # Time::DATE_FORMATS[:short_ordinal] = ->(time) { time.strftime("%B #{time.day.ordinalize}") }
53
- def to_formatted_s(format = :default)
53
+ def to_fs(format = :default)
54
54
  if formatter = DATE_FORMATS[format]
55
55
  formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
56
56
  else
@@ -58,7 +58,7 @@ class Time
58
58
  to_default_s
59
59
  end
60
60
  end
61
- alias_method :to_fs, :to_formatted_s
61
+ alias_method :to_formatted_s, :to_fs
62
62
  alias_method :to_default_s, :to_s
63
63
 
64
64
  # Returns a formatted string of the offset from UTC, or an alternative
@@ -7,14 +7,14 @@ class Time
7
7
  def to_s(format = NOT_SET) # :nodoc:
8
8
  if formatter = DATE_FORMATS[format]
9
9
  ActiveSupport::Deprecation.warn(
10
- "Time#to_s(#{format.inspect}) is deprecated. Please use Time#to_formatted_s(#{format.inspect}) instead."
10
+ "Time#to_s(#{format.inspect}) is deprecated. Please use Time#to_fs(#{format.inspect}) instead."
11
11
  )
12
12
  formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
13
13
  elsif format == NOT_SET
14
14
  to_default_s
15
15
  else
16
16
  ActiveSupport::Deprecation.warn(
17
- "Time#to_s(#{format.inspect}) is deprecated. Please use Time#to_formatted_s(#{format.inspect}) instead."
17
+ "Time#to_s(#{format.inspect}) is deprecated. Please use Time#to_fs(#{format.inspect}) instead."
18
18
  )
19
19
  to_default_s
20
20
  end
@@ -51,7 +51,6 @@ module ActiveSupport
51
51
  unless @clear_disabled
52
52
  @clear_disabled = true
53
53
  remove_method(:subclasses)
54
- remove_method(:descendants)
55
54
  @@excluded_descendants = nil
56
55
  end
57
56
  end
@@ -87,9 +86,7 @@ module ActiveSupport
87
86
  end
88
87
 
89
88
  def descendants
90
- descendants = super
91
- descendants.reject! { |d| @@excluded_descendants[d] }
92
- descendants
89
+ subclasses.concat(subclasses.flat_map(&:descendants))
93
90
  end
94
91
 
95
92
  def direct_descendants
@@ -49,7 +49,8 @@ module ActiveSupport
49
49
  end
50
50
 
51
51
  def deserialize(config)
52
- YAML.load(config).presence || {}
52
+ doc = YAML.respond_to?(:unsafe_load) ? YAML.unsafe_load(config) : YAML.load(config)
53
+ doc.presence || {}
53
54
  end
54
55
  end
55
56
  end
@@ -64,18 +64,21 @@ module ActiveSupport
64
64
  # after the work has been performed.
65
65
  #
66
66
  # Where possible, prefer +wrap+.
67
- def self.run!
68
- if active?
69
- Null
67
+ def self.run!(reset: false)
68
+ if reset
69
+ lost_instance = IsolatedExecutionState.delete(active_key)
70
+ lost_instance&.complete!
70
71
  else
71
- new.tap do |instance|
72
- success = nil
73
- begin
74
- instance.run!
75
- success = true
76
- ensure
77
- instance.complete! unless success
78
- end
72
+ return Null if active?
73
+ end
74
+
75
+ new.tap do |instance|
76
+ success = nil
77
+ begin
78
+ instance.run!
79
+ success = true
80
+ ensure
81
+ instance.complete! unless success
79
82
  end
80
83
  end
81
84
  end
@@ -105,27 +108,20 @@ module ActiveSupport
105
108
  end
106
109
  end
107
110
 
108
- class << self # :nodoc:
109
- attr_accessor :active
110
- end
111
-
112
111
  def self.error_reporter
113
112
  @error_reporter ||= ActiveSupport::ErrorReporter.new
114
113
  end
115
114
 
116
- def self.inherited(other) # :nodoc:
117
- super
118
- other.active = Concurrent::Hash.new
115
+ def self.active_key # :nodoc:
116
+ @active_key ||= :"active_execution_wrapper_#{object_id}"
119
117
  end
120
118
 
121
- self.active = Concurrent::Hash.new
122
-
123
119
  def self.active? # :nodoc:
124
- @active[IsolatedExecutionState.unique_id]
120
+ IsolatedExecutionState.key?(active_key)
125
121
  end
126
122
 
127
123
  def run! # :nodoc:
128
- self.class.active[IsolatedExecutionState.unique_id] = true
124
+ IsolatedExecutionState[self.class.active_key] = self
129
125
  run
130
126
  end
131
127
 
@@ -140,7 +136,7 @@ module ActiveSupport
140
136
  def complete!
141
137
  complete
142
138
  ensure
143
- self.class.active.delete(IsolatedExecutionState.unique_id)
139
+ IsolatedExecutionState.delete(self.class.active_key)
144
140
  end
145
141
 
146
142
  def complete # :nodoc:
@@ -9,8 +9,8 @@ module ActiveSupport
9
9
  module VERSION
10
10
  MAJOR = 7
11
11
  MINOR = 0
12
- TINY = 0
13
- PRE = nil
12
+ TINY = 2
13
+ PRE = "2"
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
16
16
  end
@@ -37,6 +37,14 @@ module ActiveSupport
37
37
  current[key] = value
38
38
  end
39
39
 
40
+ def key?(key)
41
+ current.key?(key)
42
+ end
43
+
44
+ def delete(key)
45
+ current.delete(key)
46
+ end
47
+
40
48
  def clear
41
49
  current.clear
42
50
  end
@@ -58,7 +58,7 @@ module ActiveSupport
58
58
  prepare!
59
59
  end
60
60
 
61
- def self.run! # :nodoc:
61
+ def self.run!(reset: false) # :nodoc:
62
62
  if check!
63
63
  super
64
64
  else
@@ -33,7 +33,7 @@ module ActiveSupport
33
33
  # t.dst? # => true
34
34
  # t.utc_offset # => -14400
35
35
  # t.zone # => "EDT"
36
- # t.to_formatted_s(:rfc822) # => "Sun, 18 May 2008 13:27:25 -0400"
36
+ # t.to_fs(:rfc822) # => "Sun, 18 May 2008 13:27:25 -0400"
37
37
  # t + 1.day # => Mon, 19 May 2008 13:27:25.031505668 EDT -04:00
38
38
  # t.beginning_of_year # => Tue, 01 Jan 2008 00:00:00.000000000 EST -05:00
39
39
  # t > Time.utc(1999) # => true
@@ -202,7 +202,7 @@ module ActiveSupport
202
202
  #
203
203
  # Time.zone.now.rfc2822 # => "Tue, 01 Jan 2013 04:51:39 +0000"
204
204
  def rfc2822
205
- to_formatted_s(:rfc822)
205
+ to_fs(:rfc822)
206
206
  end
207
207
  alias_method :rfc822, :rfc2822
208
208
 
@@ -212,19 +212,19 @@ module ActiveSupport
212
212
  def to_s(format = NOT_SET)
213
213
  if format == :db
214
214
  ActiveSupport::Deprecation.warn(
215
- "TimeWithZone#to_s(:db) is deprecated. Please use TimeWithZone#to_formatted_s(:db) instead."
215
+ "TimeWithZone#to_s(:db) is deprecated. Please use TimeWithZone#to_fs(:db) instead."
216
216
  )
217
- utc.to_formatted_s(format)
217
+ utc.to_fs(format)
218
218
  elsif formatter = ::Time::DATE_FORMATS[format]
219
219
  ActiveSupport::Deprecation.warn(
220
- "TimeWithZone#to_s(#{format.inspect}) is deprecated. Please use TimeWithZone#to_formatted_s(#{format.inspect}) instead."
220
+ "TimeWithZone#to_s(#{format.inspect}) is deprecated. Please use TimeWithZone#to_fs(#{format.inspect}) instead."
221
221
  )
222
222
  formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
223
223
  elsif format == NOT_SET
224
224
  "#{time.strftime("%Y-%m-%d %H:%M:%S")} #{formatted_offset(false, 'UTC')}" # mimicking Ruby Time#to_s format
225
225
  else
226
226
  ActiveSupport::Deprecation.warn(
227
- "TimeWithZone#to_s(#{format.inspect}) is deprecated. Please use TimeWithZone#to_formatted_s(#{format.inspect}) instead."
227
+ "TimeWithZone#to_s(#{format.inspect}) is deprecated. Please use TimeWithZone#to_fs(#{format.inspect}) instead."
228
228
  )
229
229
  "#{time.strftime("%Y-%m-%d %H:%M:%S")} #{formatted_offset(false, 'UTC')}" # mimicking Ruby Time#to_s format
230
230
  end
@@ -232,15 +232,15 @@ module ActiveSupport
232
232
 
233
233
  # Returns a string of the object's date and time.
234
234
  #
235
- # This method is aliased to <tt>to_fs</tt>.
235
+ # This method is aliased to <tt>to_formatted_s</tt>.
236
236
  #
237
237
  # Accepts an optional <tt>format</tt>:
238
238
  # * <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).
239
+ # * <tt>:db</tt> - format outputs time in UTC :db time. See Time#to_fs(:db).
240
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)
241
+ def to_fs(format = :default)
242
242
  if format == :db
243
- utc.to_formatted_s(format)
243
+ utc.to_fs(format)
244
244
  elsif formatter = ::Time::DATE_FORMATS[format]
245
245
  formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
246
246
  else
@@ -248,7 +248,7 @@ module ActiveSupport
248
248
  "#{time.strftime("%Y-%m-%d %H:%M:%S")} #{formatted_offset(false, 'UTC')}"
249
249
  end
250
250
  end
251
- alias_method :to_fs, :to_formatted_s
251
+ alias_method :to_formatted_s, :to_fs
252
252
 
253
253
  # Replaces <tt>%Z</tt> directive with +zone before passing to Time#strftime,
254
254
  # so that zone information is correct.
@@ -54,7 +54,7 @@ module ActiveSupport
54
54
 
55
55
  FORMATTING = {
56
56
  "symbol" => Proc.new { |symbol| symbol.to_s },
57
- "date" => Proc.new { |date| date.to_formatted_s(:db) },
57
+ "date" => Proc.new { |date| date.to_fs(:db) },
58
58
  "dateTime" => Proc.new { |time| time.xmlschema },
59
59
  "binary" => Proc.new { |binary| ::Base64.encode64(binary) },
60
60
  "yaml" => Proc.new { |yaml| yaml.to_yaml }
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  #--
4
- # Copyright (c) 2005-2021 David Heinemeier Hansson
4
+ # Copyright (c) 2005-2022 David Heinemeier Hansson
5
5
  #
6
6
  # Permission is hereby granted, free of charge, to any person obtaining
7
7
  # a copy of this software and associated documentation files (the
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activesupport
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0
4
+ version: 7.0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-15 00:00:00.000000000 Z
11
+ date: 2022-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -359,12 +359,12 @@ licenses:
359
359
  - MIT
360
360
  metadata:
361
361
  bug_tracker_uri: https://github.com/rails/rails/issues
362
- changelog_uri: https://github.com/rails/rails/blob/v7.0.0/activesupport/CHANGELOG.md
363
- documentation_uri: https://api.rubyonrails.org/v7.0.0/
362
+ changelog_uri: https://github.com/rails/rails/blob/v7.0.2.2/activesupport/CHANGELOG.md
363
+ documentation_uri: https://api.rubyonrails.org/v7.0.2.2/
364
364
  mailing_list_uri: https://discuss.rubyonrails.org/c/rubyonrails-talk
365
- source_code_uri: https://github.com/rails/rails/tree/v7.0.0/activesupport
365
+ source_code_uri: https://github.com/rails/rails/tree/v7.0.2.2/activesupport
366
366
  rubygems_mfa_required: 'true'
367
- post_install_message:
367
+ post_install_message:
368
368
  rdoc_options:
369
369
  - "--encoding"
370
370
  - UTF-8
@@ -381,8 +381,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
381
381
  - !ruby/object:Gem::Version
382
382
  version: '0'
383
383
  requirements: []
384
- rubygems_version: 3.2.32
385
- signing_key:
384
+ rubygems_version: 3.2.22
385
+ signing_key:
386
386
  specification_version: 4
387
387
  summary: A toolkit of support libraries and Ruby core extensions extracted from the
388
388
  Rails framework.