activesupport 5.2.4 → 6.0.0
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 +331 -396
- data/MIT-LICENSE +1 -1
- data/README.rdoc +3 -2
- data/lib/active_support.rb +2 -1
- data/lib/active_support/actionable_error.rb +48 -0
- data/lib/active_support/backtrace_cleaner.rb +28 -1
- data/lib/active_support/cache.rb +45 -23
- data/lib/active_support/cache/file_store.rb +22 -22
- data/lib/active_support/cache/mem_cache_store.rb +5 -0
- data/lib/active_support/cache/memory_store.rb +7 -2
- data/lib/active_support/cache/null_store.rb +5 -0
- data/lib/active_support/cache/redis_cache_store.rb +36 -9
- data/lib/active_support/callbacks.rb +16 -5
- data/lib/active_support/concern.rb +24 -1
- data/lib/active_support/configurable.rb +7 -11
- data/lib/active_support/core_ext/array.rb +1 -1
- data/lib/active_support/core_ext/array/access.rb +18 -6
- data/lib/active_support/core_ext/array/extract.rb +21 -0
- data/lib/active_support/core_ext/array/prepend_and_append.rb +2 -6
- data/lib/active_support/core_ext/class/attribute.rb +11 -16
- data/lib/active_support/core_ext/class/subclasses.rb +1 -1
- data/lib/active_support/core_ext/date/calculations.rb +6 -5
- data/lib/active_support/core_ext/date_and_time/calculations.rb +24 -47
- data/lib/active_support/core_ext/date_time/calculations.rb +1 -1
- data/lib/active_support/core_ext/enumerable.rb +97 -73
- data/lib/active_support/core_ext/hash.rb +1 -2
- data/lib/active_support/core_ext/hash/compact.rb +2 -26
- data/lib/active_support/core_ext/hash/deep_transform_values.rb +46 -0
- data/lib/active_support/core_ext/hash/except.rb +1 -1
- data/lib/active_support/core_ext/hash/keys.rb +0 -29
- data/lib/active_support/core_ext/hash/slice.rb +3 -25
- data/lib/active_support/core_ext/hash/transform_values.rb +2 -29
- data/lib/active_support/core_ext/integer/multiple.rb +1 -1
- data/lib/active_support/core_ext/kernel.rb +0 -1
- data/lib/active_support/core_ext/load_error.rb +1 -1
- data/lib/active_support/core_ext/module.rb +0 -1
- data/lib/active_support/core_ext/module/attribute_accessors.rb +7 -10
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +13 -19
- data/lib/active_support/core_ext/module/delegation.rb +33 -7
- data/lib/active_support/core_ext/module/introspection.rb +37 -13
- data/lib/active_support/core_ext/module/reachable.rb +1 -6
- data/lib/active_support/core_ext/module/redefine_method.rb +8 -17
- data/lib/active_support/core_ext/numeric.rb +0 -1
- data/lib/active_support/core_ext/numeric/conversions.rb +124 -128
- data/lib/active_support/core_ext/numeric/inquiry.rb +2 -25
- data/lib/active_support/core_ext/object/blank.rb +1 -2
- data/lib/active_support/core_ext/object/duplicable.rb +7 -114
- data/lib/active_support/core_ext/object/json.rb +1 -0
- data/lib/active_support/core_ext/object/try.rb +15 -7
- data/lib/active_support/core_ext/object/with_options.rb +1 -1
- data/lib/active_support/core_ext/range/compare_range.rb +22 -13
- data/lib/active_support/core_ext/range/conversions.rb +31 -29
- data/lib/active_support/core_ext/range/include_range.rb +6 -0
- data/lib/active_support/core_ext/regexp.rb +0 -4
- data/lib/active_support/core_ext/securerandom.rb +23 -3
- data/lib/active_support/core_ext/string/access.rb +8 -0
- data/lib/active_support/core_ext/string/filters.rb +42 -1
- data/lib/active_support/core_ext/string/inflections.rb +7 -2
- data/lib/active_support/core_ext/string/multibyte.rb +4 -3
- data/lib/active_support/core_ext/string/output_safety.rb +61 -5
- data/lib/active_support/core_ext/string/strip.rb +3 -1
- data/lib/active_support/core_ext/time/calculations.rb +31 -2
- data/lib/active_support/core_ext/uri.rb +1 -0
- data/lib/active_support/current_attributes.rb +8 -0
- data/lib/active_support/dependencies.rb +69 -16
- data/lib/active_support/dependencies/zeitwerk_integration.rb +110 -0
- data/lib/active_support/deprecation.rb +1 -1
- data/lib/active_support/deprecation/behaviors.rb +1 -1
- data/lib/active_support/deprecation/method_wrappers.rb +8 -20
- data/lib/active_support/deprecation/proxy_wrappers.rb +24 -5
- data/lib/active_support/descendants_tracker.rb +56 -9
- data/lib/active_support/duration.rb +4 -3
- data/lib/active_support/duration/iso8601_parser.rb +2 -3
- data/lib/active_support/duration/iso8601_serializer.rb +3 -4
- data/lib/active_support/encrypted_configuration.rb +0 -4
- data/lib/active_support/encrypted_file.rb +2 -1
- data/lib/active_support/evented_file_update_checker.rb +39 -9
- data/lib/active_support/execution_wrapper.rb +1 -0
- data/lib/active_support/gem_version.rb +3 -3
- data/lib/active_support/hash_with_indifferent_access.rb +22 -18
- data/lib/active_support/i18n.rb +1 -0
- data/lib/active_support/i18n_railtie.rb +9 -1
- data/lib/active_support/inflector/inflections.rb +1 -4
- data/lib/active_support/inflector/methods.rb +15 -27
- data/lib/active_support/inflector/transliterate.rb +47 -18
- data/lib/active_support/json/decoding.rb +23 -23
- data/lib/active_support/json/encoding.rb +6 -2
- data/lib/active_support/key_generator.rb +0 -32
- data/lib/active_support/lazy_load_hooks.rb +5 -1
- data/lib/active_support/locale/en.rb +31 -0
- data/lib/active_support/log_subscriber.rb +31 -8
- data/lib/active_support/logger.rb +0 -15
- data/lib/active_support/logger_silence.rb +28 -12
- data/lib/active_support/logger_thread_safe_level.rb +26 -4
- data/lib/active_support/message_encryptor.rb +3 -5
- data/lib/active_support/message_verifier.rb +3 -3
- data/lib/active_support/multibyte/chars.rb +29 -48
- data/lib/active_support/multibyte/unicode.rb +44 -281
- data/lib/active_support/notifications.rb +41 -4
- data/lib/active_support/notifications/fanout.rb +98 -13
- data/lib/active_support/notifications/instrumenter.rb +79 -8
- data/lib/active_support/number_helper.rb +7 -0
- data/lib/active_support/number_helper/number_to_currency_converter.rb +2 -2
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +3 -1
- data/lib/active_support/number_helper/number_to_human_converter.rb +3 -1
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +3 -1
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +3 -1
- data/lib/active_support/number_helper/number_to_phone_converter.rb +2 -0
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +5 -3
- data/lib/active_support/ordered_options.rb +1 -1
- data/lib/active_support/parameter_filter.rb +129 -0
- data/lib/active_support/rails.rb +0 -6
- data/lib/active_support/reloader.rb +4 -5
- data/lib/active_support/security_utils.rb +1 -1
- data/lib/active_support/subscriber.rb +65 -26
- data/lib/active_support/tagged_logging.rb +13 -4
- data/lib/active_support/test_case.rb +91 -0
- data/lib/active_support/testing/assertions.rb +15 -1
- data/lib/active_support/testing/deprecation.rb +0 -1
- data/lib/active_support/testing/file_fixtures.rb +2 -0
- data/lib/active_support/testing/isolation.rb +2 -2
- data/lib/active_support/testing/method_call_assertions.rb +28 -1
- data/lib/active_support/testing/parallelization.rb +128 -0
- data/lib/active_support/testing/stream.rb +1 -1
- data/lib/active_support/testing/time_helpers.rb +7 -7
- data/lib/active_support/time_with_zone.rb +15 -5
- data/lib/active_support/values/time_zone.rb +12 -7
- data/lib/active_support/xml_mini.rb +2 -9
- data/lib/active_support/xml_mini/jdom.rb +2 -2
- data/lib/active_support/xml_mini/libxml.rb +2 -2
- data/lib/active_support/xml_mini/libxmlsax.rb +4 -4
- data/lib/active_support/xml_mini/nokogiri.rb +2 -2
- data/lib/active_support/xml_mini/nokogirisax.rb +3 -3
- data/lib/active_support/xml_mini/rexml.rb +2 -2
- metadata +34 -9
- data/lib/active_support/core_ext/kernel/agnostics.rb +0 -13
- data/lib/active_support/values/unicode_tables.dat +0 -0
@@ -0,0 +1,110 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "set"
|
4
|
+
require "active_support/core_ext/string/inflections"
|
5
|
+
|
6
|
+
module ActiveSupport
|
7
|
+
module Dependencies
|
8
|
+
module ZeitwerkIntegration # :nodoc: all
|
9
|
+
module Decorations
|
10
|
+
def clear
|
11
|
+
Dependencies.unload_interlock do
|
12
|
+
Rails.autoloaders.main.reload
|
13
|
+
rescue Zeitwerk::ReloadingDisabledError
|
14
|
+
raise "reloading is disabled because config.cache_classes is true"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def constantize(cpath)
|
19
|
+
ActiveSupport::Inflector.constantize(cpath)
|
20
|
+
end
|
21
|
+
|
22
|
+
def safe_constantize(cpath)
|
23
|
+
ActiveSupport::Inflector.safe_constantize(cpath)
|
24
|
+
end
|
25
|
+
|
26
|
+
def autoloaded_constants
|
27
|
+
Rails.autoloaders.main.unloadable_cpaths
|
28
|
+
end
|
29
|
+
|
30
|
+
def autoloaded?(object)
|
31
|
+
cpath = object.is_a?(Module) ? real_mod_name(object) : object.to_s
|
32
|
+
Rails.autoloaders.main.unloadable_cpath?(cpath)
|
33
|
+
end
|
34
|
+
|
35
|
+
def verbose=(verbose)
|
36
|
+
l = verbose ? logger || Rails.logger : nil
|
37
|
+
Rails.autoloaders.each { |autoloader| autoloader.logger = l }
|
38
|
+
end
|
39
|
+
|
40
|
+
def unhook!
|
41
|
+
:no_op
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
module RequireDependency
|
46
|
+
def require_dependency(filename)
|
47
|
+
filename = filename.to_path if filename.respond_to?(:to_path)
|
48
|
+
if abspath = ActiveSupport::Dependencies.search_for_file(filename)
|
49
|
+
require abspath
|
50
|
+
else
|
51
|
+
require filename
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
module Inflector
|
57
|
+
def self.camelize(basename, _abspath)
|
58
|
+
basename.camelize
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class << self
|
63
|
+
def take_over(enable_reloading:)
|
64
|
+
setup_autoloaders(enable_reloading)
|
65
|
+
freeze_paths
|
66
|
+
decorate_dependencies
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def setup_autoloaders(enable_reloading)
|
72
|
+
Dependencies.autoload_paths.each do |autoload_path|
|
73
|
+
# Zeitwerk only accepts existing directories in `push_dir` to
|
74
|
+
# prevent misconfigurations.
|
75
|
+
next unless File.directory?(autoload_path)
|
76
|
+
|
77
|
+
autoloader = \
|
78
|
+
autoload_once?(autoload_path) ? Rails.autoloaders.once : Rails.autoloaders.main
|
79
|
+
|
80
|
+
autoloader.push_dir(autoload_path)
|
81
|
+
autoloader.do_not_eager_load(autoload_path) unless eager_load?(autoload_path)
|
82
|
+
end
|
83
|
+
|
84
|
+
Rails.autoloaders.main.enable_reloading if enable_reloading
|
85
|
+
Rails.autoloaders.each(&:setup)
|
86
|
+
end
|
87
|
+
|
88
|
+
def autoload_once?(autoload_path)
|
89
|
+
Dependencies.autoload_once_paths.include?(autoload_path)
|
90
|
+
end
|
91
|
+
|
92
|
+
def eager_load?(autoload_path)
|
93
|
+
Dependencies._eager_load_paths.member?(autoload_path)
|
94
|
+
end
|
95
|
+
|
96
|
+
def freeze_paths
|
97
|
+
Dependencies.autoload_paths.freeze
|
98
|
+
Dependencies.autoload_once_paths.freeze
|
99
|
+
Dependencies._eager_load_paths.freeze
|
100
|
+
end
|
101
|
+
|
102
|
+
def decorate_dependencies
|
103
|
+
Dependencies.unhook!
|
104
|
+
Dependencies.singleton_class.prepend(Decorations)
|
105
|
+
Object.prepend(RequireDependency)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -35,7 +35,7 @@ module ActiveSupport
|
|
35
35
|
# and the second is a library name.
|
36
36
|
#
|
37
37
|
# ActiveSupport::Deprecation.new('2.0', 'MyLibrary')
|
38
|
-
def initialize(deprecation_horizon = "6.
|
38
|
+
def initialize(deprecation_horizon = "6.1", gem_name = "Rails")
|
39
39
|
self.gem_name = gem_name
|
40
40
|
self.deprecation_horizon = deprecation_horizon
|
41
41
|
# By default, warnings are not silenced and debugging is off.
|
@@ -43,7 +43,7 @@ module ActiveSupport
|
|
43
43
|
deprecation_horizon: deprecation_horizon)
|
44
44
|
},
|
45
45
|
|
46
|
-
silence: ->(message, callstack, deprecation_horizon, gem_name) {},
|
46
|
+
silence: ->(message, callstack, deprecation_horizon, gem_name) { },
|
47
47
|
}
|
48
48
|
|
49
49
|
# Behavior module allows to determine how to display deprecation messages.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "active_support/core_ext/module/aliasing"
|
4
3
|
require "active_support/core_ext/array/extract_options"
|
4
|
+
require "active_support/core_ext/module/redefine_method"
|
5
5
|
|
6
6
|
module ActiveSupport
|
7
7
|
class Deprecation
|
@@ -53,37 +53,25 @@ module ActiveSupport
|
|
53
53
|
options = method_names.extract_options!
|
54
54
|
deprecator = options.delete(:deprecator) || self
|
55
55
|
method_names += options.keys
|
56
|
-
mod =
|
56
|
+
mod = nil
|
57
57
|
|
58
58
|
method_names.each do |method_name|
|
59
59
|
if target_module.method_defined?(method_name) || target_module.private_method_defined?(method_name)
|
60
|
-
|
61
|
-
|
62
|
-
without_method = "#{aliased_method}_without_deprecation#{punctuation}"
|
63
|
-
|
64
|
-
target_module.send(:define_method, with_method) do |*args, &block|
|
60
|
+
method = target_module.instance_method(method_name)
|
61
|
+
target_module.redefine_method(method_name) do |*args, &block|
|
65
62
|
deprecator.deprecation_warning(method_name, options[method_name])
|
66
|
-
|
67
|
-
end
|
68
|
-
|
69
|
-
target_module.send(:alias_method, without_method, method_name)
|
70
|
-
target_module.send(:alias_method, method_name, with_method)
|
71
|
-
|
72
|
-
case
|
73
|
-
when target_module.protected_method_defined?(without_method)
|
74
|
-
target_module.send(:protected, method_name)
|
75
|
-
when target_module.private_method_defined?(without_method)
|
76
|
-
target_module.send(:private, method_name)
|
63
|
+
method.bind(self).call(*args, &block)
|
77
64
|
end
|
78
65
|
else
|
79
|
-
mod
|
66
|
+
mod ||= Module.new
|
67
|
+
mod.define_method(method_name) do |*args, &block|
|
80
68
|
deprecator.deprecation_warning(method_name, options[method_name])
|
81
69
|
super(*args, &block)
|
82
70
|
end
|
83
71
|
end
|
84
72
|
end
|
85
73
|
|
86
|
-
target_module.prepend(mod)
|
74
|
+
target_module.prepend(mod) if mod
|
87
75
|
end
|
88
76
|
end
|
89
77
|
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "active_support/core_ext/regexp"
|
4
|
-
|
5
3
|
module ActiveSupport
|
6
4
|
class Deprecation
|
7
5
|
class DeprecationProxy #:nodoc:
|
@@ -122,7 +120,14 @@ module ActiveSupport
|
|
122
120
|
# # => DEPRECATION WARNING: PLANETS is deprecated! Use PLANETS_POST_2006 instead.
|
123
121
|
# (Backtrace information…)
|
124
122
|
# ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"]
|
125
|
-
class DeprecatedConstantProxy <
|
123
|
+
class DeprecatedConstantProxy < Module
|
124
|
+
def self.new(*args, &block)
|
125
|
+
object = args.first
|
126
|
+
|
127
|
+
return object unless object
|
128
|
+
super
|
129
|
+
end
|
130
|
+
|
126
131
|
def initialize(old_const, new_const, deprecator = ActiveSupport::Deprecation.instance, message: "#{old_const} is deprecated! Use #{new_const} instead.")
|
127
132
|
require "active_support/inflector/methods"
|
128
133
|
|
@@ -132,6 +137,14 @@ module ActiveSupport
|
|
132
137
|
@message = message
|
133
138
|
end
|
134
139
|
|
140
|
+
instance_methods.each { |m| undef_method m unless /^__|^object_id$/.match?(m) }
|
141
|
+
|
142
|
+
# Don't give a deprecation warning on inspect since test/unit and error
|
143
|
+
# logs rely on it for diagnostics.
|
144
|
+
def inspect
|
145
|
+
target.inspect
|
146
|
+
end
|
147
|
+
|
135
148
|
# Returns the class of the new constant.
|
136
149
|
#
|
137
150
|
# PLANETS_POST_2006 = %w(mercury venus earth mars jupiter saturn uranus neptune)
|
@@ -146,8 +159,14 @@ module ActiveSupport
|
|
146
159
|
ActiveSupport::Inflector.constantize(@new_const.to_s)
|
147
160
|
end
|
148
161
|
|
149
|
-
def
|
150
|
-
@deprecator.warn(@message,
|
162
|
+
def const_missing(name)
|
163
|
+
@deprecator.warn(@message, caller_locations)
|
164
|
+
target.const_get(name)
|
165
|
+
end
|
166
|
+
|
167
|
+
def method_missing(called, *args, &block)
|
168
|
+
@deprecator.warn(@message, caller_locations)
|
169
|
+
target.__send__(called, *args, &block)
|
151
170
|
end
|
152
171
|
end
|
153
172
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "weakref"
|
4
|
+
|
3
5
|
module ActiveSupport
|
4
6
|
# This module provides an internal implementation to track descendants
|
5
7
|
# which is faster than iterating through ObjectSpace.
|
@@ -8,7 +10,8 @@ module ActiveSupport
|
|
8
10
|
|
9
11
|
class << self
|
10
12
|
def direct_descendants(klass)
|
11
|
-
@@direct_descendants[klass]
|
13
|
+
descendants = @@direct_descendants[klass]
|
14
|
+
descendants ? descendants.to_a : []
|
12
15
|
end
|
13
16
|
|
14
17
|
def descendants(klass)
|
@@ -20,10 +23,10 @@ module ActiveSupport
|
|
20
23
|
def clear
|
21
24
|
if defined? ActiveSupport::Dependencies
|
22
25
|
@@direct_descendants.each do |klass, descendants|
|
23
|
-
if
|
26
|
+
if Dependencies.autoloaded?(klass)
|
24
27
|
@@direct_descendants.delete(klass)
|
25
28
|
else
|
26
|
-
descendants.reject! { |v|
|
29
|
+
descendants.reject! { |v| Dependencies.autoloaded?(v) }
|
27
30
|
end
|
28
31
|
end
|
29
32
|
else
|
@@ -34,16 +37,19 @@ module ActiveSupport
|
|
34
37
|
# This is the only method that is not thread safe, but is only ever called
|
35
38
|
# during the eager loading phase.
|
36
39
|
def store_inherited(klass, descendant)
|
37
|
-
(@@direct_descendants[klass] ||=
|
40
|
+
(@@direct_descendants[klass] ||= DescendantsArray.new) << descendant
|
38
41
|
end
|
39
42
|
|
40
43
|
private
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
44
|
+
|
45
|
+
def accumulate_descendants(klass, acc)
|
46
|
+
if direct_descendants = @@direct_descendants[klass]
|
47
|
+
direct_descendants.each do |direct_descendant|
|
48
|
+
acc << direct_descendant
|
49
|
+
accumulate_descendants(direct_descendant, acc)
|
50
|
+
end
|
51
|
+
end
|
45
52
|
end
|
46
|
-
end
|
47
53
|
end
|
48
54
|
|
49
55
|
def inherited(base)
|
@@ -58,5 +64,46 @@ module ActiveSupport
|
|
58
64
|
def descendants
|
59
65
|
DescendantsTracker.descendants(self)
|
60
66
|
end
|
67
|
+
|
68
|
+
# DescendantsArray is an array that contains weak references to classes.
|
69
|
+
class DescendantsArray # :nodoc:
|
70
|
+
include Enumerable
|
71
|
+
|
72
|
+
def initialize
|
73
|
+
@refs = []
|
74
|
+
end
|
75
|
+
|
76
|
+
def initialize_copy(orig)
|
77
|
+
@refs = @refs.dup
|
78
|
+
end
|
79
|
+
|
80
|
+
def <<(klass)
|
81
|
+
cleanup!
|
82
|
+
@refs << WeakRef.new(klass)
|
83
|
+
end
|
84
|
+
|
85
|
+
def each
|
86
|
+
@refs.each do |ref|
|
87
|
+
yield ref.__getobj__
|
88
|
+
rescue WeakRef::RefError
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def refs_size
|
93
|
+
@refs.size
|
94
|
+
end
|
95
|
+
|
96
|
+
def cleanup!
|
97
|
+
@refs.delete_if { |ref| !ref.weakref_alive? }
|
98
|
+
end
|
99
|
+
|
100
|
+
def reject!
|
101
|
+
@refs.reject! do |ref|
|
102
|
+
yield ref.__getobj__
|
103
|
+
rescue WeakRef::RefError
|
104
|
+
true
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
61
108
|
end
|
62
109
|
end
|
@@ -4,7 +4,6 @@ require "active_support/core_ext/array/conversions"
|
|
4
4
|
require "active_support/core_ext/module/delegation"
|
5
5
|
require "active_support/core_ext/object/acts_like"
|
6
6
|
require "active_support/core_ext/string/filters"
|
7
|
-
require "active_support/deprecation"
|
8
7
|
|
9
8
|
module ActiveSupport
|
10
9
|
# Provides accurate date and time measurements using Date#advance and
|
@@ -214,8 +213,11 @@ module ActiveSupport
|
|
214
213
|
end
|
215
214
|
|
216
215
|
def coerce(other) #:nodoc:
|
217
|
-
|
216
|
+
case other
|
217
|
+
when Scalar
|
218
218
|
[other, self]
|
219
|
+
when Duration
|
220
|
+
[Scalar.new(other.value), self]
|
219
221
|
else
|
220
222
|
[Scalar.new(other), self]
|
221
223
|
end
|
@@ -373,7 +375,6 @@ module ActiveSupport
|
|
373
375
|
return "0 seconds" if parts.empty?
|
374
376
|
|
375
377
|
parts.
|
376
|
-
reduce(::Hash.new(0)) { |h, (l, r)| h[l] += r; h }.
|
377
378
|
sort_by { |unit, _ | PARTS.index(unit) }.
|
378
379
|
map { |unit, val| "#{val} #{val == 1 ? unit.to_s.chop : unit.to_s}" }.
|
379
380
|
to_sentence(locale: ::I18n.default_locale)
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "strscan"
|
4
|
-
require "active_support/core_ext/regexp"
|
5
4
|
|
6
5
|
module ActiveSupport
|
7
6
|
class Duration
|
@@ -14,8 +13,8 @@ module ActiveSupport
|
|
14
13
|
class ParsingError < ::ArgumentError; end
|
15
14
|
|
16
15
|
PERIOD_OR_COMMA = /\.|,/
|
17
|
-
PERIOD = "."
|
18
|
-
COMMA = ","
|
16
|
+
PERIOD = "."
|
17
|
+
COMMA = ","
|
19
18
|
|
20
19
|
SIGN_MARKER = /\A\-|\+|/
|
21
20
|
DATE_MARKER = /P/
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "active_support/core_ext/object/blank"
|
4
|
-
require "active_support/core_ext/hash/transform_values"
|
5
4
|
|
6
5
|
module ActiveSupport
|
7
6
|
class Duration
|
@@ -15,14 +14,14 @@ module ActiveSupport
|
|
15
14
|
# Builds and returns output string.
|
16
15
|
def serialize
|
17
16
|
parts, sign = normalize
|
18
|
-
return "PT0S"
|
17
|
+
return "PT0S" if parts.empty?
|
19
18
|
|
20
|
-
output = "P"
|
19
|
+
output = +"P"
|
21
20
|
output << "#{parts[:years]}Y" if parts.key?(:years)
|
22
21
|
output << "#{parts[:months]}M" if parts.key?(:months)
|
23
22
|
output << "#{parts[:weeks]}W" if parts.key?(:weeks)
|
24
23
|
output << "#{parts[:days]}D" if parts.key?(:days)
|
25
|
-
time = ""
|
24
|
+
time = +""
|
26
25
|
time << "#{parts[:hours]}H" if parts.key?(:hours)
|
27
26
|
time << "#{parts[:minutes]}M" if parts.key?(:minutes)
|
28
27
|
if parts.key?(:seconds)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "pathname"
|
4
|
+
require "tmpdir"
|
4
5
|
require "active_support/message_encryptor"
|
5
6
|
|
6
7
|
module ActiveSupport
|
@@ -67,7 +68,7 @@ module ActiveSupport
|
|
67
68
|
|
68
69
|
write(updated_contents) if updated_contents != contents
|
69
70
|
ensure
|
70
|
-
FileUtils.rm(tmp_path) if tmp_path
|
71
|
+
FileUtils.rm(tmp_path) if tmp_path&.exist?
|
71
72
|
end
|
72
73
|
|
73
74
|
|
@@ -52,16 +52,17 @@ module ActiveSupport
|
|
52
52
|
@pid = Process.pid
|
53
53
|
@boot_mutex = Mutex.new
|
54
54
|
|
55
|
-
|
55
|
+
dtw = directories_to_watch
|
56
|
+
@dtw, @missing = dtw.partition(&:exist?)
|
57
|
+
|
58
|
+
if @dtw.any?
|
56
59
|
# Loading listen triggers warnings. These are originated by a legit
|
57
60
|
# usage of attr_* macros for private attributes, but adds a lot of noise
|
58
61
|
# to our test suite. Thus, we lazy load it and disable warnings locally.
|
59
62
|
silence_warnings do
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
raise LoadError, "Could not load the 'listen' gem. Add `gem 'listen'` to the development group of your Gemfile", e.backtrace
|
64
|
-
end
|
63
|
+
require "listen"
|
64
|
+
rescue LoadError => e
|
65
|
+
raise LoadError, "Could not load the 'listen' gem. Add `gem 'listen'` to the development group of your Gemfile", e.backtrace
|
65
66
|
end
|
66
67
|
end
|
67
68
|
boot!
|
@@ -75,6 +76,19 @@ module ActiveSupport
|
|
75
76
|
@updated.make_true
|
76
77
|
end
|
77
78
|
end
|
79
|
+
|
80
|
+
if @missing.any?(&:exist?)
|
81
|
+
@boot_mutex.synchronize do
|
82
|
+
appeared, @missing = @missing.partition(&:exist?)
|
83
|
+
shutdown!
|
84
|
+
|
85
|
+
@dtw += appeared
|
86
|
+
boot!
|
87
|
+
|
88
|
+
@updated.make_true
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
78
92
|
@updated.true?
|
79
93
|
end
|
80
94
|
|
@@ -93,7 +107,21 @@ module ActiveSupport
|
|
93
107
|
|
94
108
|
private
|
95
109
|
def boot!
|
96
|
-
|
110
|
+
normalize_dirs!
|
111
|
+
|
112
|
+
unless @dtw.empty?
|
113
|
+
Listen.to(*@dtw, &method(:changed)).start
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def shutdown!
|
118
|
+
Listen.stop
|
119
|
+
end
|
120
|
+
|
121
|
+
def normalize_dirs!
|
122
|
+
@dirs.transform_keys! do |dir|
|
123
|
+
dir.exist? ? dir.realpath : dir
|
124
|
+
end
|
97
125
|
end
|
98
126
|
|
99
127
|
def changed(modified, added, removed)
|
@@ -113,7 +141,9 @@ module ActiveSupport
|
|
113
141
|
ext = @ph.normalize_extension(file.extname)
|
114
142
|
|
115
143
|
file.dirname.ascend do |dir|
|
116
|
-
|
144
|
+
matching = @dirs[dir]
|
145
|
+
|
146
|
+
if matching && (matching.empty? || matching.include?(ext))
|
117
147
|
break true
|
118
148
|
elsif dir == @lcsp || dir.root?
|
119
149
|
break false
|
@@ -123,7 +153,7 @@ module ActiveSupport
|
|
123
153
|
end
|
124
154
|
|
125
155
|
def directories_to_watch
|
126
|
-
dtw =
|
156
|
+
dtw = @files.map(&:dirname) + @dirs.keys
|
127
157
|
dtw.compact!
|
128
158
|
dtw.uniq!
|
129
159
|
|