activesupport 7.0.0.rc3 → 7.0.2.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 (31) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +42 -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/pathname/existence.rb +1 -1
  17. data/lib/active_support/core_ext/range/conversions.rb +6 -6
  18. data/lib/active_support/core_ext/range/deprecated_conversions.rb +2 -2
  19. data/lib/active_support/core_ext/time/conversions.rb +12 -12
  20. data/lib/active_support/core_ext/time/deprecated_conversions.rb +2 -2
  21. data/lib/active_support/descendants_tracker.rb +2 -5
  22. data/lib/active_support/duration.rb +4 -3
  23. data/lib/active_support/encrypted_configuration.rb +2 -1
  24. data/lib/active_support/execution_wrapper.rb +19 -23
  25. data/lib/active_support/gem_version.rb +2 -2
  26. data/lib/active_support/isolated_execution_state.rb +8 -0
  27. data/lib/active_support/message_verifier.rb +42 -10
  28. data/lib/active_support/time_with_zone.rb +11 -11
  29. data/lib/active_support/xml_mini.rb +1 -1
  30. data/lib/active_support.rb +1 -1
  31. metadata +8 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c7110a52aaa738de876f0b598bccaa36eaa90fcc4876814a6d6305044627c83f
4
- data.tar.gz: c098f6ce349f5ae09b4a667152d751e07458c604c34c31d1f48714026ddda9ea
3
+ metadata.gz: 6e70dc41bc4e591f21025665c88110be5fb573df096ff18a32c8eb03537cd912
4
+ data.tar.gz: 44a03ceb522ac0a8bcaa495d885c67275eb900009273bd112b1002a713839e8c
5
5
  SHA512:
6
- metadata.gz: 43b79d9a130422f225a3b98c05d180deeca4a1da94af3a722c24e60740c87924844cbf8aaf62c18cc664134defe7f25747e18fb90ba2015b33f2c4307a741c11
7
- data.tar.gz: d977cc5c6f9cbeb0e71e9f0a848bc61bc0c3c43b9c212367bba36a42694786fb3cb58dabaa21fb78e42522e3247dd2b5109a628fb096ee0682d0f319d65045b3
6
+ metadata.gz: f3892232fa94ad774164911956d1dde53e1e3a14fa5d9cffcb7df472f0e1a410c3570edc6d16ce4e84842896cccce6fae31ec6215d0b5afb899e5829348eb804
7
+ data.tar.gz: 417107f4d3fa176ccaea68b6e7384a4ed06a622821a2d08f78fd8051b76c5df78ada4007e7f2f58a843718c5d16083ad8fe710cd0cf0440c4f622dacd8143e8f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,41 @@
1
+ ## Rails 7.0.2.1 (February 11, 2022) ##
2
+
3
+ * No changes.
4
+
5
+
6
+ ## Rails 7.0.2 (February 08, 2022) ##
7
+
8
+ * Fix `ActiveSupport::EncryptedConfiguration` to be compatible with Psych 4
9
+
10
+ *Stephen Sugden*
11
+
12
+ * Improve `File.atomic_write` error handling.
13
+
14
+ *Daniel Pepper*
15
+
16
+
17
+ ## Rails 7.0.1 (January 06, 2022) ##
18
+
19
+ * Fix `Class#descendants` and `DescendantsTracker#descendants` compatibility with Ruby 3.1.
20
+
21
+ [The native `Class#descendants` was reverted prior to Ruby 3.1 release](https://bugs.ruby-lang.org/issues/14394#note-33),
22
+ but `Class#subclasses` was kept, breaking the feature detection.
23
+
24
+ *Jean Boussier*
25
+
26
+
27
+ ## Rails 7.0.0 (December 15, 2021) ##
28
+
29
+ * Fix `ActiveSupport::Duration.build` to support negative values.
30
+
31
+ The algorithm to collect the `parts` of the `ActiveSupport::Duration`
32
+ ignored the sign of the `value` and accumulated incorrect part values. This
33
+ impacted `ActiveSupport::Duration#sum` (which is dependent on `parts`) but
34
+ not `ActiveSupport::Duration#eql?` (which is dependent on `value`).
35
+
36
+ *Caleb Buxton*, *Braden Staudacher*
37
+
38
+
1
39
  ## Rails 7.0.0.rc3 (December 14, 2021) ##
2
40
 
3
41
  * No changes.
@@ -5,6 +43,10 @@
5
43
 
6
44
  ## Rails 7.0.0.rc2 (December 14, 2021) ##
7
45
 
46
+ * No changes.
47
+
48
+ ## Rails 7.0.0.rc1 (December 06, 2021) ##
49
+
8
50
  * Deprecate passing a format to `#to_s` in favor of `#to_formatted_s` in `Array`, `Range`, `Date`, `DateTime`, `Time`,
9
51
  `BigDecimal`, `Float` and, `Integer`.
10
52
 
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"
29
+ # date.to_fs(:db) # => "2007-11-10"
30
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_formatted_s(: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