activesupport 6.1.4.1 → 7.0.8.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +325 -395
- data/MIT-LICENSE +1 -1
- data/README.rdoc +2 -2
- data/lib/active_support/actionable_error.rb +1 -1
- data/lib/active_support/array_inquirer.rb +0 -2
- data/lib/active_support/backtrace_cleaner.rb +2 -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 +148 -37
- data/lib/active_support/cache/memory_store.rb +24 -16
- data/lib/active_support/cache/null_store.rb +10 -2
- data/lib/active_support/cache/redis_cache_store.rb +68 -85
- data/lib/active_support/cache/strategy/local_cache.rb +38 -61
- data/lib/active_support/cache.rb +299 -147
- data/lib/active_support/callbacks.rb +184 -85
- 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 +8 -5
- 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 +13 -12
- 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/inquiry.rb +2 -2
- 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 +24 -9
- data/lib/active_support/core_ext/date/conversions.rb +14 -14
- data/lib/active_support/core_ext/date/deprecated_conversions.rb +40 -0
- data/lib/active_support/core_ext/date.rb +1 -0
- data/lib/active_support/core_ext/date_and_time/calculations.rb +4 -4
- 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/calculations.rb +4 -0
- data/lib/active_support/core_ext/date_time/conversions.rb +13 -13
- data/lib/active_support/core_ext/date_time/deprecated_conversions.rb +36 -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 +112 -38
- data/lib/active_support/core_ext/file/atomic.rb +3 -1
- data/lib/active_support/core_ext/hash/conversions.rb +0 -1
- data/lib/active_support/core_ext/hash/deep_transform_values.rb +3 -3
- data/lib/active_support/core_ext/hash/indifferent_access.rb +3 -3
- data/lib/active_support/core_ext/hash/keys.rb +4 -4
- data/lib/active_support/core_ext/integer/inflections.rb +12 -12
- data/lib/active_support/core_ext/kernel/reporting.rb +4 -4
- data/lib/active_support/core_ext/kernel/singleton_class.rb +1 -1
- 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 +80 -77
- 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 +15 -4
- data/lib/active_support/core_ext/object/json.rb +30 -25
- data/lib/active_support/core_ext/object/to_query.rb +2 -4
- data/lib/active_support/core_ext/object/try.rb +20 -20
- data/lib/active_support/core_ext/object/with_options.rb +21 -2
- 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 +36 -0
- data/lib/active_support/core_ext/range/each.rb +1 -1
- data/lib/active_support/core_ext/range/include_time_with_zone.rb +3 -26
- data/lib/active_support/core_ext/range/overlaps.rb +1 -1
- data/lib/active_support/core_ext/range.rb +1 -1
- data/lib/active_support/core_ext/securerandom.rb +1 -1
- data/lib/active_support/core_ext/string/conversions.rb +2 -2
- data/lib/active_support/core_ext/string/filters.rb +1 -1
- data/lib/active_support/core_ext/string/inflections.rb +1 -5
- data/lib/active_support/core_ext/string/inquiry.rb +1 -1
- data/lib/active_support/core_ext/string/output_safety.rb +94 -38
- data/lib/active_support/core_ext/symbol/starts_ends_with.rb +0 -8
- data/lib/active_support/core_ext/time/calculations.rb +13 -8
- data/lib/active_support/core_ext/time/conversions.rb +13 -12
- data/lib/active_support/core_ext/time/deprecated_conversions.rb +73 -0
- data/lib/active_support/core_ext/time/zones.rb +10 -26
- 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 +8 -5
- data/lib/active_support/deprecation/disallowed.rb +3 -3
- data/lib/active_support/deprecation/method_wrappers.rb +3 -3
- data/lib/active_support/deprecation/proxy_wrappers.rb +2 -2
- data/lib/active_support/deprecation.rb +2 -2
- 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 +45 -3
- data/lib/active_support/encrypted_file.rb +21 -10
- 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 +20 -7
- 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 +43 -21
- 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 +5 -5
- 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 +29 -55
- data/lib/active_support/inflector/transliterate.rb +1 -1
- data/lib/active_support/isolated_execution_state.rb +72 -0
- data/lib/active_support/json/encoding.rb +3 -3
- data/lib/active_support/key_generator.rb +22 -5
- data/lib/active_support/lazy_load_hooks.rb +28 -4
- data/lib/active_support/locale/en.yml +1 -1
- data/lib/active_support/log_subscriber/test_helper.rb +2 -2
- data/lib/active_support/log_subscriber.rb +15 -5
- data/lib/active_support/logger_thread_safe_level.rb +4 -13
- data/lib/active_support/message_encryptor.rb +12 -6
- 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 +23 -23
- 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 +4 -5
- data/lib/active_support/option_merger.rb +10 -18
- data/lib/active_support/ordered_hash.rb +1 -1
- data/lib/active_support/ordered_options.rb +1 -1
- data/lib/active_support/parameter_filter.rb +20 -11
- data/lib/active_support/per_thread_registry.rb +5 -0
- data/lib/active_support/railtie.rb +69 -19
- data/lib/active_support/reloader.rb +1 -1
- data/lib/active_support/rescuable.rb +12 -12
- data/lib/active_support/ruby_features.rb +7 -0
- data/lib/active_support/secure_compare_rotator.rb +2 -2
- 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 +13 -21
- data/lib/active_support/testing/assertions.rb +36 -6
- data/lib/active_support/testing/deprecation.rb +52 -1
- data/lib/active_support/testing/isolation.rb +30 -29
- 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 +43 -22
- data/lib/active_support/values/time_zone.rb +35 -14
- data/lib/active_support/version.rb +1 -1
- 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 +26 -23
- data/lib/active_support/core_ext/marshal.rb +0 -26
- data/lib/active_support/dependencies/zeitwerk_integration.rb +0 -117
@@ -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
|
|
@@ -127,8 +126,8 @@ class Time
|
|
127
126
|
# Returns a new Time where one or more of the elements have been changed according
|
128
127
|
# to the +options+ parameter. The time options (<tt>:hour</tt>, <tt>:min</tt>,
|
129
128
|
# <tt>:sec</tt>, <tt>:usec</tt>, <tt>:nsec</tt>) reset cascadingly, so if only
|
130
|
-
# the hour is passed, then minute, sec, usec and nsec is set to 0. If the hour
|
131
|
-
# and minute is passed, then sec, usec and nsec is set to 0. The +options+ parameter
|
129
|
+
# the hour is passed, then minute, sec, usec, and nsec is set to 0. If the hour
|
130
|
+
# and minute is passed, then sec, usec, and nsec is set to 0. The +options+ parameter
|
132
131
|
# takes a hash with any of these keys: <tt>:year</tt>, <tt>:month</tt>, <tt>:day</tt>,
|
133
132
|
# <tt>:hour</tt>, <tt>:min</tt>, <tt>:sec</tt>, <tt>:usec</tt>, <tt>:nsec</tt>,
|
134
133
|
# <tt>:offset</tt>. Pass either <tt>:usec</tt> or <tt>:nsec</tt>, not both.
|
@@ -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
|
@@ -178,6 +179,10 @@ class Time
|
|
178
179
|
# Time.new(2015, 8, 1, 14, 35, 0).advance(hours: 1) # => 2015-08-01 15:35:00 -0700
|
179
180
|
# Time.new(2015, 8, 1, 14, 35, 0).advance(days: 1) # => 2015-08-02 14:35:00 -0700
|
180
181
|
# Time.new(2015, 8, 1, 14, 35, 0).advance(weeks: 1) # => 2015-08-08 14:35:00 -0700
|
182
|
+
#
|
183
|
+
# Just like Date#advance, increments are applied in order of time units from
|
184
|
+
# largest to smallest. This order can affect the result around the end of a
|
185
|
+
# month.
|
181
186
|
def advance(options)
|
182
187
|
unless options[:weeks].nil?
|
183
188
|
options[:weeks], partial_weeks = options[:weeks].divmod(1)
|
@@ -276,7 +281,7 @@ class Time
|
|
276
281
|
end
|
277
282
|
alias :at_end_of_minute :end_of_minute
|
278
283
|
|
279
|
-
def plus_with_duration(other)
|
284
|
+
def plus_with_duration(other) # :nodoc:
|
280
285
|
if ActiveSupport::Duration === other
|
281
286
|
other.since(self)
|
282
287
|
else
|
@@ -286,7 +291,7 @@ class Time
|
|
286
291
|
alias_method :plus_without_duration, :+
|
287
292
|
alias_method :+, :plus_with_duration
|
288
293
|
|
289
|
-
def minus_with_duration(other)
|
294
|
+
def minus_with_duration(other) # :nodoc:
|
290
295
|
if ActiveSupport::Duration === other
|
291
296
|
other.until(self)
|
292
297
|
else
|
@@ -304,7 +309,7 @@ class Time
|
|
304
309
|
other.is_a?(DateTime) ? to_f - other.to_f : minus_without_coercion(other)
|
305
310
|
end
|
306
311
|
alias_method :minus_without_coercion, :-
|
307
|
-
alias_method :-, :minus_with_coercion
|
312
|
+
alias_method :-, :minus_with_coercion # rubocop:disable Lint/DuplicateMethods
|
308
313
|
|
309
314
|
# Layers additional behavior on Time#<=> so that DateTime and ActiveSupport::TimeWithZone instances
|
310
315
|
# can be chronologically compared with a Time
|
@@ -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>
|
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_fs(:time) # => "06:10"
|
34
35
|
# time.to_formatted_s(:time) # => "06:10"
|
35
|
-
# time.to_s(:time) # => "06:10"
|
36
36
|
#
|
37
|
-
# time.
|
38
|
-
# time.
|
39
|
-
# time.
|
40
|
-
# time.
|
41
|
-
# time.
|
42
|
-
# time.
|
43
|
-
# time.
|
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 +
|
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,15 +50,16 @@ 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
|
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
|
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_formatted_s, :to_fs
|
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,73 @@
|
|
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_fs(#{format.inspect}) instead."
|
11
|
+
)
|
12
|
+
formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
|
13
|
+
elsif format == NOT_SET
|
14
|
+
if formatter = ::Time::DATE_FORMATS[:default]
|
15
|
+
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
16
|
+
Using a :default format for Time#to_s is deprecated. Please use Time#to_fs instead. If you fixed all places
|
17
|
+
inside your application that you see this deprecation, you can set
|
18
|
+
`ENV['RAILS_DISABLE_DEPRECATED_TO_S_CONVERSION']` to `"true"` in the `config/application.rb` file before
|
19
|
+
the `Bundler.require` call to fix all the callers outside of your application.
|
20
|
+
MSG
|
21
|
+
if formatter.respond_to?(:call)
|
22
|
+
formatter.call(self).to_s
|
23
|
+
else
|
24
|
+
strftime(formatter)
|
25
|
+
end
|
26
|
+
else
|
27
|
+
to_default_s
|
28
|
+
end
|
29
|
+
else
|
30
|
+
ActiveSupport::Deprecation.warn(
|
31
|
+
"Time#to_s(#{format.inspect}) is deprecated. Please use Time#to_fs(#{format.inspect}) instead."
|
32
|
+
)
|
33
|
+
to_default_s
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
module ActiveSupport
|
39
|
+
class TimeWithZone
|
40
|
+
NOT_SET = Object.new # :nodoc:
|
41
|
+
|
42
|
+
def to_s(format = NOT_SET) # :nodoc:
|
43
|
+
if format == :db
|
44
|
+
ActiveSupport::Deprecation.warn(
|
45
|
+
"TimeWithZone#to_s(:db) is deprecated. Please use TimeWithZone#to_fs(:db) instead."
|
46
|
+
)
|
47
|
+
utc.to_fs(format)
|
48
|
+
elsif formatter = ::Time::DATE_FORMATS[format]
|
49
|
+
ActiveSupport::Deprecation.warn(
|
50
|
+
"TimeWithZone#to_s(#{format.inspect}) is deprecated. Please use TimeWithZone#to_fs(#{format.inspect}) instead."
|
51
|
+
)
|
52
|
+
formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
|
53
|
+
elsif format == NOT_SET
|
54
|
+
if formatter = ::Time::DATE_FORMATS[:default]
|
55
|
+
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
56
|
+
Using a :default format for TimeWithZone#to_s is deprecated. Please use TimeWithZone#to_fs instead.
|
57
|
+
If you fixed all places inside your application that you see this deprecation, you can set
|
58
|
+
`ENV['RAILS_DISABLE_DEPRECATED_TO_S_CONVERSION']` to `"true"` in the `config/application.rb` file before
|
59
|
+
the `Bundler.require` call to fix all the callers outside of your application.
|
60
|
+
MSG
|
61
|
+
formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
|
62
|
+
else
|
63
|
+
"#{time.strftime("%Y-%m-%d %H:%M:%S")} #{formatted_offset(false, 'UTC')}" # mimicking Ruby Time#to_s format
|
64
|
+
end
|
65
|
+
else
|
66
|
+
ActiveSupport::Deprecation.warn(
|
67
|
+
"TimeWithZone#to_s(#{format.inspect}) is deprecated. Please use TimeWithZone#to_fs(#{format.inspect}) instead."
|
68
|
+
)
|
69
|
+
"#{time.strftime("%Y-%m-%d %H:%M:%S")} #{formatted_offset(false, 'UTC')}" # mimicking Ruby Time#to_s format
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
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.
|
@@ -21,8 +21,8 @@ class Time
|
|
21
21
|
#
|
22
22
|
# * A Rails TimeZone object.
|
23
23
|
# * An identifier for a Rails TimeZone object (e.g., "Eastern Time (US & Canada)", <tt>-5.hours</tt>).
|
24
|
-
# * A TZInfo::Timezone object.
|
25
|
-
# * An identifier for a TZInfo::Timezone object (e.g., "America/New_York").
|
24
|
+
# * A <tt>TZInfo::Timezone</tt> object.
|
25
|
+
# * An identifier for a <tt>TZInfo::Timezone</tt> object (e.g., "America/New_York").
|
26
26
|
#
|
27
27
|
# Here's an example of how you might set <tt>Time.zone</tt> on a per request basis and reset it when the request is done.
|
28
28
|
# <tt>current_user.time_zone</tt> just needs to return a string identifying the user's preferred time zone:
|
@@ -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;
|
@@ -49,13 +49,12 @@ class Time
|
|
49
49
|
# around_action :set_time_zone
|
50
50
|
#
|
51
51
|
# private
|
52
|
-
#
|
53
|
-
#
|
54
|
-
#
|
55
|
-
# end
|
52
|
+
# def set_time_zone
|
53
|
+
# Time.use_zone(current_user.timezone) { yield }
|
54
|
+
# end
|
56
55
|
# end
|
57
56
|
#
|
58
|
-
# NOTE: This won't affect any
|
57
|
+
# NOTE: This won't affect any ActiveSupport::TimeWithZone
|
59
58
|
# objects that have already been created, e.g. any model timestamp
|
60
59
|
# attributes that have been read before the block will remain in
|
61
60
|
# the application's default timezone.
|
@@ -80,24 +79,9 @@ class Time
|
|
80
79
|
# Time.find_zone! false # => false
|
81
80
|
# Time.find_zone! "NOT-A-TIMEZONE" # => ArgumentError: Invalid Timezone: NOT-A-TIMEZONE
|
82
81
|
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
|
82
|
+
return time_zone unless time_zone
|
91
83
|
|
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}"
|
84
|
+
ActiveSupport::TimeZone[time_zone] || raise(ArgumentError, "Invalid Timezone: #{time_zone}")
|
101
85
|
end
|
102
86
|
|
103
87
|
# 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"
|
@@ -1,29 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
require "active_support/core_ext/module/redefine_method"
|
7
|
-
URI::Parser.class_eval do
|
8
|
-
silence_redefinition_of_method :unescape
|
9
|
-
def unescape(str, escaped = /%[a-fA-F\d]{2}/)
|
10
|
-
# TODO: Are we actually sure that ASCII == UTF-8?
|
11
|
-
# YK: My initial experiments say yes, but let's be sure please
|
12
|
-
enc = str.encoding
|
13
|
-
enc = Encoding::UTF_8 if enc == Encoding::US_ASCII
|
14
|
-
str.dup.force_encoding(Encoding::ASCII_8BIT).gsub(escaped) { |match| [match[1, 2].hex].pack("C") }.force_encoding(enc)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
module URI
|
20
|
-
class << self
|
21
|
-
def parser
|
22
|
-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
23
|
-
URI.parser is deprecated and will be removed in Rails 6.2.
|
24
|
-
Use `URI::DEFAULT_PARSER` instead.
|
25
|
-
MSG
|
26
|
-
URI::DEFAULT_PARSER
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
3
|
+
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
4
|
+
`active_support/core_ext/uri` is deprecated and will be removed in Rails 7.1.
|
5
|
+
MSG
|
@@ -98,25 +98,37 @@ module ActiveSupport
|
|
98
98
|
|
99
99
|
# Declares one or more attributes that will be given both class and instance accessor methods.
|
100
100
|
def attribute(*names)
|
101
|
-
generated_attribute_methods
|
101
|
+
ActiveSupport::CodeGenerator.batch(generated_attribute_methods, __FILE__, __LINE__) do |owner|
|
102
102
|
names.each do |name|
|
103
|
-
|
104
|
-
|
103
|
+
owner.define_cached_method(name, namespace: :current_attributes) do |batch|
|
104
|
+
batch <<
|
105
|
+
"def #{name}" <<
|
106
|
+
"attributes[:#{name}]" <<
|
107
|
+
"end"
|
105
108
|
end
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
+
owner.define_cached_method("#{name}=", namespace: :current_attributes) do |batch|
|
110
|
+
batch <<
|
111
|
+
"def #{name}=(value)" <<
|
112
|
+
"attributes[:#{name}] = value" <<
|
113
|
+
"end"
|
109
114
|
end
|
110
115
|
end
|
111
116
|
end
|
112
117
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
118
|
+
ActiveSupport::CodeGenerator.batch(singleton_class, __FILE__, __LINE__) do |owner|
|
119
|
+
names.each do |name|
|
120
|
+
owner.define_cached_method(name, namespace: :current_attributes_delegation) do |batch|
|
121
|
+
batch <<
|
122
|
+
"def #{name}" <<
|
123
|
+
"instance.#{name}" <<
|
124
|
+
"end"
|
125
|
+
end
|
126
|
+
owner.define_cached_method("#{name}=", namespace: :current_attributes_delegation) do |batch|
|
127
|
+
batch <<
|
128
|
+
"def #{name}=(value)" <<
|
129
|
+
"instance.#{name} = value" <<
|
130
|
+
"end"
|
131
|
+
end
|
120
132
|
end
|
121
133
|
end
|
122
134
|
end
|
@@ -149,7 +161,7 @@ module ActiveSupport
|
|
149
161
|
end
|
150
162
|
|
151
163
|
def current_instances
|
152
|
-
|
164
|
+
IsolatedExecutionState[:current_attributes_instances] ||= {}
|
153
165
|
end
|
154
166
|
|
155
167
|
def current_instances_key
|
@@ -164,6 +176,11 @@ module ActiveSupport
|
|
164
176
|
|
165
177
|
send(name, *args, &block)
|
166
178
|
end
|
179
|
+
ruby2_keywords(:method_missing)
|
180
|
+
|
181
|
+
def respond_to_missing?(name, _)
|
182
|
+
super || instance.respond_to?(name)
|
183
|
+
end
|
167
184
|
end
|
168
185
|
|
169
186
|
attr_accessor :attributes
|
@@ -2,23 +2,19 @@
|
|
2
2
|
|
3
3
|
require "active_support/concurrency/share_lock"
|
4
4
|
|
5
|
-
module ActiveSupport
|
6
|
-
module Dependencies
|
5
|
+
module ActiveSupport # :nodoc:
|
6
|
+
module Dependencies # :nodoc:
|
7
7
|
class Interlock
|
8
8
|
def initialize # :nodoc:
|
9
9
|
@lock = ActiveSupport::Concurrency::ShareLock.new
|
10
10
|
end
|
11
11
|
|
12
|
-
def loading
|
13
|
-
@lock.exclusive(purpose: :load, compatible: [:load], after_compatible: [:load])
|
14
|
-
yield
|
15
|
-
end
|
12
|
+
def loading(&block)
|
13
|
+
@lock.exclusive(purpose: :load, compatible: [:load], after_compatible: [:load], &block)
|
16
14
|
end
|
17
15
|
|
18
|
-
def unloading
|
19
|
-
@lock.exclusive(purpose: :unload, compatible: [:load, :unload], after_compatible: [:load, :unload])
|
20
|
-
yield
|
21
|
-
end
|
16
|
+
def unloading(&block)
|
17
|
+
@lock.exclusive(purpose: :unload, compatible: [:load, :unload], after_compatible: [:load, :unload], &block)
|
22
18
|
end
|
23
19
|
|
24
20
|
def start_unloading
|
@@ -37,16 +33,12 @@ module ActiveSupport #:nodoc:
|
|
37
33
|
@lock.stop_sharing
|
38
34
|
end
|
39
35
|
|
40
|
-
def running
|
41
|
-
@lock.sharing
|
42
|
-
yield
|
43
|
-
end
|
36
|
+
def running(&block)
|
37
|
+
@lock.sharing(&block)
|
44
38
|
end
|
45
39
|
|
46
|
-
def permit_concurrent_loads
|
47
|
-
@lock.yield_shares(compatible: [:load])
|
48
|
-
yield
|
49
|
-
end
|
40
|
+
def permit_concurrent_loads(&block)
|
41
|
+
@lock.yield_shares(compatible: [:load], &block)
|
50
42
|
end
|
51
43
|
|
52
44
|
def raw_state(&block) # :nodoc:
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveSupport::Dependencies::RequireDependency
|
4
|
+
# <b>Warning:</b> This method is obsolete. The semantics of the autoloader
|
5
|
+
# match Ruby's and you do not need to be defensive with load order anymore.
|
6
|
+
# Just refer to classes and modules normally.
|
7
|
+
#
|
8
|
+
# Engines that do not control the mode in which their parent application runs
|
9
|
+
# should call +require_dependency+ where needed in case the runtime mode is
|
10
|
+
# +:classic+.
|
11
|
+
def require_dependency(filename)
|
12
|
+
filename = filename.to_path if filename.respond_to?(:to_path)
|
13
|
+
|
14
|
+
unless filename.is_a?(String)
|
15
|
+
raise ArgumentError, "the file name must be either a String or implement #to_path -- you passed #{filename.inspect}"
|
16
|
+
end
|
17
|
+
|
18
|
+
if abspath = ActiveSupport::Dependencies.search_for_file(filename)
|
19
|
+
require abspath
|
20
|
+
else
|
21
|
+
require filename
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# We could define require_dependency in Object directly, but a module makes
|
26
|
+
# the extension apparent if you list ancestors.
|
27
|
+
Object.prepend(self)
|
28
|
+
end
|