activesupport 6.0.6.1 → 7.1.3.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +865 -438
- data/MIT-LICENSE +1 -1
- data/README.rdoc +6 -6
- data/lib/active_support/actionable_error.rb +4 -2
- data/lib/active_support/array_inquirer.rb +4 -2
- data/lib/active_support/backtrace_cleaner.rb +30 -10
- data/lib/active_support/benchmarkable.rb +4 -3
- data/lib/active_support/broadcast_logger.rb +250 -0
- data/lib/active_support/builder.rb +1 -1
- data/lib/active_support/cache/coder.rb +153 -0
- data/lib/active_support/cache/entry.rb +134 -0
- data/lib/active_support/cache/file_store.rb +53 -20
- data/lib/active_support/cache/mem_cache_store.rb +208 -63
- data/lib/active_support/cache/memory_store.rb +120 -38
- data/lib/active_support/cache/null_store.rb +16 -2
- data/lib/active_support/cache/redis_cache_store.rb +201 -208
- data/lib/active_support/cache/serializer_with_fallback.rb +175 -0
- data/lib/active_support/cache/strategy/local_cache.rb +73 -66
- data/lib/active_support/cache.rb +539 -261
- data/lib/active_support/callbacks.rb +273 -142
- data/lib/active_support/code_generator.rb +65 -0
- data/lib/active_support/concern.rb +53 -7
- data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +44 -7
- data/lib/active_support/concurrency/null_lock.rb +13 -0
- data/lib/active_support/concurrency/share_lock.rb +2 -2
- data/lib/active_support/configurable.rb +19 -6
- data/lib/active_support/configuration_file.rb +51 -0
- data/lib/active_support/core_ext/array/access.rb +1 -5
- data/lib/active_support/core_ext/array/conversions.rb +15 -13
- 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/benchmark.rb +2 -2
- data/lib/active_support/core_ext/big_decimal/conversions.rb +1 -1
- data/lib/active_support/core_ext/class/attribute.rb +34 -44
- data/lib/active_support/core_ext/class/subclasses.rb +19 -29
- 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 +18 -16
- data/lib/active_support/core_ext/date_and_time/calculations.rb +27 -4
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +15 -0
- 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 +19 -15
- data/lib/active_support/core_ext/digest/uuid.rb +30 -13
- data/lib/active_support/core_ext/enumerable.rb +146 -72
- data/lib/active_support/core_ext/erb/util.rb +196 -0
- data/lib/active_support/core_ext/file/atomic.rb +3 -1
- data/lib/active_support/core_ext/hash/conversions.rb +3 -4
- data/lib/active_support/core_ext/hash/deep_merge.rb +22 -14
- data/lib/active_support/core_ext/hash/deep_transform_values.rb +4 -4
- data/lib/active_support/core_ext/hash/indifferent_access.rb +3 -3
- data/lib/active_support/core_ext/hash/keys.rb +5 -5
- data/lib/active_support/core_ext/hash/slice.rb +3 -2
- 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/load_error.rb +1 -1
- data/lib/active_support/core_ext/module/attr_internal.rb +2 -2
- data/lib/active_support/core_ext/module/attribute_accessors.rb +31 -29
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +51 -20
- data/lib/active_support/core_ext/module/concerning.rb +14 -8
- data/lib/active_support/core_ext/module/delegation.rb +75 -42
- data/lib/active_support/core_ext/module/deprecation.rb +15 -12
- data/lib/active_support/core_ext/module/introspection.rb +1 -26
- data/lib/active_support/core_ext/name_error.rb +23 -2
- data/lib/active_support/core_ext/numeric/bytes.rb +9 -0
- data/lib/active_support/core_ext/numeric/conversions.rb +82 -73
- 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 +17 -1
- data/lib/active_support/core_ext/object/duplicable.rb +15 -4
- data/lib/active_support/core_ext/object/inclusion.rb +13 -5
- data/lib/active_support/core_ext/object/instance_variables.rb +22 -12
- data/lib/active_support/core_ext/object/json.rb +52 -28
- 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.rb +44 -0
- data/lib/active_support/core_ext/object/with_options.rb +25 -6
- data/lib/active_support/core_ext/object.rb +1 -0
- data/lib/active_support/core_ext/pathname/blank.rb +16 -0
- data/lib/active_support/core_ext/pathname/existence.rb +23 -0
- data/lib/active_support/core_ext/pathname.rb +4 -0
- data/lib/active_support/core_ext/range/compare_range.rb +6 -25
- data/lib/active_support/core_ext/range/conversions.rb +34 -13
- data/lib/active_support/core_ext/range/each.rb +1 -1
- data/lib/active_support/core_ext/range/overlap.rb +40 -0
- data/lib/active_support/core_ext/range.rb +1 -2
- data/lib/active_support/core_ext/regexp.rb +8 -1
- data/lib/active_support/core_ext/securerandom.rb +25 -13
- data/lib/active_support/core_ext/string/access.rb +5 -24
- data/lib/active_support/core_ext/string/conversions.rb +3 -2
- data/lib/active_support/core_ext/string/filters.rb +21 -15
- data/lib/active_support/core_ext/string/indent.rb +1 -1
- data/lib/active_support/core_ext/string/inflections.rb +51 -10
- data/lib/active_support/core_ext/string/inquiry.rb +2 -1
- data/lib/active_support/core_ext/string/multibyte.rb +2 -2
- data/lib/active_support/core_ext/string/output_safety.rb +85 -194
- data/lib/active_support/core_ext/string/starts_ends_with.rb +2 -2
- data/lib/active_support/core_ext/symbol/starts_ends_with.rb +6 -0
- data/lib/active_support/core_ext/symbol.rb +3 -0
- data/lib/active_support/core_ext/thread/backtrace/location.rb +12 -0
- data/lib/active_support/core_ext/time/calculations.rb +46 -8
- data/lib/active_support/core_ext/time/conversions.rb +16 -13
- data/lib/active_support/core_ext/time/zones.rb +12 -28
- data/lib/active_support/core_ext.rb +2 -1
- data/lib/active_support/current_attributes/test_helper.rb +13 -0
- data/lib/active_support/current_attributes.rb +54 -22
- data/lib/active_support/deep_mergeable.rb +53 -0
- data/lib/active_support/dependencies/autoload.rb +17 -12
- 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 -769
- data/lib/active_support/deprecation/behaviors.rb +77 -38
- data/lib/active_support/deprecation/constant_accessor.rb +5 -4
- data/lib/active_support/deprecation/deprecators.rb +104 -0
- data/lib/active_support/deprecation/disallowed.rb +54 -0
- data/lib/active_support/deprecation/instance_delegator.rb +31 -5
- data/lib/active_support/deprecation/method_wrappers.rb +12 -28
- data/lib/active_support/deprecation/proxy_wrappers.rb +40 -25
- data/lib/active_support/deprecation/reporting.rb +76 -16
- data/lib/active_support/deprecation.rb +36 -4
- data/lib/active_support/deprecator.rb +7 -0
- data/lib/active_support/descendants_tracker.rb +150 -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 +24 -12
- data/lib/active_support/duration.rb +136 -56
- data/lib/active_support/encrypted_configuration.rb +72 -9
- data/lib/active_support/encrypted_file.rb +46 -13
- data/lib/active_support/environment_inquirer.rb +40 -0
- data/lib/active_support/error_reporter/test_helper.rb +15 -0
- data/lib/active_support/error_reporter.rb +203 -0
- data/lib/active_support/evented_file_update_checker.rb +86 -137
- 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 +31 -12
- data/lib/active_support/executor/test_helper.rb +7 -0
- data/lib/active_support/file_update_checker.rb +4 -2
- data/lib/active_support/fork_tracker.rb +79 -0
- data/lib/active_support/gem_version.rb +5 -5
- data/lib/active_support/gzip.rb +2 -0
- data/lib/active_support/hash_with_indifferent_access.rb +86 -42
- data/lib/active_support/html_safe_translation.rb +53 -0
- data/lib/active_support/i18n.rb +2 -1
- data/lib/active_support/i18n_railtie.rb +29 -27
- data/lib/active_support/inflector/inflections.rb +26 -9
- data/lib/active_support/inflector/methods.rb +54 -64
- data/lib/active_support/inflector/transliterate.rb +7 -5
- data/lib/active_support/isolated_execution_state.rb +76 -0
- data/lib/active_support/json/decoding.rb +6 -5
- data/lib/active_support/json/encoding.rb +31 -45
- data/lib/active_support/key_generator.rb +32 -7
- data/lib/active_support/lazy_load_hooks.rb +33 -7
- data/lib/active_support/locale/en.yml +10 -4
- data/lib/active_support/log_subscriber/test_helper.rb +2 -2
- data/lib/active_support/log_subscriber.rb +101 -32
- data/lib/active_support/logger.rb +9 -60
- data/lib/active_support/logger_silence.rb +2 -26
- data/lib/active_support/logger_thread_safe_level.rb +24 -25
- data/lib/active_support/message_encryptor.rb +205 -58
- data/lib/active_support/message_encryptors.rb +141 -0
- data/lib/active_support/message_pack/cache_serializer.rb +23 -0
- data/lib/active_support/message_pack/extensions.rb +292 -0
- data/lib/active_support/message_pack/serializer.rb +63 -0
- data/lib/active_support/message_pack.rb +50 -0
- data/lib/active_support/message_verifier.rb +237 -86
- data/lib/active_support/message_verifiers.rb +135 -0
- data/lib/active_support/messages/codec.rb +65 -0
- data/lib/active_support/messages/metadata.rb +112 -46
- data/lib/active_support/messages/rotation_configuration.rb +2 -1
- data/lib/active_support/messages/rotation_coordinator.rb +93 -0
- data/lib/active_support/messages/rotator.rb +35 -32
- data/lib/active_support/messages/serializer_with_fallback.rb +158 -0
- data/lib/active_support/multibyte/chars.rb +15 -52
- data/lib/active_support/multibyte/unicode.rb +8 -122
- data/lib/active_support/multibyte.rb +1 -1
- data/lib/active_support/notifications/fanout.rb +310 -105
- data/lib/active_support/notifications/instrumenter.rb +113 -48
- data/lib/active_support/notifications.rb +56 -29
- data/lib/active_support/number_helper/number_converter.rb +15 -8
- 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_converter.rb +1 -1
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +5 -5
- data/lib/active_support/number_helper/number_to_phone_converter.rb +2 -1
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +9 -5
- data/lib/active_support/number_helper/rounding_helper.rb +12 -32
- data/lib/active_support/number_helper.rb +379 -304
- data/lib/active_support/option_merger.rb +11 -18
- data/lib/active_support/ordered_hash.rb +4 -4
- data/lib/active_support/ordered_options.rb +23 -3
- data/lib/active_support/parameter_filter.rb +104 -75
- data/lib/active_support/proxy_object.rb +2 -0
- data/lib/active_support/rails.rb +1 -4
- data/lib/active_support/railtie.rb +90 -6
- data/lib/active_support/reloader.rb +12 -4
- data/lib/active_support/rescuable.rb +18 -16
- data/lib/active_support/ruby_features.rb +7 -0
- data/lib/active_support/secure_compare_rotator.rb +58 -0
- data/lib/active_support/security_utils.rb +19 -12
- data/lib/active_support/string_inquirer.rb +5 -3
- data/lib/active_support/subscriber.rb +23 -47
- data/lib/active_support/syntax_error_proxy.rb +70 -0
- data/lib/active_support/tagged_logging.rb +84 -23
- data/lib/active_support/test_case.rb +166 -27
- data/lib/active_support/testing/assertions.rb +73 -20
- data/lib/active_support/testing/autorun.rb +0 -2
- data/lib/active_support/testing/constant_stubbing.rb +32 -0
- data/lib/active_support/testing/deprecation.rb +53 -2
- data/lib/active_support/testing/error_reporter_assertions.rb +107 -0
- data/lib/active_support/testing/isolation.rb +30 -29
- data/lib/active_support/testing/method_call_assertions.rb +24 -11
- data/lib/active_support/testing/parallelization/server.rb +82 -0
- data/lib/active_support/testing/parallelization/worker.rb +103 -0
- data/lib/active_support/testing/parallelization.rb +16 -95
- data/lib/active_support/testing/parallelize_executor.rb +81 -0
- data/lib/active_support/testing/stream.rb +4 -6
- data/lib/active_support/testing/strict_warnings.rb +39 -0
- data/lib/active_support/testing/tagged_logging.rb +1 -1
- data/lib/active_support/testing/time_helpers.rb +89 -19
- data/lib/active_support/time_with_zone.rb +105 -70
- data/lib/active_support/values/time_zone.rb +59 -26
- data/lib/active_support/version.rb +1 -1
- data/lib/active_support/xml_mini/jdom.rb +4 -11
- 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 +5 -5
- data/lib/active_support/xml_mini/nokogirisax.rb +2 -2
- data/lib/active_support/xml_mini/rexml.rb +9 -2
- data/lib/active_support/xml_mini.rb +7 -6
- data/lib/active_support.rb +40 -1
- metadata +127 -40
- data/lib/active_support/core_ext/array/prepend_and_append.rb +0 -5
- data/lib/active_support/core_ext/hash/compact.rb +0 -5
- data/lib/active_support/core_ext/hash/transform_values.rb +0 -5
- data/lib/active_support/core_ext/marshal.rb +0 -24
- data/lib/active_support/core_ext/module/reachable.rb +0 -6
- data/lib/active_support/core_ext/numeric/inquiry.rb +0 -5
- data/lib/active_support/core_ext/range/include_range.rb +0 -9
- data/lib/active_support/core_ext/range/include_time_with_zone.rb +0 -23
- data/lib/active_support/core_ext/range/overlaps.rb +0 -10
- data/lib/active_support/core_ext/uri.rb +0 -25
- data/lib/active_support/dependencies/zeitwerk_integration.rb +0 -117
- data/lib/active_support/per_thread_registry.rb +0 -60
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveSupport::CurrentAttributes::TestHelper # :nodoc:
|
4
|
+
def before_setup
|
5
|
+
ActiveSupport::CurrentAttributes.reset_all
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
def after_teardown
|
10
|
+
super
|
11
|
+
ActiveSupport::CurrentAttributes.reset_all
|
12
|
+
end
|
13
|
+
end
|
@@ -1,8 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "active_support/callbacks"
|
4
|
+
require "active_support/core_ext/enumerable"
|
5
|
+
require "active_support/core_ext/module/delegation"
|
4
6
|
|
5
7
|
module ActiveSupport
|
8
|
+
# = Current Attributes
|
9
|
+
#
|
6
10
|
# Abstract super class that provides a thread-isolated attributes singleton, which resets automatically
|
7
11
|
# before and after each request. This allows you to keep all the per-request attributes easily
|
8
12
|
# available to the whole system.
|
@@ -88,45 +92,64 @@ module ActiveSupport
|
|
88
92
|
include ActiveSupport::Callbacks
|
89
93
|
define_callbacks :reset
|
90
94
|
|
95
|
+
INVALID_ATTRIBUTE_NAMES = [:set, :reset, :resets, :instance, :before_reset, :after_reset, :reset_all, :clear_all] # :nodoc:
|
96
|
+
|
91
97
|
class << self
|
92
98
|
# Returns singleton instance for this class in this thread. If none exists, one is created.
|
93
99
|
def instance
|
94
|
-
current_instances[
|
100
|
+
current_instances[current_instances_key] ||= new
|
95
101
|
end
|
96
102
|
|
97
103
|
# Declares one or more attributes that will be given both class and instance accessor methods.
|
98
104
|
def attribute(*names)
|
99
|
-
|
105
|
+
invalid_attribute_names = names.map(&:to_sym) & INVALID_ATTRIBUTE_NAMES
|
106
|
+
if invalid_attribute_names.any?
|
107
|
+
raise ArgumentError, "Restricted attribute names: #{invalid_attribute_names.join(", ")}"
|
108
|
+
end
|
109
|
+
|
110
|
+
ActiveSupport::CodeGenerator.batch(generated_attribute_methods, __FILE__, __LINE__) do |owner|
|
100
111
|
names.each do |name|
|
101
|
-
|
102
|
-
|
112
|
+
owner.define_cached_method(name, namespace: :current_attributes) do |batch|
|
113
|
+
batch <<
|
114
|
+
"def #{name}" <<
|
115
|
+
"attributes[:#{name}]" <<
|
116
|
+
"end"
|
103
117
|
end
|
104
|
-
|
105
|
-
|
106
|
-
|
118
|
+
owner.define_cached_method("#{name}=", namespace: :current_attributes) do |batch|
|
119
|
+
batch <<
|
120
|
+
"def #{name}=(value)" <<
|
121
|
+
"attributes[:#{name}] = value" <<
|
122
|
+
"end"
|
107
123
|
end
|
108
124
|
end
|
109
125
|
end
|
110
126
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
127
|
+
ActiveSupport::CodeGenerator.batch(singleton_class, __FILE__, __LINE__) do |owner|
|
128
|
+
names.each do |name|
|
129
|
+
owner.define_cached_method(name, namespace: :current_attributes_delegation) do |batch|
|
130
|
+
batch <<
|
131
|
+
"def #{name}" <<
|
132
|
+
"instance.#{name}" <<
|
133
|
+
"end"
|
134
|
+
end
|
135
|
+
owner.define_cached_method("#{name}=", namespace: :current_attributes_delegation) do |batch|
|
136
|
+
batch <<
|
137
|
+
"def #{name}=(value)" <<
|
138
|
+
"instance.#{name} = value" <<
|
139
|
+
"end"
|
140
|
+
end
|
118
141
|
end
|
119
142
|
end
|
120
143
|
end
|
121
144
|
|
122
|
-
# Calls this
|
123
|
-
def before_reset(&block)
|
124
|
-
set_callback :reset, :before, &block
|
145
|
+
# Calls this callback before #reset is called on the instance. Used for resetting external collaborators that depend on current values.
|
146
|
+
def before_reset(*methods, &block)
|
147
|
+
set_callback :reset, :before, *methods, &block
|
125
148
|
end
|
126
149
|
|
127
|
-
# Calls this
|
128
|
-
def resets(&block)
|
129
|
-
set_callback :reset, :after, &block
|
150
|
+
# Calls this callback after #reset is called on the instance. Used for resetting external collaborators, like Time.zone.
|
151
|
+
def resets(*methods, &block)
|
152
|
+
set_callback :reset, :after, *methods, &block
|
130
153
|
end
|
131
154
|
alias_method :after_reset, :resets
|
132
155
|
|
@@ -147,7 +170,11 @@ module ActiveSupport
|
|
147
170
|
end
|
148
171
|
|
149
172
|
def current_instances
|
150
|
-
|
173
|
+
IsolatedExecutionState[:current_attributes_instances] ||= {}
|
174
|
+
end
|
175
|
+
|
176
|
+
def current_instances_key
|
177
|
+
@current_instances_key ||= name.to_sym
|
151
178
|
end
|
152
179
|
|
153
180
|
def method_missing(name, *args, &block)
|
@@ -158,6 +185,11 @@ module ActiveSupport
|
|
158
185
|
|
159
186
|
send(name, *args, &block)
|
160
187
|
end
|
188
|
+
ruby2_keywords(:method_missing)
|
189
|
+
|
190
|
+
def respond_to_missing?(name, _)
|
191
|
+
super || instance.respond_to?(name)
|
192
|
+
end
|
161
193
|
end
|
162
194
|
|
163
195
|
attr_accessor :attributes
|
@@ -197,7 +229,7 @@ module ActiveSupport
|
|
197
229
|
end
|
198
230
|
|
199
231
|
def compute_attributes(keys)
|
200
|
-
keys.
|
232
|
+
keys.index_with { |key| public_send(key) }
|
201
233
|
end
|
202
234
|
end
|
203
235
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
# Provides +deep_merge+ and +deep_merge!+ methods. Expects the including class
|
5
|
+
# to provide a <tt>merge!(other, &block)</tt> method.
|
6
|
+
module DeepMergeable # :nodoc:
|
7
|
+
# Returns a new instance with the values from +other+ merged recursively.
|
8
|
+
#
|
9
|
+
# class Hash
|
10
|
+
# include ActiveSupport::DeepMergeable
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# hash_1 = { a: true, b: { c: [1, 2, 3] } }
|
14
|
+
# hash_2 = { a: false, b: { x: [3, 4, 5] } }
|
15
|
+
#
|
16
|
+
# hash_1.deep_merge(hash_2)
|
17
|
+
# # => { a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } }
|
18
|
+
#
|
19
|
+
# A block can be provided to merge non-<tt>DeepMergeable</tt> values:
|
20
|
+
#
|
21
|
+
# hash_1 = { a: 100, b: 200, c: { c1: 100 } }
|
22
|
+
# hash_2 = { b: 250, c: { c1: 200 } }
|
23
|
+
#
|
24
|
+
# hash_1.deep_merge(hash_2) do |key, this_val, other_val|
|
25
|
+
# this_val + other_val
|
26
|
+
# end
|
27
|
+
# # => { a: 100, b: 450, c: { c1: 300 } }
|
28
|
+
#
|
29
|
+
def deep_merge(other, &block)
|
30
|
+
dup.deep_merge!(other, &block)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Same as #deep_merge, but modifies +self+.
|
34
|
+
def deep_merge!(other, &block)
|
35
|
+
merge!(other) do |key, this_val, other_val|
|
36
|
+
if this_val.is_a?(DeepMergeable) && this_val.deep_merge?(other_val)
|
37
|
+
this_val.deep_merge(other_val, &block)
|
38
|
+
elsif block_given?
|
39
|
+
block.call(key, this_val, other_val)
|
40
|
+
else
|
41
|
+
other_val
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Returns true if +other+ can be deep merged into +self+. Classes may
|
47
|
+
# override this method to restrict or expand the domain of deep mergeable
|
48
|
+
# values. Defaults to checking that +other+ is of type +self.class+.
|
49
|
+
def deep_merge?(other)
|
50
|
+
other.is_a?(self.class)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -3,10 +3,12 @@
|
|
3
3
|
require "active_support/inflector/methods"
|
4
4
|
|
5
5
|
module ActiveSupport
|
6
|
+
# = Active Support \Autoload
|
7
|
+
#
|
6
8
|
# Autoload and eager load conveniences for your library.
|
7
9
|
#
|
8
10
|
# This module allows you to define autoloads based on
|
9
|
-
# Rails conventions (i.e. no need to define the path
|
11
|
+
# \Rails conventions (i.e. no need to define the path
|
10
12
|
# it is automatically guessed based on the filename)
|
11
13
|
# and also define a set of constants that needs to be
|
12
14
|
# eager loaded:
|
@@ -26,11 +28,14 @@ module ActiveSupport
|
|
26
28
|
# MyLib.eager_load!
|
27
29
|
module Autoload
|
28
30
|
def self.extended(base) # :nodoc:
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
if RUBY_VERSION < "3"
|
32
|
+
base.class_eval do
|
33
|
+
@_autoloads = nil
|
34
|
+
@_under_path = nil
|
35
|
+
@_at_path = nil
|
36
|
+
@_eager_autoload = false
|
37
|
+
@_eagerloaded_constants = nil
|
38
|
+
end
|
34
39
|
end
|
35
40
|
end
|
36
41
|
|
@@ -41,7 +46,8 @@ module ActiveSupport
|
|
41
46
|
end
|
42
47
|
|
43
48
|
if @_eager_autoload
|
44
|
-
@
|
49
|
+
@_eagerloaded_constants ||= []
|
50
|
+
@_eagerloaded_constants << const_name
|
45
51
|
end
|
46
52
|
|
47
53
|
super const_name, path
|
@@ -69,11 +75,10 @@ module ActiveSupport
|
|
69
75
|
end
|
70
76
|
|
71
77
|
def eager_load!
|
72
|
-
@
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
@_autoloads
|
78
|
+
if @_eagerloaded_constants
|
79
|
+
@_eagerloaded_constants.each { |const_name| const_get(const_name) }
|
80
|
+
@_eagerloaded_constants = nil
|
81
|
+
end
|
77
82
|
end
|
78
83
|
end
|
79
84
|
end
|
@@ -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
|