activesupport 8.0.2 → 8.1.4

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 (123) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +646 -124
  3. data/README.rdoc +1 -1
  4. data/lib/active_support/backtrace_cleaner.rb +71 -0
  5. data/lib/active_support/broadcast_logger.rb +46 -59
  6. data/lib/active_support/cache/file_store.rb +1 -0
  7. data/lib/active_support/cache/mem_cache_store.rb +29 -28
  8. data/lib/active_support/cache/memory_store.rb +3 -1
  9. data/lib/active_support/cache/redis_cache_store.rb +46 -32
  10. data/lib/active_support/cache/strategy/local_cache.rb +17 -8
  11. data/lib/active_support/cache/strategy/local_cache_middleware.rb +7 -7
  12. data/lib/active_support/cache.rb +71 -7
  13. data/lib/active_support/callbacks.rb +20 -8
  14. data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +8 -62
  15. data/lib/active_support/concurrency/thread_monitor.rb +55 -0
  16. data/lib/active_support/configurable.rb +34 -0
  17. data/lib/active_support/continuous_integration.rb +145 -0
  18. data/lib/active_support/core_ext/array.rb +7 -7
  19. data/lib/active_support/core_ext/benchmark.rb +0 -12
  20. data/lib/active_support/core_ext/big_decimal.rb +1 -1
  21. data/lib/active_support/core_ext/class/attribute.rb +8 -6
  22. data/lib/active_support/core_ext/class.rb +2 -2
  23. data/lib/active_support/core_ext/date.rb +5 -5
  24. data/lib/active_support/core_ext/date_and_time/compatibility.rb +0 -35
  25. data/lib/active_support/core_ext/date_time/calculations.rb +1 -0
  26. data/lib/active_support/core_ext/date_time/compatibility.rb +3 -5
  27. data/lib/active_support/core_ext/date_time/conversions.rb +4 -2
  28. data/lib/active_support/core_ext/date_time.rb +5 -5
  29. data/lib/active_support/core_ext/digest.rb +1 -1
  30. data/lib/active_support/core_ext/enumerable.rb +18 -6
  31. data/lib/active_support/core_ext/erb/util.rb +3 -3
  32. data/lib/active_support/core_ext/file.rb +1 -1
  33. data/lib/active_support/core_ext/hash.rb +8 -8
  34. data/lib/active_support/core_ext/integer.rb +3 -3
  35. data/lib/active_support/core_ext/kernel.rb +3 -3
  36. data/lib/active_support/core_ext/module.rb +11 -11
  37. data/lib/active_support/core_ext/numeric.rb +3 -3
  38. data/lib/active_support/core_ext/object/instance_variables.rb +1 -1
  39. data/lib/active_support/core_ext/object/json.rb +9 -2
  40. data/lib/active_support/core_ext/object/to_query.rb +7 -1
  41. data/lib/active_support/core_ext/object/try.rb +2 -2
  42. data/lib/active_support/core_ext/object.rb +13 -13
  43. data/lib/active_support/core_ext/pathname.rb +2 -2
  44. data/lib/active_support/core_ext/range/compare_range.rb +2 -14
  45. data/lib/active_support/core_ext/range/overlap.rb +3 -3
  46. data/lib/active_support/core_ext/range/sole.rb +19 -0
  47. data/lib/active_support/core_ext/range.rb +4 -4
  48. data/lib/active_support/core_ext/string/filters.rb +5 -3
  49. data/lib/active_support/core_ext/string/inflections.rb +1 -1
  50. data/lib/active_support/core_ext/string/multibyte.rb +12 -3
  51. data/lib/active_support/core_ext/string/output_safety.rb +29 -13
  52. data/lib/active_support/core_ext/string.rb +13 -13
  53. data/lib/active_support/core_ext/symbol.rb +1 -1
  54. data/lib/active_support/core_ext/time/calculations.rb +4 -7
  55. data/lib/active_support/core_ext/time/compatibility.rb +2 -27
  56. data/lib/active_support/core_ext/time.rb +5 -5
  57. data/lib/active_support/current_attributes/test_helper.rb +2 -2
  58. data/lib/active_support/current_attributes.rb +26 -16
  59. data/lib/active_support/delegation.rb +25 -42
  60. data/lib/active_support/dependencies/interlock.rb +11 -5
  61. data/lib/active_support/dependencies.rb +6 -1
  62. data/lib/active_support/deprecation/reporting.rb +4 -2
  63. data/lib/active_support/deprecation.rb +1 -1
  64. data/lib/active_support/duration.rb +6 -6
  65. data/lib/active_support/editor.rb +70 -0
  66. data/lib/active_support/error_reporter.rb +50 -6
  67. data/lib/active_support/event_reporter/test_helper.rb +32 -0
  68. data/lib/active_support/event_reporter.rb +592 -0
  69. data/lib/active_support/evented_file_update_checker.rb +5 -1
  70. data/lib/active_support/execution_context.rb +75 -7
  71. data/lib/active_support/file_update_checker.rb +8 -6
  72. data/lib/active_support/gem_version.rb +2 -2
  73. data/lib/active_support/gzip.rb +1 -0
  74. data/lib/active_support/hash_with_indifferent_access.rb +49 -25
  75. data/lib/active_support/i18n_railtie.rb +2 -2
  76. data/lib/active_support/inflector/inflections.rb +34 -16
  77. data/lib/active_support/inflector/methods.rb +4 -4
  78. data/lib/active_support/inflector/transliterate.rb +18 -10
  79. data/lib/active_support/isolated_execution_state.rb +17 -15
  80. data/lib/active_support/json/decoding.rb +10 -4
  81. data/lib/active_support/json/encoding.rb +147 -17
  82. data/lib/active_support/lazy_load_hooks.rb +1 -1
  83. data/lib/active_support/log_subscriber.rb +2 -6
  84. data/lib/active_support/logger_thread_safe_level.rb +6 -3
  85. data/lib/active_support/message_encryptors.rb +52 -0
  86. data/lib/active_support/message_pack/extensions.rb +15 -1
  87. data/lib/active_support/message_verifiers.rb +52 -0
  88. data/lib/active_support/messages/rotation_coordinator.rb +9 -0
  89. data/lib/active_support/messages/rotator.rb +5 -0
  90. data/lib/active_support/messages/serializer_with_fallback.rb +1 -1
  91. data/lib/active_support/multibyte/chars.rb +8 -1
  92. data/lib/active_support/multibyte.rb +4 -0
  93. data/lib/active_support/notifications/fanout.rb +64 -42
  94. data/lib/active_support/notifications/instrumenter.rb +1 -1
  95. data/lib/active_support/notifications.rb +2 -2
  96. data/lib/active_support/number_helper/number_converter.rb +5 -2
  97. data/lib/active_support/number_helper/number_to_currency_converter.rb +1 -1
  98. data/lib/active_support/number_helper/number_to_delimited_converter.rb +19 -5
  99. data/lib/active_support/number_helper/number_to_phone_converter.rb +3 -7
  100. data/lib/active_support/number_helper/rounding_helper.rb +1 -1
  101. data/lib/active_support/ordered_options.rb +2 -2
  102. data/lib/active_support/railtie.rb +32 -15
  103. data/lib/active_support/security_utils.rb +4 -5
  104. data/lib/active_support/structured_event_subscriber.rb +99 -0
  105. data/lib/active_support/subscriber.rb +0 -5
  106. data/lib/active_support/syntax_error_proxy.rb +9 -1
  107. data/lib/active_support/test_case.rb +67 -6
  108. data/lib/active_support/testing/assertions.rb +42 -9
  109. data/lib/active_support/testing/autorun.rb +5 -0
  110. data/lib/active_support/testing/error_reporter_assertions.rb +17 -0
  111. data/lib/active_support/testing/event_reporter_assertions.rb +227 -0
  112. data/lib/active_support/testing/notification_assertions.rb +92 -0
  113. data/lib/active_support/testing/parallelization/server.rb +15 -2
  114. data/lib/active_support/testing/parallelization/worker.rb +9 -3
  115. data/lib/active_support/testing/parallelization.rb +29 -1
  116. data/lib/active_support/testing/tests_without_assertions.rb +1 -1
  117. data/lib/active_support/testing/time_helpers.rb +7 -3
  118. data/lib/active_support/time_with_zone.rb +27 -23
  119. data/lib/active_support/values/time_zone.rb +11 -4
  120. data/lib/active_support/xml_mini.rb +3 -2
  121. data/lib/active_support.rb +20 -15
  122. metadata +27 -19
  123. data/lib/active_support/core_ext/range/each.rb +0 -24
@@ -5,41 +5,6 @@ require "active_support/core_ext/module/redefine_method"
5
5
 
6
6
  module DateAndTime
7
7
  module Compatibility
8
- # If true, +to_time+ preserves the timezone offset of receiver.
9
- #
10
- # NOTE: With Ruby 2.4+ the default for +to_time+ changed from
11
- # converting to the local system time, to preserving the offset
12
- # of the receiver. For backwards compatibility we're overriding
13
- # this behavior, but new apps will have an initializer that sets
14
- # this to true, because the new behavior is preferred.
15
- mattr_accessor :preserve_timezone, instance_accessor: false, default: nil
16
-
17
- singleton_class.silence_redefinition_of_method :preserve_timezone
18
-
19
- #--
20
- # This re-implements the behaviour of the mattr_reader, instead
21
- # of prepending on to it, to avoid overcomplicating a module that
22
- # is in turn included in several places. This will all go away in
23
- # Rails 8.0 anyway.
24
- def self.preserve_timezone # :nodoc:
25
- if @@preserve_timezone.nil?
26
- # Only warn once, the first time the value is used (which should
27
- # be the first time #to_time is called).
28
- ActiveSupport.deprecator.warn(
29
- "`to_time` will always preserve the receiver timezone rather than system local time in Rails 8.1." \
30
- "To opt in to the new behavior, set `config.active_support.to_time_preserves_timezone = :zone`."
31
- )
32
-
33
- @@preserve_timezone = false
34
- end
35
-
36
- @@preserve_timezone
37
- end
38
-
39
- def preserve_timezone # :nodoc:
40
- Compatibility.preserve_timezone
41
- end
42
-
43
8
  # Change the output of <tt>ActiveSupport::TimeZone.utc_to_local</tt>.
44
9
  #
45
10
  # When +true+, it returns local times with a UTC offset, with +false+ local
@@ -80,6 +80,7 @@ class DateTime
80
80
  # largest to smallest. This order can affect the result around the end of a
81
81
  # month.
82
82
  def advance(options)
83
+ options = options.dup
83
84
  unless options[:weeks].nil?
84
85
  options[:weeks], partial_weeks = options[:weeks].divmod(1)
85
86
  options[:days] = options.fetch(:days, 0) + 7 * partial_weeks
@@ -8,11 +8,9 @@ class DateTime
8
8
 
9
9
  silence_redefinition_of_method :to_time
10
10
 
11
- # Either return an instance of +Time+ with the same UTC offset
12
- # as +self+ or an instance of +Time+ representing the same time
13
- # in the local system timezone depending on the setting of
14
- # on the setting of +ActiveSupport.to_time_preserves_timezone+.
11
+ # Return an instance of +Time+ with the same UTC offset
12
+ # as +self+.
15
13
  def to_time
16
- preserve_timezone ? getlocal(utc_offset) : getlocal
14
+ getlocal(utc_offset)
17
15
  end
18
16
  end
@@ -11,7 +11,8 @@ class DateTime
11
11
  #
12
12
  # This method is aliased to <tt>to_formatted_s</tt>.
13
13
  #
14
- # === Examples
14
+ # ==== Examples
15
+ #
15
16
  # datetime = DateTime.civil(2007, 12, 4, 0, 0, 0, 0) # => Tue, 04 Dec 2007 00:00:00 +0000
16
17
  #
17
18
  # datetime.to_fs(:db) # => "2007-12-04 00:00:00"
@@ -23,7 +24,8 @@ class DateTime
23
24
  # datetime.to_fs(:rfc822) # => "Tue, 04 Dec 2007 00:00:00 +0000"
24
25
  # datetime.to_fs(:iso8601) # => "2007-12-04T00:00:00+00:00"
25
26
  #
26
- # == Adding your own datetime formats to to_fs
27
+ # ==== Adding your own datetime formats to +to_fs+
28
+ #
27
29
  # DateTime formats are shared with Time. You can add your own to the
28
30
  # Time::DATE_FORMATS hash. Use the format name as the hash key and
29
31
  # either a strftime string or Proc instance that takes a time or
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/core_ext/date_time/acts_like"
4
- require "active_support/core_ext/date_time/blank"
5
- require "active_support/core_ext/date_time/calculations"
6
- require "active_support/core_ext/date_time/compatibility"
7
- require "active_support/core_ext/date_time/conversions"
3
+ require_relative "date_time/acts_like"
4
+ require_relative "date_time/blank"
5
+ require_relative "date_time/calculations"
6
+ require_relative "date_time/compatibility"
7
+ require_relative "date_time/conversions"
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/core_ext/digest/uuid"
3
+ require_relative "digest/uuid"
@@ -196,9 +196,9 @@ module Enumerable
196
196
  # the +filter+ option is set to +false+.
197
197
  def in_order_of(key, series, filter: true)
198
198
  if filter
199
- group_by(&key).values_at(*series).flatten(1).compact
199
+ group_by(&key).values_at(*series).compact.flatten(1)
200
200
  else
201
- sort_by { |v| series.index(v.public_send(key)) || series.size }.compact
201
+ sort_by { |v| series.index(v.public_send(key)) || series.size }
202
202
  end
203
203
  end
204
204
 
@@ -209,10 +209,22 @@ module Enumerable
209
209
  # Set.new.sole # => Enumerable::SoleItemExpectedError: no item found
210
210
  # { a: 1, b: 2 }.sole # => Enumerable::SoleItemExpectedError: multiple items found
211
211
  def sole
212
- case count
213
- when 1 then return first # rubocop:disable Style/RedundantReturn
214
- when 0 then raise ActiveSupport::EnumerableCoreExt::SoleItemExpectedError, "no item found"
215
- when 2.. then raise ActiveSupport::EnumerableCoreExt::SoleItemExpectedError, "multiple items found"
212
+ result = nil
213
+ found = false
214
+
215
+ each do |*element|
216
+ if found
217
+ raise SoleItemExpectedError, "multiple items found"
218
+ end
219
+
220
+ result = element.size == 1 ? element[0] : element
221
+ found = true
222
+ end
223
+
224
+ if found
225
+ result
226
+ else
227
+ raise SoleItemExpectedError, "no item found"
216
228
  end
217
229
  end
218
230
  end
@@ -12,7 +12,7 @@ module ActiveSupport
12
12
  if s.html_safe?
13
13
  s
14
14
  else
15
- super(ActiveSupport::Multibyte::Unicode.tidy_bytes(s))
15
+ super(s)
16
16
  end
17
17
  end
18
18
  alias :unwrapped_html_escape :html_escape # :nodoc:
@@ -61,7 +61,7 @@ class ERB
61
61
  # html_escape_once('&lt;&lt; Accept & Checkout')
62
62
  # # => "&lt;&lt; Accept &amp; Checkout"
63
63
  def html_escape_once(s)
64
- ActiveSupport::Multibyte::Unicode.tidy_bytes(s.to_s).gsub(HTML_ESCAPE_ONCE_REGEXP, HTML_ESCAPE).html_safe
64
+ s.to_s.gsub(HTML_ESCAPE_ONCE_REGEXP, HTML_ESCAPE).html_safe
65
65
  end
66
66
 
67
67
  module_function :html_escape_once
@@ -169,7 +169,7 @@ class ERB
169
169
  while !source.eos?
170
170
  pos = source.pos
171
171
  source.scan_until(/(?:#{start_re}|#{finish_re})/)
172
- raise NotImplementedError if source.matched.nil?
172
+ return [[:PLAIN, source.string]] unless source.matched?
173
173
  len = source.pos - source.matched.bytesize - pos
174
174
 
175
175
  case source.matched
@@ -1,3 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/core_ext/file/atomic"
3
+ require_relative "file/atomic"
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/core_ext/hash/conversions"
4
- require "active_support/core_ext/hash/deep_merge"
5
- require "active_support/core_ext/hash/deep_transform_values"
6
- require "active_support/core_ext/hash/except"
7
- require "active_support/core_ext/hash/indifferent_access"
8
- require "active_support/core_ext/hash/keys"
9
- require "active_support/core_ext/hash/reverse_merge"
10
- require "active_support/core_ext/hash/slice"
3
+ require_relative "hash/conversions"
4
+ require_relative "hash/deep_merge"
5
+ require_relative "hash/deep_transform_values"
6
+ require_relative "hash/except"
7
+ require_relative "hash/indifferent_access"
8
+ require_relative "hash/keys"
9
+ require_relative "hash/reverse_merge"
10
+ require_relative "hash/slice"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/core_ext/integer/multiple"
4
- require "active_support/core_ext/integer/inflections"
5
- require "active_support/core_ext/integer/time"
3
+ require_relative "integer/multiple"
4
+ require_relative "integer/inflections"
5
+ require_relative "integer/time"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/core_ext/kernel/concern"
4
- require "active_support/core_ext/kernel/reporting"
5
- require "active_support/core_ext/kernel/singleton_class"
3
+ require_relative "kernel/concern"
4
+ require_relative "kernel/reporting"
5
+ require_relative "kernel/singleton_class"
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/core_ext/module/aliasing"
4
- require "active_support/core_ext/module/introspection"
5
- require "active_support/core_ext/module/anonymous"
6
- require "active_support/core_ext/module/attribute_accessors"
7
- require "active_support/core_ext/module/attribute_accessors_per_thread"
8
- require "active_support/core_ext/module/attr_internal"
9
- require "active_support/core_ext/module/concerning"
10
- require "active_support/core_ext/module/delegation"
11
- require "active_support/core_ext/module/deprecation"
12
- require "active_support/core_ext/module/redefine_method"
13
- require "active_support/core_ext/module/remove_method"
3
+ require_relative "module/aliasing"
4
+ require_relative "module/introspection"
5
+ require_relative "module/anonymous"
6
+ require_relative "module/attribute_accessors"
7
+ require_relative "module/attribute_accessors_per_thread"
8
+ require_relative "module/attr_internal"
9
+ require_relative "module/concerning"
10
+ require_relative "module/delegation"
11
+ require_relative "module/deprecation"
12
+ require_relative "module/redefine_method"
13
+ require_relative "module/remove_method"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/core_ext/numeric/bytes"
4
- require "active_support/core_ext/numeric/time"
5
- require "active_support/core_ext/numeric/conversions"
3
+ require_relative "numeric/bytes"
4
+ require_relative "numeric/time"
5
+ require_relative "numeric/conversions"
@@ -25,7 +25,7 @@ class Object
25
25
  # end
26
26
  # end
27
27
  #
28
- # C.new(0, 1).instance_variable_names # => ["@y", "@x"]
28
+ # C.new(0, 1).instance_variable_names # => ["@x", "@y"]
29
29
  def instance_variable_names
30
30
  instance_variables.map(&:name)
31
31
  end
@@ -4,7 +4,7 @@
4
4
  require "json"
5
5
  require "bigdecimal"
6
6
  require "ipaddr"
7
- require "uri/generic"
7
+ require "uri"
8
8
  require "pathname"
9
9
  require "active_support/core_ext/big_decimal/conversions" # for #to_s
10
10
  require "active_support/core_ext/hash/except"
@@ -240,9 +240,16 @@ class Pathname # :nodoc:
240
240
  end
241
241
 
242
242
  unless IPAddr.method_defined?(:as_json, false)
243
+ # Use `IPAddr#as_json` from the IPAddr gem if the version is 1.2.7 or higher.
243
244
  class IPAddr # :nodoc:
244
245
  def as_json(options = nil)
245
- to_s
246
+ if ipv4? && prefix == 32
247
+ to_s
248
+ elsif ipv6? && prefix == 128
249
+ to_s
250
+ else
251
+ "#{self}/#{prefix}"
252
+ end
246
253
  end
247
254
  end
248
255
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "cgi"
3
+ require "cgi/escape"
4
+ require "cgi/util" if RUBY_VERSION < "3.5"
4
5
 
5
6
  class Object
6
7
  # Alias of <tt>to_s</tt>.
@@ -16,6 +17,11 @@ class Object
16
17
  end
17
18
 
18
19
  class NilClass
20
+ # Returns a CGI-escaped +key+.
21
+ def to_query(key)
22
+ CGI.escape(key.to_param)
23
+ end
24
+
19
25
  # Returns +self+.
20
26
  def to_param
21
27
  self
@@ -145,14 +145,14 @@ class NilClass
145
145
  #
146
146
  # With +try+
147
147
  # @person.try(:children).try(:first).try(:name)
148
- def try(*)
148
+ def try(*, &)
149
149
  nil
150
150
  end
151
151
 
152
152
  # Calling +try!+ on +nil+ always returns +nil+.
153
153
  #
154
154
  # nil.try!(:name) # => nil
155
- def try!(*)
155
+ def try!(*, &)
156
156
  nil
157
157
  end
158
158
  end
@@ -1,17 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/core_ext/object/acts_like"
4
- require "active_support/core_ext/object/blank"
5
- require "active_support/core_ext/object/duplicable"
6
- require "active_support/core_ext/object/deep_dup"
7
- require "active_support/core_ext/object/try"
8
- require "active_support/core_ext/object/inclusion"
3
+ require_relative "object/acts_like"
4
+ require_relative "object/blank"
5
+ require_relative "object/duplicable"
6
+ require_relative "object/deep_dup"
7
+ require_relative "object/try"
8
+ require_relative "object/inclusion"
9
9
 
10
- require "active_support/core_ext/object/conversions"
11
- require "active_support/core_ext/object/instance_variables"
10
+ require_relative "object/conversions"
11
+ require_relative "object/instance_variables"
12
12
 
13
- require "active_support/core_ext/object/json"
14
- require "active_support/core_ext/object/to_param"
15
- require "active_support/core_ext/object/to_query"
16
- require "active_support/core_ext/object/with"
17
- require "active_support/core_ext/object/with_options"
13
+ require_relative "object/json"
14
+ require_relative "object/to_param"
15
+ require_relative "object/to_query"
16
+ require_relative "object/with"
17
+ require_relative "object/with_options"
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/core_ext/pathname/blank"
4
- require "active_support/core_ext/pathname/existence"
3
+ require_relative "pathname/blank"
4
+ require_relative "pathname/existence"
@@ -15,13 +15,7 @@ module ActiveSupport
15
15
  # The given range must be fully bounded, with both start and end.
16
16
  def ===(value)
17
17
  if value.is_a?(::Range)
18
- is_backwards_op = value.exclude_end? ? :>= : :>
19
- return false if value.begin && value.end && value.begin.public_send(is_backwards_op, value.end)
20
- # 1...10 includes 1..9 but it does not include 1..10.
21
- # 1..10 includes 1...11 but it does not include 1...12.
22
- operator = exclude_end? && !value.exclude_end? ? :< : :<=
23
- value_max = !exclude_end? && value.exclude_end? ? value.max : value.last
24
- super(value.first) && (self.end.nil? || value_max.public_send(operator, last))
18
+ cover?(value)
25
19
  else
26
20
  super
27
21
  end
@@ -40,13 +34,7 @@ module ActiveSupport
40
34
  # The given range must be fully bounded, with both start and end.
41
35
  def include?(value)
42
36
  if value.is_a?(::Range)
43
- is_backwards_op = value.exclude_end? ? :>= : :>
44
- return false if value.begin && value.end && value.begin.public_send(is_backwards_op, value.end)
45
- # 1...10 includes 1..9 but it does not include 1..10.
46
- # 1..10 includes 1...11 but it does not include 1...12.
47
- operator = exclude_end? && !value.exclude_end? ? :< : :<=
48
- value_max = !exclude_end? && value.exclude_end? ? value.max : value.last
49
- super(value.first) && (self.end.nil? || value_max.public_send(operator, last))
37
+ cover?(value)
50
38
  else
51
39
  super
52
40
  end
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Range
4
- # Compare two ranges and see if they overlap each other
5
- # (1..5).overlap?(4..6) # => true
6
- # (1..5).overlap?(7..9) # => false
7
4
  unless Range.method_defined?(:overlap?) # Ruby 3.3+
5
+ # Compare two ranges and see if they overlap each other
6
+ # (1..5).overlap?(4..6) # => true
7
+ # (1..5).overlap?(7..9) # => false
8
8
  def overlap?(other)
9
9
  raise TypeError unless other.is_a? Range
10
10
 
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/core_ext/enumerable"
4
+
5
+ class Range
6
+ # Returns the sole item in the range. If there are no items, or more
7
+ # than one item, raises Enumerable::SoleItemExpectedError.
8
+ #
9
+ # (1..1).sole # => 1
10
+ # (2..1).sole # => Enumerable::SoleItemExpectedError: no item found
11
+ # (..1).sole # => Enumerable::SoleItemExpectedError: infinite range cannot represent a sole item
12
+ def sole
13
+ if self.begin.nil? || self.end.nil?
14
+ raise ActiveSupport::EnumerableCoreExt::SoleItemExpectedError, "infinite range '#{inspect}' cannot represent a sole item"
15
+ end
16
+
17
+ super
18
+ end
19
+ end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/core_ext/range/conversions"
4
- require "active_support/core_ext/range/compare_range"
5
- require "active_support/core_ext/range/overlap"
6
- require "active_support/core_ext/range/each"
3
+ require_relative "range/conversions"
4
+ require_relative "range/compare_range"
5
+ require_relative "range/overlap"
6
+ require_relative "range/sole"
@@ -72,6 +72,8 @@ class String
72
72
 
73
73
  omission = options[:omission] || "..."
74
74
  length_with_room_for_omission = truncate_to - omission.length
75
+ return omission.dup if length_with_room_for_omission <= 0
76
+
75
77
  stop = \
76
78
  if options[:separator]
77
79
  rindex(options[:separator], length_with_room_for_omission) || length_with_room_for_omission
@@ -88,11 +90,11 @@ class String
88
90
  # characters.
89
91
  #
90
92
  # >> "🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪".size
91
- # => 20
93
+ # # => 20
92
94
  # >> "🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪".bytesize
93
- # => 80
95
+ # # => 80
94
96
  # >> "🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪🔪".truncate_bytes(20)
95
- # => "🔪🔪🔪🔪…"
97
+ # # => "🔪🔪🔪🔪…"
96
98
  #
97
99
  # The truncated text ends with the <tt>:omission</tt> string, defaulting
98
100
  # to "…", for a total length not exceeding <tt>truncate_to</tt>.
@@ -248,7 +248,7 @@ class String
248
248
  # optional parameter +capitalize+ to false.
249
249
  # By default, this parameter is true.
250
250
  #
251
- # The trailing '_id' can be kept and capitalized by setting the
251
+ # The trailing '_id' can be kept by setting the
252
252
  # optional parameter +keep_id_suffix+ to true.
253
253
  # By default, this parameter is false.
254
254
  #
@@ -12,12 +12,12 @@ class String
12
12
  # class. If the proxy class doesn't respond to a certain method, it's forwarded to the encapsulated string.
13
13
  #
14
14
  # >> "lj".mb_chars.upcase.to_s
15
- # => "LJ"
15
+ # # => "LJ"
16
16
  #
17
17
  # NOTE: Ruby 2.4 and later support native Unicode case mappings:
18
18
  #
19
19
  # >> "lj".upcase
20
- # => "LJ"
20
+ # # => "LJ"
21
21
  #
22
22
  # == \Method chaining
23
23
  #
@@ -35,7 +35,16 @@ class String
35
35
  # For more information about the methods defined on the Chars proxy see ActiveSupport::Multibyte::Chars. For
36
36
  # information about how to change the default Multibyte behavior see ActiveSupport::Multibyte.
37
37
  def mb_chars
38
- ActiveSupport::Multibyte.proxy_class.new(self)
38
+ ActiveSupport.deprecator.warn(
39
+ "String#mb_chars is deprecated and will be removed in Rails 8.2. " \
40
+ "Use normal string methods instead."
41
+ )
42
+
43
+ if ActiveSupport::Multibyte.proxy_class == ActiveSupport::Multibyte::Chars
44
+ ActiveSupport::Multibyte::Chars.new(self, deprecation: false)
45
+ else
46
+ ActiveSupport::Multibyte.proxy_class.new(self)
47
+ end
39
48
  end
40
49
 
41
50
  # Returns +true+ if string has utf_8 encoding.
@@ -67,14 +67,13 @@ module ActiveSupport # :nodoc:
67
67
  original_concat(value)
68
68
  end
69
69
 
70
- def initialize(str = "")
71
- @html_safe = true
70
+ def initialize(_str = "")
72
71
  super
73
72
  end
74
73
 
75
74
  def initialize_copy(other)
76
75
  super
77
- @html_safe = other.html_safe?
76
+ @html_unsafe = true unless other.html_safe?
78
77
  end
79
78
 
80
79
  def concat(value)
@@ -116,7 +115,9 @@ module ActiveSupport # :nodoc:
116
115
  def *(_)
117
116
  new_string = super
118
117
  new_safe_buffer = new_string.is_a?(SafeBuffer) ? new_string : SafeBuffer.new(new_string)
119
- new_safe_buffer.instance_variable_set(:@html_safe, @html_safe)
118
+ if @html_unsafe
119
+ new_safe_buffer.mark_unsafe!
120
+ end
120
121
  new_safe_buffer
121
122
  end
122
123
 
@@ -128,17 +129,25 @@ module ActiveSupport # :nodoc:
128
129
  escaped_args = Array(args).map { |arg| explicit_html_escape_interpolated_argument(arg) }
129
130
  end
130
131
 
131
- self.class.new(super(escaped_args))
132
+ new_safe_buffer = self.class.new(super(escaped_args))
133
+ if @html_unsafe
134
+ new_safe_buffer.mark_unsafe!
135
+ end
136
+ new_safe_buffer
132
137
  end
133
138
 
134
- attr_reader :html_safe
135
- alias_method :html_safe?, :html_safe
136
- remove_method :html_safe
139
+ def html_safe?
140
+ @html_unsafe.nil?
141
+ end
137
142
 
138
143
  def to_s
139
144
  self
140
145
  end
141
146
 
147
+ def as_json(*)
148
+ to_str
149
+ end
150
+
142
151
  def to_param
143
152
  to_str
144
153
  end
@@ -155,7 +164,7 @@ module ActiveSupport # :nodoc:
155
164
  end # end
156
165
 
157
166
  def #{unsafe_method}!(*args) # def capitalize!(*args)
158
- @html_safe = false # @html_safe = false
167
+ @html_unsafe = true # @html_unsafe = true
159
168
  super # super
160
169
  end # end
161
170
  EOT
@@ -176,7 +185,7 @@ module ActiveSupport # :nodoc:
176
185
  end # end
177
186
 
178
187
  def #{unsafe_method}!(*args, &block) # def gsub!(*args, &block)
179
- @html_safe = false # @html_safe = false
188
+ @html_unsafe = true # @html_unsafe = true
180
189
  if block # if block
181
190
  super(*args) { |*params| # super(*args) { |*params|
182
191
  set_block_back_references(block, $~) # set_block_back_references(block, $~)
@@ -189,16 +198,21 @@ module ActiveSupport # :nodoc:
189
198
  EOT
190
199
  end
191
200
 
201
+ protected
202
+ def mark_unsafe!
203
+ @html_unsafe = true
204
+ end
205
+
192
206
  private
193
207
  def explicit_html_escape_interpolated_argument(arg)
194
- (!html_safe? || arg.html_safe?) ? arg : CGI.escapeHTML(arg.to_s)
208
+ (!html_safe? || arg.html_safe?) ? arg : ERB::Util.unwrapped_html_escape(arg)
195
209
  end
196
210
 
197
211
  def implicit_html_escape_interpolated_argument(arg)
198
212
  if !html_safe? || arg.html_safe?
199
213
  arg
200
214
  else
201
- CGI.escapeHTML(arg.to_str)
215
+ ERB::Util.unwrapped_html_escape(arg.to_str)
202
216
  end
203
217
  end
204
218
 
@@ -210,7 +224,9 @@ module ActiveSupport # :nodoc:
210
224
 
211
225
  def string_into_safe_buffer(new_string, is_html_safe)
212
226
  new_safe_buffer = new_string.is_a?(SafeBuffer) ? new_string : SafeBuffer.new(new_string)
213
- new_safe_buffer.instance_variable_set :@html_safe, is_html_safe
227
+ unless is_html_safe
228
+ new_safe_buffer.instance_variable_set :@html_unsafe, true
229
+ end
214
230
  new_safe_buffer
215
231
  end
216
232
  end