activesupport 6.1.4.1 → 7.0.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +216 -473
- data/MIT-LICENSE +1 -1
- data/lib/active_support/actionable_error.rb +1 -1
- data/lib/active_support/array_inquirer.rb +0 -2
- data/lib/active_support/benchmarkable.rb +2 -2
- data/lib/active_support/cache/file_store.rb +15 -9
- data/lib/active_support/cache/mem_cache_store.rb +127 -32
- data/lib/active_support/cache/memory_store.rb +23 -15
- data/lib/active_support/cache/null_store.rb +10 -2
- data/lib/active_support/cache/redis_cache_store.rb +42 -67
- data/lib/active_support/cache/strategy/local_cache.rb +35 -61
- data/lib/active_support/cache.rb +189 -45
- data/lib/active_support/callbacks.rb +180 -81
- data/lib/active_support/code_generator.rb +65 -0
- data/lib/active_support/concern.rb +5 -5
- data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +2 -4
- data/lib/active_support/concurrency/share_lock.rb +2 -2
- data/lib/active_support/configurable.rb +6 -3
- data/lib/active_support/configuration_file.rb +1 -1
- data/lib/active_support/core_ext/array/access.rb +1 -5
- data/lib/active_support/core_ext/array/conversions.rb +9 -7
- data/lib/active_support/core_ext/array/deprecated_conversions.rb +25 -0
- data/lib/active_support/core_ext/array/grouping.rb +6 -6
- data/lib/active_support/core_ext/array.rb +1 -0
- data/lib/active_support/core_ext/big_decimal/conversions.rb +1 -1
- data/lib/active_support/core_ext/class/subclasses.rb +25 -17
- data/lib/active_support/core_ext/date/blank.rb +1 -1
- data/lib/active_support/core_ext/date/calculations.rb +4 -4
- data/lib/active_support/core_ext/date/conversions.rb +3 -3
- data/lib/active_support/core_ext/date/deprecated_conversions.rb +26 -0
- data/lib/active_support/core_ext/date.rb +1 -0
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +1 -1
- data/lib/active_support/core_ext/date_time/blank.rb +1 -1
- data/lib/active_support/core_ext/date_time/conversions.rb +5 -5
- data/lib/active_support/core_ext/date_time/deprecated_conversions.rb +22 -0
- data/lib/active_support/core_ext/date_time.rb +1 -0
- data/lib/active_support/core_ext/digest/uuid.rb +39 -13
- data/lib/active_support/core_ext/enumerable.rb +64 -12
- data/lib/active_support/core_ext/file/atomic.rb +1 -1
- data/lib/active_support/core_ext/hash/keys.rb +1 -1
- data/lib/active_support/core_ext/kernel/reporting.rb +4 -4
- data/lib/active_support/core_ext/module/attribute_accessors.rb +2 -0
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +19 -10
- data/lib/active_support/core_ext/module/delegation.rb +2 -8
- data/lib/active_support/core_ext/name_error.rb +2 -8
- data/lib/active_support/core_ext/numeric/conversions.rb +79 -76
- data/lib/active_support/core_ext/numeric/deprecated_conversions.rb +60 -0
- data/lib/active_support/core_ext/numeric.rb +1 -0
- data/lib/active_support/core_ext/object/acts_like.rb +29 -5
- data/lib/active_support/core_ext/object/blank.rb +2 -2
- data/lib/active_support/core_ext/object/deep_dup.rb +1 -1
- data/lib/active_support/core_ext/object/duplicable.rb +11 -0
- data/lib/active_support/core_ext/object/json.rb +29 -24
- data/lib/active_support/core_ext/object/to_query.rb +2 -2
- data/lib/active_support/core_ext/object/try.rb +20 -20
- data/lib/active_support/core_ext/object/with_options.rb +20 -1
- data/lib/active_support/core_ext/pathname/existence.rb +21 -0
- data/lib/active_support/core_ext/pathname.rb +3 -0
- data/lib/active_support/core_ext/range/compare_range.rb +0 -25
- data/lib/active_support/core_ext/range/conversions.rb +8 -8
- data/lib/active_support/core_ext/range/deprecated_conversions.rb +26 -0
- data/lib/active_support/core_ext/range/each.rb +1 -1
- data/lib/active_support/core_ext/range/include_time_with_zone.rb +4 -25
- data/lib/active_support/core_ext/range.rb +1 -1
- data/lib/active_support/core_ext/string/filters.rb +1 -1
- data/lib/active_support/core_ext/string/inflections.rb +1 -1
- data/lib/active_support/core_ext/string/output_safety.rb +60 -36
- data/lib/active_support/core_ext/symbol/starts_ends_with.rb +0 -8
- data/lib/active_support/core_ext/time/calculations.rb +7 -6
- data/lib/active_support/core_ext/time/conversions.rb +4 -3
- data/lib/active_support/core_ext/time/deprecated_conversions.rb +22 -0
- data/lib/active_support/core_ext/time/zones.rb +4 -19
- data/lib/active_support/core_ext/time.rb +1 -0
- data/lib/active_support/core_ext/uri.rb +3 -27
- data/lib/active_support/core_ext.rb +1 -0
- data/lib/active_support/current_attributes.rb +31 -14
- data/lib/active_support/dependencies/interlock.rb +10 -18
- data/lib/active_support/dependencies/require_dependency.rb +28 -0
- data/lib/active_support/dependencies.rb +58 -788
- data/lib/active_support/deprecation/behaviors.rb +4 -1
- data/lib/active_support/deprecation/method_wrappers.rb +3 -3
- data/lib/active_support/deprecation/proxy_wrappers.rb +1 -1
- data/lib/active_support/deprecation.rb +1 -1
- data/lib/active_support/descendants_tracker.rb +174 -68
- data/lib/active_support/digest.rb +5 -3
- data/lib/active_support/duration/iso8601_parser.rb +3 -3
- data/lib/active_support/duration/iso8601_serializer.rb +9 -1
- data/lib/active_support/duration.rb +81 -51
- data/lib/active_support/encrypted_configuration.rb +11 -1
- data/lib/active_support/encrypted_file.rb +1 -1
- data/lib/active_support/environment_inquirer.rb +1 -1
- data/lib/active_support/error_reporter.rb +117 -0
- data/lib/active_support/evented_file_update_checker.rb +1 -1
- data/lib/active_support/execution_context/test_helper.rb +13 -0
- data/lib/active_support/execution_context.rb +53 -0
- data/lib/active_support/execution_wrapper.rb +30 -4
- data/lib/active_support/executor/test_helper.rb +7 -0
- data/lib/active_support/fork_tracker.rb +19 -12
- data/lib/active_support/gem_version.rb +4 -4
- data/lib/active_support/hash_with_indifferent_access.rb +3 -1
- data/lib/active_support/html_safe_translation.rb +43 -0
- data/lib/active_support/i18n.rb +1 -0
- data/lib/active_support/i18n_railtie.rb +1 -1
- data/lib/active_support/inflector/inflections.rb +23 -7
- data/lib/active_support/inflector/methods.rb +24 -48
- data/lib/active_support/isolated_execution_state.rb +56 -0
- data/lib/active_support/json/encoding.rb +3 -3
- data/lib/active_support/key_generator.rb +18 -1
- data/lib/active_support/locale/en.yml +1 -1
- data/lib/active_support/log_subscriber.rb +13 -3
- data/lib/active_support/logger_thread_safe_level.rb +4 -13
- data/lib/active_support/message_encryptor.rb +8 -3
- data/lib/active_support/message_verifier.rb +46 -14
- data/lib/active_support/messages/metadata.rb +2 -2
- data/lib/active_support/multibyte/chars.rb +10 -11
- data/lib/active_support/multibyte/unicode.rb +0 -12
- data/lib/active_support/multibyte.rb +1 -1
- data/lib/active_support/notifications/fanout.rb +91 -65
- data/lib/active_support/notifications/instrumenter.rb +32 -15
- data/lib/active_support/notifications.rb +15 -21
- data/lib/active_support/number_helper/number_converter.rb +1 -3
- data/lib/active_support/number_helper/number_to_currency_converter.rb +11 -6
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +1 -1
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +1 -1
- data/lib/active_support/number_helper/number_to_phone_converter.rb +1 -1
- data/lib/active_support/number_helper/rounding_helper.rb +1 -5
- data/lib/active_support/number_helper.rb +0 -2
- data/lib/active_support/option_merger.rb +8 -16
- data/lib/active_support/ordered_hash.rb +1 -1
- data/lib/active_support/parameter_filter.rb +5 -0
- data/lib/active_support/per_thread_registry.rb +5 -0
- data/lib/active_support/railtie.rb +69 -19
- data/lib/active_support/rescuable.rb +2 -2
- data/lib/active_support/ruby_features.rb +7 -0
- data/lib/active_support/secure_compare_rotator.rb +1 -1
- data/lib/active_support/string_inquirer.rb +0 -2
- data/lib/active_support/subscriber.rb +7 -18
- data/lib/active_support/tagged_logging.rb +2 -2
- data/lib/active_support/test_case.rb +9 -21
- data/lib/active_support/testing/assertions.rb +35 -5
- data/lib/active_support/testing/deprecation.rb +52 -1
- data/lib/active_support/testing/isolation.rb +2 -2
- data/lib/active_support/testing/method_call_assertions.rb +5 -5
- data/lib/active_support/testing/parallelization/server.rb +4 -0
- data/lib/active_support/testing/parallelization/worker.rb +3 -0
- data/lib/active_support/testing/parallelization.rb +4 -0
- data/lib/active_support/testing/parallelize_executor.rb +76 -0
- data/lib/active_support/testing/stream.rb +3 -5
- data/lib/active_support/testing/tagged_logging.rb +1 -1
- data/lib/active_support/testing/time_helpers.rb +13 -2
- data/lib/active_support/time_with_zone.rb +53 -12
- data/lib/active_support/values/time_zone.rb +30 -9
- data/lib/active_support/xml_mini/jdom.rb +1 -1
- data/lib/active_support/xml_mini/libxml.rb +5 -5
- data/lib/active_support/xml_mini/libxmlsax.rb +1 -1
- data/lib/active_support/xml_mini/nokogiri.rb +4 -4
- data/lib/active_support/xml_mini/nokogirisax.rb +1 -1
- data/lib/active_support/xml_mini/rexml.rb +1 -1
- data/lib/active_support/xml_mini.rb +5 -4
- data/lib/active_support.rb +17 -1
- metadata +29 -26
- data/lib/active_support/core_ext/marshal.rb +0 -26
- data/lib/active_support/dependencies/zeitwerk_integration.rb +0 -117
@@ -3,32 +3,32 @@
|
|
3
3
|
require "delegate"
|
4
4
|
|
5
5
|
module ActiveSupport
|
6
|
-
module Tryable
|
7
|
-
def try(
|
8
|
-
if
|
9
|
-
if
|
10
|
-
instance_eval(&
|
6
|
+
module Tryable # :nodoc:
|
7
|
+
def try(*args, &block)
|
8
|
+
if args.empty? && block_given?
|
9
|
+
if block.arity == 0
|
10
|
+
instance_eval(&block)
|
11
11
|
else
|
12
12
|
yield self
|
13
13
|
end
|
14
|
-
elsif respond_to?(
|
15
|
-
public_send(
|
14
|
+
elsif respond_to?(args.first)
|
15
|
+
public_send(*args, &block)
|
16
16
|
end
|
17
17
|
end
|
18
|
-
ruby2_keywords(:try)
|
18
|
+
ruby2_keywords(:try)
|
19
19
|
|
20
|
-
def try!(
|
21
|
-
if
|
22
|
-
if
|
23
|
-
instance_eval(&
|
20
|
+
def try!(*args, &block)
|
21
|
+
if args.empty? && block_given?
|
22
|
+
if block.arity == 0
|
23
|
+
instance_eval(&block)
|
24
24
|
else
|
25
25
|
yield self
|
26
26
|
end
|
27
27
|
else
|
28
|
-
public_send(
|
28
|
+
public_send(*args, &block)
|
29
29
|
end
|
30
30
|
end
|
31
|
-
ruby2_keywords(:try!)
|
31
|
+
ruby2_keywords(:try!)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -39,7 +39,7 @@ class Object
|
|
39
39
|
# :method: try
|
40
40
|
#
|
41
41
|
# :call-seq:
|
42
|
-
# try(*
|
42
|
+
# try(*args, &block)
|
43
43
|
#
|
44
44
|
# Invokes the public method whose name goes as first argument just like
|
45
45
|
# +public_send+ does, except that if the receiver does not respond to it the
|
@@ -104,7 +104,7 @@ class Object
|
|
104
104
|
# :method: try!
|
105
105
|
#
|
106
106
|
# :call-seq:
|
107
|
-
# try!(*
|
107
|
+
# try!(*args, &block)
|
108
108
|
#
|
109
109
|
# Same as #try, but raises a +NoMethodError+ exception if the receiver is
|
110
110
|
# not +nil+ and does not implement the tried method.
|
@@ -121,7 +121,7 @@ class Delegator
|
|
121
121
|
# :method: try
|
122
122
|
#
|
123
123
|
# :call-seq:
|
124
|
-
# try(
|
124
|
+
# try(*args, &block)
|
125
125
|
#
|
126
126
|
# See Object#try
|
127
127
|
|
@@ -129,7 +129,7 @@ class Delegator
|
|
129
129
|
# :method: try!
|
130
130
|
#
|
131
131
|
# :call-seq:
|
132
|
-
# try!(
|
132
|
+
# try!(*args, &block)
|
133
133
|
#
|
134
134
|
# See Object#try!
|
135
135
|
end
|
@@ -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
|
@@ -75,8 +75,27 @@ class Object
|
|
75
75
|
# end
|
76
76
|
# end
|
77
77
|
#
|
78
|
+
# When the block argument is omitted, the decorated Object instance is returned:
|
79
|
+
#
|
80
|
+
# module MyStyledHelpers
|
81
|
+
# def styled
|
82
|
+
# with_options style: "color: red;"
|
83
|
+
# end
|
84
|
+
# end
|
85
|
+
#
|
86
|
+
# # styled.link_to "I'm red", "/"
|
87
|
+
# # #=> <a href="/" style="color: red;">I'm red</a>
|
88
|
+
#
|
89
|
+
# # styled.button_tag "I'm red too!"
|
90
|
+
# # #=> <button style="color: red;">I'm red too!</button>
|
91
|
+
#
|
78
92
|
def with_options(options, &block)
|
79
93
|
option_merger = ActiveSupport::OptionMerger.new(self, options)
|
80
|
-
|
94
|
+
|
95
|
+
if block
|
96
|
+
block.arity.zero? ? option_merger.instance_eval(&block) : block.call(option_merger)
|
97
|
+
else
|
98
|
+
option_merger
|
99
|
+
end
|
81
100
|
end
|
82
101
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Pathname
|
4
|
+
# Returns the receiver if the named file exists otherwise returns +nil+.
|
5
|
+
# <tt>pathname.existence</tt> is equivalent to
|
6
|
+
#
|
7
|
+
# pathname.exist? ? pathname : nil
|
8
|
+
#
|
9
|
+
# For example, something like
|
10
|
+
#
|
11
|
+
# content = pathname.read if pathname.exist?
|
12
|
+
#
|
13
|
+
# becomes
|
14
|
+
#
|
15
|
+
# content = pathname.existence&.read
|
16
|
+
#
|
17
|
+
# @return [Pathname]
|
18
|
+
def existence
|
19
|
+
self if exist?
|
20
|
+
end
|
21
|
+
end
|
@@ -51,31 +51,6 @@ module ActiveSupport
|
|
51
51
|
super
|
52
52
|
end
|
53
53
|
end
|
54
|
-
|
55
|
-
# Extends the default Range#cover? to support range comparisons.
|
56
|
-
# (1..5).cover?(1..5) # => true
|
57
|
-
# (1..5).cover?(2..3) # => true
|
58
|
-
# (1..5).cover?(1...6) # => true
|
59
|
-
# (1..5).cover?(2..6) # => false
|
60
|
-
#
|
61
|
-
# The native Range#cover? behavior is untouched.
|
62
|
-
# ('a'..'f').cover?('c') # => true
|
63
|
-
# (5..9).cover?(11) # => false
|
64
|
-
#
|
65
|
-
# The given range must be fully bounded, with both start and end.
|
66
|
-
def cover?(value)
|
67
|
-
if value.is_a?(::Range)
|
68
|
-
is_backwards_op = value.exclude_end? ? :>= : :>
|
69
|
-
return false if value.begin && value.end && value.begin.public_send(is_backwards_op, value.end)
|
70
|
-
# 1...10 covers 1..9 but it does not cover 1..10.
|
71
|
-
# 1..10 covers 1...11 but it does not cover 1...12.
|
72
|
-
operator = exclude_end? && !value.exclude_end? ? :< : :<=
|
73
|
-
value_max = !exclude_end? && value.exclude_end? ? value.max : value.last
|
74
|
-
super(value.first) && (self.end.nil? || value_max.public_send(operator, last))
|
75
|
-
else
|
76
|
-
super
|
77
|
-
end
|
78
|
-
end
|
79
54
|
end
|
80
55
|
end
|
81
56
|
|
@@ -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.
|
10
|
+
"BETWEEN '#{start.to_formatted_s(:db)}' AND '#{stop.to_formatted_s(: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>.
|
18
|
+
#
|
17
19
|
# range = (1..100) # => 1..100
|
18
20
|
#
|
19
21
|
# range.to_s # => "1..100"
|
20
|
-
# range.
|
22
|
+
# range.to_formatted_s(:db) # => "BETWEEN '1' AND '100'"
|
21
23
|
#
|
22
24
|
# == Adding your own range formats to to_s
|
23
25
|
# You can add your own formats to the Range::RANGE_FORMATS hash.
|
24
26
|
# Use the format name as the hash key and a Proc instance.
|
25
27
|
#
|
26
28
|
# # config/initializers/range_formats.rb
|
27
|
-
# Range::RANGE_FORMATS[:short] = ->(start, stop) { "Between #{start.
|
28
|
-
def
|
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
31
|
if formatter = RANGE_FORMATS[format]
|
30
32
|
formatter.call(first, last)
|
31
33
|
else
|
32
|
-
|
34
|
+
to_s
|
33
35
|
end
|
34
36
|
end
|
35
|
-
|
36
|
-
alias_method :to_default_s, :to_s
|
37
|
-
alias_method :to_formatted_s, :to_s
|
37
|
+
alias_method :to_fs, :to_formatted_s
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
module DeprecatedRangeWithFormat # :nodoc:
|
5
|
+
NOT_SET = Object.new # :nodoc:
|
6
|
+
def to_s(format = NOT_SET)
|
7
|
+
if formatter = RangeWithFormat::RANGE_FORMATS[format]
|
8
|
+
ActiveSupport::Deprecation.warn(
|
9
|
+
"Range#to_s(#{format.inspect}) is deprecated. Please use Range#to_formatted_s(#{format.inspect}) instead."
|
10
|
+
)
|
11
|
+
formatter.call(first, last)
|
12
|
+
elsif format == NOT_SET
|
13
|
+
super()
|
14
|
+
else
|
15
|
+
ActiveSupport::Deprecation.warn(
|
16
|
+
"Range#to_s(#{format.inspect}) is deprecated. Please use Range#to_formatted_s(#{format.inspect}) instead."
|
17
|
+
)
|
18
|
+
super()
|
19
|
+
end
|
20
|
+
end
|
21
|
+
alias_method :to_default_s, :to_s
|
22
|
+
deprecate :to_default_s
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Range.prepend(ActiveSupport::DeprecatedRangeWithFormat)
|
@@ -1,28 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
require "active_support/deprecation"
|
5
|
-
|
6
|
-
module ActiveSupport
|
7
|
-
module IncludeTimeWithZone #:nodoc:
|
8
|
-
# Extends the default Range#include? to support ActiveSupport::TimeWithZone.
|
9
|
-
#
|
10
|
-
# (1.hour.ago..1.hour.from_now).include?(Time.current) # => true
|
11
|
-
#
|
12
|
-
def include?(value)
|
13
|
-
if self.begin.is_a?(TimeWithZone) || self.end.is_a?(TimeWithZone)
|
14
|
-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
15
|
-
Using `Range#include?` to check the inclusion of a value in
|
16
|
-
a date time range is deprecated.
|
17
|
-
It is recommended to use `Range#cover?` instead of `Range#include?` to
|
18
|
-
check the inclusion of a value in a date time range.
|
19
|
-
MSG
|
20
|
-
cover?(value)
|
21
|
-
else
|
22
|
-
super
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
3
|
+
# frozen_string_literal: true
|
27
4
|
|
28
|
-
|
5
|
+
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
6
|
+
`active_support/core_ext/range/include_time_with_zone` is deprecated and will be removed in Rails 7.1.
|
7
|
+
MSG
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "active_support/core_ext/range/conversions"
|
4
|
+
require "active_support/core_ext/range/deprecated_conversions" unless ENV["RAILS_DISABLE_DEPRECATED_TO_S_CONVERSION"]
|
4
5
|
require "active_support/core_ext/range/compare_range"
|
5
|
-
require "active_support/core_ext/range/include_time_with_zone"
|
6
6
|
require "active_support/core_ext/range/overlaps"
|
7
7
|
require "active_support/core_ext/range/each"
|
@@ -260,7 +260,7 @@ class String
|
|
260
260
|
# 'author_id'.humanize # => "Author"
|
261
261
|
# 'author_id'.humanize(capitalize: false) # => "author"
|
262
262
|
# '_id'.humanize # => "Id"
|
263
|
-
# 'author_id'.humanize(keep_id_suffix: true) # => "Author
|
263
|
+
# 'author_id'.humanize(keep_id_suffix: true) # => "Author id"
|
264
264
|
#
|
265
265
|
# See ActiveSupport::Inflector.humanize.
|
266
266
|
def humanize(capitalize: true, keep_id_suffix: false)
|
@@ -130,7 +130,7 @@ class Numeric
|
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
133
|
-
module ActiveSupport
|
133
|
+
module ActiveSupport # :nodoc:
|
134
134
|
class SafeBuffer < String
|
135
135
|
UNSAFE_STRING_METHODS = %w(
|
136
136
|
capitalize chomp chop delete delete_prefix delete_suffix
|
@@ -184,27 +184,30 @@ module ActiveSupport #:nodoc:
|
|
184
184
|
end
|
185
185
|
|
186
186
|
def concat(value)
|
187
|
-
|
187
|
+
unless value.nil?
|
188
|
+
super(implicit_html_escape_interpolated_argument(value))
|
189
|
+
end
|
190
|
+
self
|
188
191
|
end
|
189
192
|
alias << concat
|
190
193
|
|
191
194
|
def insert(index, value)
|
192
|
-
super(index,
|
195
|
+
super(index, implicit_html_escape_interpolated_argument(value))
|
193
196
|
end
|
194
197
|
|
195
198
|
def prepend(value)
|
196
|
-
super(
|
199
|
+
super(implicit_html_escape_interpolated_argument(value))
|
197
200
|
end
|
198
201
|
|
199
202
|
def replace(value)
|
200
|
-
super(
|
203
|
+
super(implicit_html_escape_interpolated_argument(value))
|
201
204
|
end
|
202
205
|
|
203
206
|
def []=(*args)
|
204
207
|
if args.length == 3
|
205
|
-
super(args[0], args[1],
|
208
|
+
super(args[0], args[1], implicit_html_escape_interpolated_argument(args[2]))
|
206
209
|
else
|
207
|
-
super(args[0],
|
210
|
+
super(args[0], implicit_html_escape_interpolated_argument(args[1]))
|
208
211
|
end
|
209
212
|
end
|
210
213
|
|
@@ -222,9 +225,9 @@ module ActiveSupport #:nodoc:
|
|
222
225
|
def %(args)
|
223
226
|
case args
|
224
227
|
when Hash
|
225
|
-
escaped_args = args.transform_values { |arg|
|
228
|
+
escaped_args = args.transform_values { |arg| explicit_html_escape_interpolated_argument(arg) }
|
226
229
|
else
|
227
|
-
escaped_args = Array(args).map { |arg|
|
230
|
+
escaped_args = Array(args).map { |arg| explicit_html_escape_interpolated_argument(arg) }
|
228
231
|
end
|
229
232
|
|
230
233
|
self.class.new(super(escaped_args))
|
@@ -262,39 +265,60 @@ module ActiveSupport #:nodoc:
|
|
262
265
|
end
|
263
266
|
|
264
267
|
UNSAFE_STRING_METHODS_WITH_BACKREF.each do |unsafe_method|
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
EOT
|
290
|
-
end
|
268
|
+
class_eval <<-EOT, __FILE__, __LINE__ + 1
|
269
|
+
def #{unsafe_method}(*args, &block) # def gsub(*args, &block)
|
270
|
+
if block # if block
|
271
|
+
to_str.#{unsafe_method}(*args) { |*params| # to_str.gsub(*args) { |*params|
|
272
|
+
set_block_back_references(block, $~) # set_block_back_references(block, $~)
|
273
|
+
block.call(*params) # block.call(*params)
|
274
|
+
} # }
|
275
|
+
else # else
|
276
|
+
to_str.#{unsafe_method}(*args) # to_str.gsub(*args)
|
277
|
+
end # end
|
278
|
+
end # end
|
279
|
+
|
280
|
+
def #{unsafe_method}!(*args, &block) # def gsub!(*args, &block)
|
281
|
+
@html_safe = false # @html_safe = false
|
282
|
+
if block # if block
|
283
|
+
super(*args) { |*params| # super(*args) { |*params|
|
284
|
+
set_block_back_references(block, $~) # set_block_back_references(block, $~)
|
285
|
+
block.call(*params) # block.call(*params)
|
286
|
+
} # }
|
287
|
+
else # else
|
288
|
+
super # super
|
289
|
+
end # end
|
290
|
+
end # end
|
291
|
+
EOT
|
291
292
|
end
|
292
293
|
|
293
294
|
private
|
294
|
-
def
|
295
|
+
def explicit_html_escape_interpolated_argument(arg)
|
295
296
|
(!html_safe? || arg.html_safe?) ? arg : CGI.escapeHTML(arg.to_s)
|
296
297
|
end
|
297
298
|
|
299
|
+
def implicit_html_escape_interpolated_argument(arg)
|
300
|
+
if !html_safe? || arg.html_safe?
|
301
|
+
arg
|
302
|
+
else
|
303
|
+
arg_string = begin
|
304
|
+
arg.to_str
|
305
|
+
rescue NoMethodError => error
|
306
|
+
if error.name == :to_str
|
307
|
+
str = arg.to_s
|
308
|
+
ActiveSupport::Deprecation.warn <<~MSG.squish
|
309
|
+
Implicit conversion of #{arg.class} into String by ActiveSupport::SafeBuffer
|
310
|
+
is deprecated and will be removed in Rails 7.1.
|
311
|
+
You must explicitly cast it to a String.
|
312
|
+
MSG
|
313
|
+
str
|
314
|
+
else
|
315
|
+
raise
|
316
|
+
end
|
317
|
+
end
|
318
|
+
CGI.escapeHTML(arg_string)
|
319
|
+
end
|
320
|
+
end
|
321
|
+
|
298
322
|
def set_block_back_references(block, match_data)
|
299
323
|
block.binding.eval("proc { |m| $~ = m }").call(match_data)
|
300
324
|
rescue ArgumentError
|
@@ -1,14 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Symbol
|
4
|
-
def start_with?(*prefixes)
|
5
|
-
to_s.start_with?(*prefixes)
|
6
|
-
end unless method_defined?(:start_with?)
|
7
|
-
|
8
|
-
def end_with?(*suffixes)
|
9
|
-
to_s.end_with?(*suffixes)
|
10
|
-
end unless method_defined?(:end_with?)
|
11
|
-
|
12
4
|
alias :starts_with? :start_with?
|
13
5
|
alias :ends_with? :end_with?
|
14
6
|
end
|
@@ -42,8 +42,8 @@ class Time
|
|
42
42
|
|
43
43
|
# Layers additional behavior on Time.at so that ActiveSupport::TimeWithZone and DateTime
|
44
44
|
# instances can be used when called with a single argument
|
45
|
-
def at_with_coercion(*args)
|
46
|
-
return at_without_coercion(*args) if args.size != 1
|
45
|
+
def at_with_coercion(*args, **kwargs)
|
46
|
+
return at_without_coercion(*args, **kwargs) if args.size != 1 || !kwargs.empty?
|
47
47
|
|
48
48
|
# Time.at can be called with a time or numerical value
|
49
49
|
time_or_number = args.first
|
@@ -56,7 +56,6 @@ class Time
|
|
56
56
|
at_without_coercion(time_or_number)
|
57
57
|
end
|
58
58
|
end
|
59
|
-
ruby2_keywords(:at_with_coercion) if respond_to?(:ruby2_keywords, true)
|
60
59
|
alias_method :at_without_coercion, :at
|
61
60
|
alias_method :at, :at_with_coercion
|
62
61
|
|
@@ -160,6 +159,8 @@ class Time
|
|
160
159
|
::Time.new(new_year, new_month, new_day, new_hour, new_min, new_sec, new_offset)
|
161
160
|
elsif utc?
|
162
161
|
::Time.utc(new_year, new_month, new_day, new_hour, new_min, new_sec)
|
162
|
+
elsif zone&.respond_to?(:utc_to_local)
|
163
|
+
::Time.new(new_year, new_month, new_day, new_hour, new_min, new_sec, zone)
|
163
164
|
elsif zone
|
164
165
|
::Time.local(new_year, new_month, new_day, new_hour, new_min, new_sec)
|
165
166
|
else
|
@@ -276,7 +277,7 @@ class Time
|
|
276
277
|
end
|
277
278
|
alias :at_end_of_minute :end_of_minute
|
278
279
|
|
279
|
-
def plus_with_duration(other)
|
280
|
+
def plus_with_duration(other) # :nodoc:
|
280
281
|
if ActiveSupport::Duration === other
|
281
282
|
other.since(self)
|
282
283
|
else
|
@@ -286,7 +287,7 @@ class Time
|
|
286
287
|
alias_method :plus_without_duration, :+
|
287
288
|
alias_method :+, :plus_with_duration
|
288
289
|
|
289
|
-
def minus_with_duration(other)
|
290
|
+
def minus_with_duration(other) # :nodoc:
|
290
291
|
if ActiveSupport::Duration === other
|
291
292
|
other.until(self)
|
292
293
|
else
|
@@ -304,7 +305,7 @@ class Time
|
|
304
305
|
other.is_a?(DateTime) ? to_f - other.to_f : minus_without_coercion(other)
|
305
306
|
end
|
306
307
|
alias_method :minus_without_coercion, :-
|
307
|
-
alias_method :-, :minus_with_coercion
|
308
|
+
alias_method :-, :minus_with_coercion # rubocop:disable Lint/DuplicateMethods
|
308
309
|
|
309
310
|
# Layers additional behavior on Time#<=> so that DateTime and ActiveSupport::TimeWithZone instances
|
310
311
|
# can be chronologically compared with a Time
|
@@ -27,12 +27,12 @@ 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>
|
30
|
+
# This method is aliased to <tt>to_fs</tt>.
|
31
31
|
#
|
32
32
|
# time = Time.now # => 2007-01-18 06:10:17 -06:00
|
33
33
|
#
|
34
34
|
# time.to_formatted_s(:time) # => "06:10"
|
35
|
-
# time.
|
35
|
+
# time.to_fs(:time) # => "06:10"
|
36
36
|
#
|
37
37
|
# time.to_formatted_s(:db) # => "2007-01-18 06:10:17"
|
38
38
|
# time.to_formatted_s(:number) # => "20070118061017"
|
@@ -54,11 +54,12 @@ class Time
|
|
54
54
|
if formatter = DATE_FORMATS[format]
|
55
55
|
formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
|
56
56
|
else
|
57
|
+
# Change to `to_s` when deprecation is gone. Also deprecate `to_default_s`.
|
57
58
|
to_default_s
|
58
59
|
end
|
59
60
|
end
|
61
|
+
alias_method :to_fs, :to_formatted_s
|
60
62
|
alias_method :to_default_s, :to_s
|
61
|
-
alias_method :to_s, :to_formatted_s
|
62
63
|
|
63
64
|
# Returns a formatted string of the offset from UTC, or an alternative
|
64
65
|
# string if the time zone is already UTC.
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "time"
|
4
|
+
|
5
|
+
class Time
|
6
|
+
NOT_SET = Object.new # :nodoc:
|
7
|
+
def to_s(format = NOT_SET) # :nodoc:
|
8
|
+
if formatter = DATE_FORMATS[format]
|
9
|
+
ActiveSupport::Deprecation.warn(
|
10
|
+
"Time#to_s(#{format.inspect}) is deprecated. Please use Time#to_formatted_s(#{format.inspect}) instead."
|
11
|
+
)
|
12
|
+
formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
|
13
|
+
elsif format == NOT_SET
|
14
|
+
to_default_s
|
15
|
+
else
|
16
|
+
ActiveSupport::Deprecation.warn(
|
17
|
+
"Time#to_s(#{format.inspect}) is deprecated. Please use Time#to_formatted_s(#{format.inspect}) instead."
|
18
|
+
)
|
19
|
+
to_default_s
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -12,7 +12,7 @@ class Time
|
|
12
12
|
# Returns the TimeZone for the current request, if this has been set (via Time.zone=).
|
13
13
|
# If <tt>Time.zone</tt> has not been set for the current request, returns the TimeZone specified in <tt>config.time_zone</tt>.
|
14
14
|
def zone
|
15
|
-
|
15
|
+
::ActiveSupport::IsolatedExecutionState[:time_zone] || zone_default
|
16
16
|
end
|
17
17
|
|
18
18
|
# Sets <tt>Time.zone</tt> to a TimeZone object for the current request/thread.
|
@@ -39,7 +39,7 @@ class Time
|
|
39
39
|
# end
|
40
40
|
# end
|
41
41
|
def zone=(time_zone)
|
42
|
-
|
42
|
+
::ActiveSupport::IsolatedExecutionState[:time_zone] = find_zone!(time_zone)
|
43
43
|
end
|
44
44
|
|
45
45
|
# Allows override of <tt>Time.zone</tt> locally inside supplied block;
|
@@ -80,24 +80,9 @@ class Time
|
|
80
80
|
# Time.find_zone! false # => false
|
81
81
|
# Time.find_zone! "NOT-A-TIMEZONE" # => ArgumentError: Invalid Timezone: NOT-A-TIMEZONE
|
82
82
|
def find_zone!(time_zone)
|
83
|
-
|
84
|
-
time_zone
|
85
|
-
else
|
86
|
-
# Look up the timezone based on the identifier (unless we've been
|
87
|
-
# passed a TZInfo::Timezone)
|
88
|
-
unless time_zone.respond_to?(:period_for_local)
|
89
|
-
time_zone = ActiveSupport::TimeZone[time_zone] || TZInfo::Timezone.get(time_zone)
|
90
|
-
end
|
83
|
+
return time_zone unless time_zone
|
91
84
|
|
92
|
-
|
93
|
-
if time_zone.is_a?(ActiveSupport::TimeZone)
|
94
|
-
time_zone
|
95
|
-
else
|
96
|
-
ActiveSupport::TimeZone.create(time_zone.name, nil, time_zone)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
rescue TZInfo::InvalidTimezoneIdentifier
|
100
|
-
raise ArgumentError, "Invalid Timezone: #{time_zone}"
|
85
|
+
ActiveSupport::TimeZone[time_zone] || raise(ArgumentError, "Invalid Timezone: #{time_zone}")
|
101
86
|
end
|
102
87
|
|
103
88
|
# Returns a TimeZone instance matching the time zone provided.
|
@@ -4,4 +4,5 @@ require "active_support/core_ext/time/acts_like"
|
|
4
4
|
require "active_support/core_ext/time/calculations"
|
5
5
|
require "active_support/core_ext/time/compatibility"
|
6
6
|
require "active_support/core_ext/time/conversions"
|
7
|
+
require "active_support/core_ext/time/deprecated_conversions" unless ENV["RAILS_DISABLE_DEPRECATED_TO_S_CONVERSION"]
|
7
8
|
require "active_support/core_ext/time/zones"
|