activesupport 7.1.6 → 8.1.1
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 +256 -1133
- data/README.rdoc +1 -1
- data/lib/active_support/array_inquirer.rb +1 -1
- data/lib/active_support/backtrace_cleaner.rb +81 -3
- data/lib/active_support/benchmark.rb +21 -0
- data/lib/active_support/benchmarkable.rb +3 -2
- data/lib/active_support/broadcast_logger.rb +65 -78
- data/lib/active_support/cache/file_store.rb +29 -14
- data/lib/active_support/cache/mem_cache_store.rb +42 -102
- data/lib/active_support/cache/memory_store.rb +11 -6
- data/lib/active_support/cache/null_store.rb +2 -2
- data/lib/active_support/cache/redis_cache_store.rb +58 -46
- data/lib/active_support/cache/serializer_with_fallback.rb +0 -23
- data/lib/active_support/cache/strategy/local_cache.rb +72 -27
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +7 -7
- data/lib/active_support/cache.rb +146 -86
- data/lib/active_support/callbacks.rb +102 -126
- data/lib/active_support/class_attribute.rb +33 -0
- data/lib/active_support/code_generator.rb +9 -0
- data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +8 -62
- data/lib/active_support/concurrency/share_lock.rb +0 -1
- data/lib/active_support/concurrency/thread_monitor.rb +55 -0
- data/lib/active_support/configurable.rb +34 -0
- data/lib/active_support/configuration_file.rb +15 -6
- data/lib/active_support/continuous_integration.rb +145 -0
- data/lib/active_support/core_ext/array/conversions.rb +3 -5
- data/lib/active_support/core_ext/array.rb +7 -7
- data/lib/active_support/core_ext/benchmark.rb +4 -14
- data/lib/active_support/core_ext/big_decimal.rb +1 -1
- data/lib/active_support/core_ext/class/attribute.rb +26 -19
- data/lib/active_support/core_ext/class/subclasses.rb +15 -35
- data/lib/active_support/core_ext/class.rb +2 -2
- data/lib/active_support/core_ext/date/blank.rb +4 -0
- data/lib/active_support/core_ext/date/conversions.rb +2 -2
- data/lib/active_support/core_ext/date.rb +5 -5
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +1 -9
- data/lib/active_support/core_ext/date_time/blank.rb +4 -0
- data/lib/active_support/core_ext/date_time/compatibility.rb +3 -5
- data/lib/active_support/core_ext/date_time/conversions.rb +4 -6
- data/lib/active_support/core_ext/date_time.rb +5 -5
- data/lib/active_support/core_ext/digest/uuid.rb +6 -0
- data/lib/active_support/core_ext/digest.rb +1 -1
- data/lib/active_support/core_ext/enumerable.rb +25 -8
- data/lib/active_support/core_ext/erb/util.rb +10 -5
- data/lib/active_support/core_ext/file.rb +1 -1
- data/lib/active_support/core_ext/hash/deep_merge.rb +1 -0
- data/lib/active_support/core_ext/hash/except.rb +0 -12
- data/lib/active_support/core_ext/hash/keys.rb +4 -4
- data/lib/active_support/core_ext/hash.rb +8 -8
- data/lib/active_support/core_ext/integer.rb +3 -3
- data/lib/active_support/core_ext/kernel.rb +3 -3
- data/lib/active_support/core_ext/module/attr_internal.rb +16 -6
- data/lib/active_support/core_ext/module/delegation.rb +20 -163
- data/lib/active_support/core_ext/module/deprecation.rb +1 -4
- data/lib/active_support/core_ext/module/introspection.rb +3 -0
- data/lib/active_support/core_ext/module.rb +11 -11
- data/lib/active_support/core_ext/numeric/conversions.rb +3 -3
- data/lib/active_support/core_ext/numeric.rb +3 -3
- data/lib/active_support/core_ext/object/blank.rb +45 -1
- data/lib/active_support/core_ext/object/instance_variables.rb +11 -19
- data/lib/active_support/core_ext/object/json.rb +24 -11
- data/lib/active_support/core_ext/object/to_query.rb +7 -1
- data/lib/active_support/core_ext/object/try.rb +2 -2
- data/lib/active_support/core_ext/object/with.rb +5 -3
- data/lib/active_support/core_ext/object.rb +13 -13
- data/lib/active_support/core_ext/pathname/blank.rb +4 -0
- data/lib/active_support/core_ext/pathname.rb +2 -2
- data/lib/active_support/core_ext/range/overlap.rb +4 -4
- data/lib/active_support/core_ext/range/sole.rb +17 -0
- data/lib/active_support/core_ext/range.rb +4 -4
- data/lib/active_support/core_ext/securerandom.rb +4 -4
- data/lib/active_support/core_ext/string/conversions.rb +1 -1
- data/lib/active_support/core_ext/string/filters.rb +4 -4
- data/lib/active_support/core_ext/string/multibyte.rb +13 -4
- data/lib/active_support/core_ext/string/output_safety.rb +19 -19
- data/lib/active_support/core_ext/string.rb +13 -13
- data/lib/active_support/core_ext/symbol.rb +1 -1
- data/lib/active_support/core_ext/thread/backtrace/location.rb +2 -7
- data/lib/active_support/core_ext/time/calculations.rb +25 -30
- data/lib/active_support/core_ext/time/compatibility.rb +2 -3
- data/lib/active_support/core_ext/time/conversions.rb +2 -2
- data/lib/active_support/core_ext/time/zones.rb +1 -1
- data/lib/active_support/core_ext/time.rb +5 -5
- data/lib/active_support/core_ext.rb +1 -2
- data/lib/active_support/current_attributes/test_helper.rb +2 -2
- data/lib/active_support/current_attributes.rb +58 -50
- data/lib/active_support/delegation.rb +200 -0
- data/lib/active_support/dependencies/autoload.rb +0 -12
- data/lib/active_support/dependencies/interlock.rb +11 -5
- data/lib/active_support/dependencies.rb +6 -2
- data/lib/active_support/deprecation/constant_accessor.rb +47 -26
- data/lib/active_support/deprecation/proxy_wrappers.rb +9 -12
- data/lib/active_support/deprecation/reporting.rb +5 -17
- data/lib/active_support/deprecation.rb +8 -5
- data/lib/active_support/descendants_tracker.rb +9 -87
- data/lib/active_support/duration/iso8601_parser.rb +2 -2
- data/lib/active_support/duration/iso8601_serializer.rb +1 -2
- data/lib/active_support/duration.rb +25 -16
- data/lib/active_support/editor.rb +70 -0
- data/lib/active_support/encrypted_configuration.rb +20 -2
- data/lib/active_support/encrypted_file.rb +1 -1
- data/lib/active_support/error_reporter.rb +121 -6
- data/lib/active_support/event_reporter/test_helper.rb +32 -0
- data/lib/active_support/event_reporter.rb +592 -0
- data/lib/active_support/evented_file_update_checker.rb +5 -3
- data/lib/active_support/execution_context.rb +64 -7
- data/lib/active_support/execution_wrapper.rb +1 -2
- data/lib/active_support/file_update_checker.rb +9 -7
- data/lib/active_support/fork_tracker.rb +2 -38
- data/lib/active_support/gem_version.rb +2 -2
- data/lib/active_support/gzip.rb +1 -0
- data/lib/active_support/hash_with_indifferent_access.rb +66 -45
- data/lib/active_support/html_safe_translation.rb +3 -0
- data/lib/active_support/i18n_railtie.rb +19 -11
- data/lib/active_support/inflector/inflections.rb +31 -15
- data/lib/active_support/inflector/transliterate.rb +6 -8
- data/lib/active_support/isolated_execution_state.rb +12 -17
- data/lib/active_support/json/decoding.rb +6 -4
- data/lib/active_support/json/encoding.rb +157 -21
- data/lib/active_support/lazy_load_hooks.rb +1 -1
- data/lib/active_support/log_subscriber.rb +2 -18
- data/lib/active_support/logger.rb +15 -2
- data/lib/active_support/logger_thread_safe_level.rb +4 -9
- data/lib/active_support/message_encryptors.rb +54 -2
- data/lib/active_support/message_pack/extensions.rb +20 -2
- data/lib/active_support/message_verifier.rb +21 -0
- data/lib/active_support/message_verifiers.rb +57 -3
- data/lib/active_support/messages/rotation_coordinator.rb +9 -0
- data/lib/active_support/messages/rotator.rb +10 -0
- data/lib/active_support/multibyte/chars.rb +14 -4
- data/lib/active_support/multibyte.rb +4 -0
- data/lib/active_support/notifications/fanout.rb +68 -50
- data/lib/active_support/notifications/instrumenter.rb +22 -19
- data/lib/active_support/notifications.rb +28 -27
- data/lib/active_support/number_helper/number_converter.rb +2 -2
- data/lib/active_support/number_helper.rb +22 -0
- data/lib/active_support/option_merger.rb +2 -2
- data/lib/active_support/ordered_options.rb +53 -15
- data/lib/active_support/railtie.rb +36 -20
- data/lib/active_support/string_inquirer.rb +1 -1
- data/lib/active_support/structured_event_subscriber.rb +99 -0
- data/lib/active_support/subscriber.rb +1 -5
- data/lib/active_support/syntax_error_proxy.rb +3 -0
- data/lib/active_support/tagged_logging.rb +5 -1
- data/lib/active_support/test_case.rb +63 -6
- data/lib/active_support/testing/assertions.rb +113 -27
- data/lib/active_support/testing/constant_stubbing.rb +30 -8
- data/lib/active_support/testing/deprecation.rb +5 -12
- data/lib/active_support/testing/error_reporter_assertions.rb +18 -1
- data/lib/active_support/testing/event_reporter_assertions.rb +227 -0
- data/lib/active_support/testing/isolation.rb +19 -9
- data/lib/active_support/testing/method_call_assertions.rb +2 -16
- data/lib/active_support/testing/notification_assertions.rb +92 -0
- data/lib/active_support/testing/parallelization/server.rb +18 -2
- data/lib/active_support/testing/parallelization/worker.rb +4 -2
- data/lib/active_support/testing/parallelization.rb +25 -1
- data/lib/active_support/testing/tests_without_assertions.rb +19 -0
- data/lib/active_support/testing/time_helpers.rb +11 -6
- data/lib/active_support/time_with_zone.rb +39 -26
- data/lib/active_support/values/time_zone.rb +26 -17
- data/lib/active_support/xml_mini.rb +14 -4
- data/lib/active_support.rb +22 -9
- metadata +31 -17
- data/lib/active_support/core_ext/range/each.rb +0 -24
- data/lib/active_support/deprecation/instance_delegator.rb +0 -65
- data/lib/active_support/proxy_object.rb +0 -17
- data/lib/active_support/ruby_features.rb +0 -7
- data/lib/active_support/testing/strict_warnings.rb +0 -39
|
@@ -8,13 +8,13 @@ class Hash
|
|
|
8
8
|
# hash.stringify_keys
|
|
9
9
|
# # => {"name"=>"Rob", "age"=>"28"}
|
|
10
10
|
def stringify_keys
|
|
11
|
-
transform_keys
|
|
11
|
+
transform_keys { |k| Symbol === k ? k.name : k.to_s }
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
# Destructively converts all keys to strings. Same as
|
|
15
15
|
# +stringify_keys+, but modifies +self+.
|
|
16
16
|
def stringify_keys!
|
|
17
|
-
transform_keys!
|
|
17
|
+
transform_keys! { |k| Symbol === k ? k.name : k.to_s }
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
# Returns a new hash with all keys converted to symbols, as long as
|
|
@@ -82,14 +82,14 @@ class Hash
|
|
|
82
82
|
# hash.deep_stringify_keys
|
|
83
83
|
# # => {"person"=>{"name"=>"Rob", "age"=>"28"}}
|
|
84
84
|
def deep_stringify_keys
|
|
85
|
-
deep_transform_keys
|
|
85
|
+
deep_transform_keys { |k| Symbol === k ? k.name : k.to_s }
|
|
86
86
|
end
|
|
87
87
|
|
|
88
88
|
# Destructively converts all keys to strings.
|
|
89
89
|
# This includes the keys from the root hash and from all
|
|
90
90
|
# nested hashes and arrays.
|
|
91
91
|
def deep_stringify_keys!
|
|
92
|
-
deep_transform_keys!
|
|
92
|
+
deep_transform_keys! { |k| Symbol === k ? k.name : k.to_s }
|
|
93
93
|
end
|
|
94
94
|
|
|
95
95
|
# Returns a new hash with all keys converted to symbols, as long as
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
require_relative "hash/conversions"
|
|
4
|
+
require_relative "hash/deep_merge"
|
|
5
|
+
require_relative "hash/deep_transform_values"
|
|
6
|
+
require_relative "hash/except"
|
|
7
|
+
require_relative "hash/indifferent_access"
|
|
8
|
+
require_relative "hash/keys"
|
|
9
|
+
require_relative "hash/reverse_merge"
|
|
10
|
+
require_relative "hash/slice"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
require_relative "integer/multiple"
|
|
4
|
+
require_relative "integer/inflections"
|
|
5
|
+
require_relative "integer/time"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
require_relative "kernel/concern"
|
|
4
|
+
require_relative "kernel/reporting"
|
|
5
|
+
require_relative "kernel/singleton_class"
|
|
@@ -19,16 +19,26 @@ class Module
|
|
|
19
19
|
end
|
|
20
20
|
alias_method :attr_internal, :attr_internal_accessor
|
|
21
21
|
|
|
22
|
-
class << self
|
|
23
|
-
|
|
22
|
+
class << self
|
|
23
|
+
attr_reader :attr_internal_naming_format
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
def attr_internal_naming_format=(format)
|
|
26
|
+
if format.start_with?("@")
|
|
27
|
+
raise ArgumentError, <<~MESSAGE.squish
|
|
28
|
+
Setting `attr_internal_naming_format` with a `@` prefix is not supported.
|
|
29
|
+
|
|
30
|
+
You can simply replace #{format.inspect} by #{format.delete_prefix("@").inspect}.
|
|
31
|
+
MESSAGE
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
@attr_internal_naming_format = format
|
|
28
35
|
end
|
|
36
|
+
end
|
|
37
|
+
self.attr_internal_naming_format = "_%s"
|
|
29
38
|
|
|
39
|
+
private
|
|
30
40
|
def attr_internal_define(attr_name, type)
|
|
31
|
-
internal_name =
|
|
41
|
+
internal_name = Module.attr_internal_naming_format % attr_name
|
|
32
42
|
# use native attr_* methods as they are faster on some Ruby implementations
|
|
33
43
|
public_send("attr_#{type}", internal_name)
|
|
34
44
|
attr_name, internal_name = "#{attr_name}=", "#{internal_name}=" if type == :writer
|
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "set"
|
|
4
|
-
|
|
5
3
|
class Module
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class DelegationError < NoMethodError; end
|
|
9
|
-
|
|
10
|
-
RUBY_RESERVED_KEYWORDS = %w(__ENCODING__ __LINE__ __FILE__ alias and BEGIN begin break
|
|
11
|
-
case class def defined? do else elsif END end ensure false for if in module next nil
|
|
12
|
-
not or redo rescue retry return self super then true undef unless until when while yield)
|
|
13
|
-
DELEGATION_RESERVED_KEYWORDS = %w(_ arg args block)
|
|
14
|
-
DELEGATION_RESERVED_METHOD_NAMES = Set.new(
|
|
15
|
-
RUBY_RESERVED_KEYWORDS + DELEGATION_RESERVED_KEYWORDS
|
|
16
|
-
).freeze
|
|
4
|
+
require "active_support/delegation"
|
|
5
|
+
DelegationError = ActiveSupport::DelegationError # :nodoc:
|
|
17
6
|
|
|
18
7
|
# Provides a +delegate+ class method to easily expose contained objects'
|
|
19
8
|
# public methods as your own.
|
|
@@ -21,7 +10,7 @@ class Module
|
|
|
21
10
|
# ==== Options
|
|
22
11
|
# * <tt>:to</tt> - Specifies the target object name as a symbol or string
|
|
23
12
|
# * <tt>:prefix</tt> - Prefixes the new method with the target name or a custom prefix
|
|
24
|
-
# * <tt>:allow_nil</tt> - If set to true, prevents a +
|
|
13
|
+
# * <tt>:allow_nil</tt> - If set to true, prevents a +ActiveSupport::DelegationError+
|
|
25
14
|
# from being raised
|
|
26
15
|
# * <tt>:private</tt> - If set to true, changes method visibility to private
|
|
27
16
|
#
|
|
@@ -132,7 +121,7 @@ class Module
|
|
|
132
121
|
# User.new.age # => 2
|
|
133
122
|
#
|
|
134
123
|
# If the target is +nil+ and does not respond to the delegated method a
|
|
135
|
-
# +
|
|
124
|
+
# +ActiveSupport::DelegationError+ is raised. If you wish to instead return +nil+,
|
|
136
125
|
# use the <tt>:allow_nil</tt> option.
|
|
137
126
|
#
|
|
138
127
|
# class User < ActiveRecord::Base
|
|
@@ -141,7 +130,7 @@ class Module
|
|
|
141
130
|
# end
|
|
142
131
|
#
|
|
143
132
|
# User.new.age
|
|
144
|
-
# # =>
|
|
133
|
+
# # => ActiveSupport::DelegationError: User#age delegated to profile.age, but profile is nil
|
|
145
134
|
#
|
|
146
135
|
# But if not having a profile yet is fine and should not be an error
|
|
147
136
|
# condition:
|
|
@@ -169,104 +158,15 @@ class Module
|
|
|
169
158
|
#
|
|
170
159
|
# The target method must be public, otherwise it will raise +NoMethodError+.
|
|
171
160
|
def delegate(*methods, to: nil, prefix: nil, allow_nil: nil, private: nil)
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if prefix
|
|
182
|
-
"#{prefix == true ? to : prefix}_"
|
|
183
|
-
else
|
|
184
|
-
""
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
location = caller_locations(1, 1).first
|
|
188
|
-
file, line = location.path, location.lineno
|
|
189
|
-
|
|
190
|
-
receiver = to.to_s
|
|
191
|
-
receiver = "self.#{receiver}" if DELEGATION_RESERVED_METHOD_NAMES.include?(receiver)
|
|
192
|
-
|
|
193
|
-
method_def = []
|
|
194
|
-
method_names = []
|
|
195
|
-
|
|
196
|
-
method_def << "self.private" if private
|
|
197
|
-
|
|
198
|
-
methods.each do |method|
|
|
199
|
-
method_name = prefix ? "#{method_prefix}#{method}" : method
|
|
200
|
-
method_names << method_name.to_sym
|
|
201
|
-
|
|
202
|
-
# Attribute writer methods only accept one argument. Makes sure []=
|
|
203
|
-
# methods still accept two arguments.
|
|
204
|
-
definition = \
|
|
205
|
-
if /[^\]]=\z/.match?(method)
|
|
206
|
-
"arg"
|
|
207
|
-
else
|
|
208
|
-
method_object =
|
|
209
|
-
begin
|
|
210
|
-
if to.is_a?(Module)
|
|
211
|
-
to.method(method)
|
|
212
|
-
elsif receiver == "self.class"
|
|
213
|
-
method(method)
|
|
214
|
-
end
|
|
215
|
-
rescue NameError
|
|
216
|
-
# Do nothing. Fall back to `"..."`
|
|
217
|
-
end
|
|
218
|
-
|
|
219
|
-
if method_object
|
|
220
|
-
parameters = method_object.parameters
|
|
221
|
-
|
|
222
|
-
if (parameters.map(&:first) & [:opt, :rest, :keyreq, :key, :keyrest]).any?
|
|
223
|
-
"..."
|
|
224
|
-
else
|
|
225
|
-
defn = parameters.filter_map { |type, arg| arg if type == :req }
|
|
226
|
-
defn << "&block"
|
|
227
|
-
defn.join(", ")
|
|
228
|
-
end
|
|
229
|
-
else
|
|
230
|
-
"..."
|
|
231
|
-
end
|
|
232
|
-
end
|
|
233
|
-
|
|
234
|
-
# The following generated method calls the target exactly once, storing
|
|
235
|
-
# the returned value in a dummy variable.
|
|
236
|
-
#
|
|
237
|
-
# Reason is twofold: On one hand doing less calls is in general better.
|
|
238
|
-
# On the other hand it could be that the target has side-effects,
|
|
239
|
-
# whereas conceptually, from the user point of view, the delegator should
|
|
240
|
-
# be doing one call.
|
|
241
|
-
if allow_nil
|
|
242
|
-
method = method.to_s
|
|
243
|
-
|
|
244
|
-
method_def <<
|
|
245
|
-
"def #{method_name}(#{definition})" <<
|
|
246
|
-
" _ = #{receiver}" <<
|
|
247
|
-
" if !_.nil? || nil.respond_to?(:#{method})" <<
|
|
248
|
-
" _.#{method}(#{definition})" <<
|
|
249
|
-
" end" <<
|
|
250
|
-
"end"
|
|
251
|
-
else
|
|
252
|
-
method = method.to_s
|
|
253
|
-
method_name = method_name.to_s
|
|
254
|
-
|
|
255
|
-
method_def <<
|
|
256
|
-
"def #{method_name}(#{definition})" <<
|
|
257
|
-
" _ = #{receiver}" <<
|
|
258
|
-
" _.#{method}(#{definition})" <<
|
|
259
|
-
"rescue NoMethodError => e" <<
|
|
260
|
-
" if _.nil? && e.name == :#{method}" <<
|
|
261
|
-
%( raise DelegationError, "#{self}##{method_name} delegated to #{receiver}.#{method}, but #{receiver} is nil: \#{self.inspect}") <<
|
|
262
|
-
" else" <<
|
|
263
|
-
" raise" <<
|
|
264
|
-
" end" <<
|
|
265
|
-
"end"
|
|
266
|
-
end
|
|
267
|
-
end
|
|
268
|
-
module_eval(method_def.join(";"), file, line)
|
|
269
|
-
method_names
|
|
161
|
+
::ActiveSupport::Delegation.generate(
|
|
162
|
+
self,
|
|
163
|
+
methods,
|
|
164
|
+
location: caller_locations(1, 1).first,
|
|
165
|
+
to: to,
|
|
166
|
+
prefix: prefix,
|
|
167
|
+
allow_nil: allow_nil,
|
|
168
|
+
private: private,
|
|
169
|
+
)
|
|
270
170
|
end
|
|
271
171
|
|
|
272
172
|
# When building decorators, a common pattern may emerge:
|
|
@@ -308,7 +208,7 @@ class Module
|
|
|
308
208
|
# variables, methods, constants, etc.
|
|
309
209
|
#
|
|
310
210
|
# The delegated method must be public on the target, otherwise it will
|
|
311
|
-
# raise +DelegationError+. If you wish to instead return +nil+,
|
|
211
|
+
# raise +ActiveSupport::DelegationError+. If you wish to instead return +nil+,
|
|
312
212
|
# use the <tt>:allow_nil</tt> option.
|
|
313
213
|
#
|
|
314
214
|
# The <tt>marshal_dump</tt> and <tt>_dump</tt> methods are exempt from
|
|
@@ -316,53 +216,10 @@ class Module
|
|
|
316
216
|
# <tt>Marshal.dump(object)</tt>, should the delegation target method
|
|
317
217
|
# of <tt>object</tt> add or remove instance variables.
|
|
318
218
|
def delegate_missing_to(target, allow_nil: nil)
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
def respond_to_missing?(name, include_private = false)
|
|
325
|
-
# It may look like an oversight, but we deliberately do not pass
|
|
326
|
-
# +include_private+, because they do not get delegated.
|
|
327
|
-
|
|
328
|
-
return false if name == :marshal_dump || name == :_dump
|
|
329
|
-
#{target}.respond_to?(name) || super
|
|
330
|
-
end
|
|
331
|
-
|
|
332
|
-
def method_missing(method, *args, &block)
|
|
333
|
-
__target = #{target}
|
|
334
|
-
if __target.nil? && !nil.respond_to?(method)
|
|
335
|
-
nil
|
|
336
|
-
elsif __target.respond_to?(method)
|
|
337
|
-
__target.public_send(method, *args, &block)
|
|
338
|
-
else
|
|
339
|
-
super
|
|
340
|
-
end
|
|
341
|
-
end
|
|
342
|
-
ruby2_keywords(:method_missing)
|
|
343
|
-
RUBY
|
|
344
|
-
else
|
|
345
|
-
module_eval <<~RUBY, __FILE__, __LINE__ + 1
|
|
346
|
-
def respond_to_missing?(name, include_private = false)
|
|
347
|
-
# It may look like an oversight, but we deliberately do not pass
|
|
348
|
-
# +include_private+, because they do not get delegated.
|
|
349
|
-
|
|
350
|
-
return false if name == :marshal_dump || name == :_dump
|
|
351
|
-
#{target}.respond_to?(name) || super
|
|
352
|
-
end
|
|
353
|
-
|
|
354
|
-
def method_missing(method, *args, &block)
|
|
355
|
-
__target = #{target}
|
|
356
|
-
if __target.nil? && !nil.respond_to?(method)
|
|
357
|
-
raise DelegationError, "\#{method} delegated to #{target}, but #{target} is nil"
|
|
358
|
-
elsif __target.respond_to?(method)
|
|
359
|
-
__target.public_send(method, *args, &block)
|
|
360
|
-
else
|
|
361
|
-
super
|
|
362
|
-
end
|
|
363
|
-
end
|
|
364
|
-
ruby2_keywords(:method_missing)
|
|
365
|
-
RUBY
|
|
366
|
-
end
|
|
219
|
+
::ActiveSupport::Delegation.generate_method_missing(
|
|
220
|
+
self,
|
|
221
|
+
target,
|
|
222
|
+
allow_nil: allow_nil,
|
|
223
|
+
)
|
|
367
224
|
end
|
|
368
225
|
end
|
|
@@ -14,15 +14,12 @@ class Module
|
|
|
14
14
|
# Kernel.warn message
|
|
15
15
|
# end
|
|
16
16
|
# end
|
|
17
|
-
def deprecate(*method_names, deprecator
|
|
17
|
+
def deprecate(*method_names, deprecator:, **options)
|
|
18
18
|
if deprecator.is_a?(ActiveSupport::Deprecation)
|
|
19
19
|
deprecator.deprecate_methods(self, *method_names, **options)
|
|
20
20
|
elsif deprecator
|
|
21
21
|
# we just need any instance to call deprecate_methods, but the deprecation will be emitted by deprecator
|
|
22
22
|
ActiveSupport.deprecator.deprecate_methods(self, *method_names, **options, deprecator: deprecator)
|
|
23
|
-
else
|
|
24
|
-
ActiveSupport.deprecator.warn("Module.deprecate without a deprecator is deprecated")
|
|
25
|
-
ActiveSupport::Deprecation._instance.deprecate_methods(self, *method_names, **options)
|
|
26
23
|
end
|
|
27
24
|
end
|
|
28
25
|
end
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
require_relative "module/aliasing"
|
|
4
|
+
require_relative "module/introspection"
|
|
5
|
+
require_relative "module/anonymous"
|
|
6
|
+
require_relative "module/attribute_accessors"
|
|
7
|
+
require_relative "module/attribute_accessors_per_thread"
|
|
8
|
+
require_relative "module/attr_internal"
|
|
9
|
+
require_relative "module/concerning"
|
|
10
|
+
require_relative "module/delegation"
|
|
11
|
+
require_relative "module/deprecation"
|
|
12
|
+
require_relative "module/redefine_method"
|
|
13
|
+
require_relative "module/remove_method"
|
|
@@ -140,6 +140,6 @@ module ActiveSupport
|
|
|
140
140
|
end
|
|
141
141
|
end
|
|
142
142
|
|
|
143
|
-
Integer.
|
|
144
|
-
Float.
|
|
145
|
-
BigDecimal.
|
|
143
|
+
Integer.include ActiveSupport::NumericWithFormat
|
|
144
|
+
Float.include ActiveSupport::NumericWithFormat
|
|
145
|
+
BigDecimal.include ActiveSupport::NumericWithFormat
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
require_relative "numeric/bytes"
|
|
4
|
+
require_relative "numeric/time"
|
|
5
|
+
require_relative "numeric/conversions"
|
|
@@ -16,7 +16,7 @@ class Object
|
|
|
16
16
|
#
|
|
17
17
|
# @return [true, false]
|
|
18
18
|
def blank?
|
|
19
|
-
respond_to?(:empty?) ? !!empty? :
|
|
19
|
+
respond_to?(:empty?) ? !!empty? : false
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
# An object is present if it's not blank.
|
|
@@ -56,6 +56,10 @@ class NilClass
|
|
|
56
56
|
def blank?
|
|
57
57
|
true
|
|
58
58
|
end
|
|
59
|
+
|
|
60
|
+
def present? # :nodoc:
|
|
61
|
+
false
|
|
62
|
+
end
|
|
59
63
|
end
|
|
60
64
|
|
|
61
65
|
class FalseClass
|
|
@@ -67,6 +71,10 @@ class FalseClass
|
|
|
67
71
|
def blank?
|
|
68
72
|
true
|
|
69
73
|
end
|
|
74
|
+
|
|
75
|
+
def present? # :nodoc:
|
|
76
|
+
false
|
|
77
|
+
end
|
|
70
78
|
end
|
|
71
79
|
|
|
72
80
|
class TrueClass
|
|
@@ -78,6 +86,10 @@ class TrueClass
|
|
|
78
86
|
def blank?
|
|
79
87
|
false
|
|
80
88
|
end
|
|
89
|
+
|
|
90
|
+
def present? # :nodoc:
|
|
91
|
+
true
|
|
92
|
+
end
|
|
81
93
|
end
|
|
82
94
|
|
|
83
95
|
class Array
|
|
@@ -88,6 +100,10 @@ class Array
|
|
|
88
100
|
#
|
|
89
101
|
# @return [true, false]
|
|
90
102
|
alias_method :blank?, :empty?
|
|
103
|
+
|
|
104
|
+
def present? # :nodoc:
|
|
105
|
+
!empty?
|
|
106
|
+
end
|
|
91
107
|
end
|
|
92
108
|
|
|
93
109
|
class Hash
|
|
@@ -98,6 +114,22 @@ class Hash
|
|
|
98
114
|
#
|
|
99
115
|
# @return [true, false]
|
|
100
116
|
alias_method :blank?, :empty?
|
|
117
|
+
|
|
118
|
+
def present? # :nodoc:
|
|
119
|
+
!empty?
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
class Symbol
|
|
124
|
+
# A Symbol is blank if it's empty:
|
|
125
|
+
#
|
|
126
|
+
# :''.blank? # => true
|
|
127
|
+
# :symbol.blank? # => false
|
|
128
|
+
alias_method :blank?, :empty?
|
|
129
|
+
|
|
130
|
+
def present? # :nodoc:
|
|
131
|
+
!empty?
|
|
132
|
+
end
|
|
101
133
|
end
|
|
102
134
|
|
|
103
135
|
class String
|
|
@@ -129,6 +161,10 @@ class String
|
|
|
129
161
|
ENCODED_BLANKS[self.encoding].match?(self)
|
|
130
162
|
end
|
|
131
163
|
end
|
|
164
|
+
|
|
165
|
+
def present? # :nodoc:
|
|
166
|
+
!blank?
|
|
167
|
+
end
|
|
132
168
|
end
|
|
133
169
|
|
|
134
170
|
class Numeric # :nodoc:
|
|
@@ -141,6 +177,10 @@ class Numeric # :nodoc:
|
|
|
141
177
|
def blank?
|
|
142
178
|
false
|
|
143
179
|
end
|
|
180
|
+
|
|
181
|
+
def present?
|
|
182
|
+
true
|
|
183
|
+
end
|
|
144
184
|
end
|
|
145
185
|
|
|
146
186
|
class Time # :nodoc:
|
|
@@ -152,4 +192,8 @@ class Time # :nodoc:
|
|
|
152
192
|
def blank?
|
|
153
193
|
false
|
|
154
194
|
end
|
|
195
|
+
|
|
196
|
+
def present?
|
|
197
|
+
true
|
|
198
|
+
end
|
|
155
199
|
end
|
|
@@ -17,24 +17,16 @@ class Object
|
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
instance_variables.map(&:name)
|
|
32
|
-
end
|
|
33
|
-
else
|
|
34
|
-
def instance_variable_names
|
|
35
|
-
variables = instance_variables
|
|
36
|
-
variables.map! { |s| s.to_s.freeze }
|
|
37
|
-
variables
|
|
38
|
-
end
|
|
20
|
+
# Returns an array of instance variable names as strings including "@".
|
|
21
|
+
#
|
|
22
|
+
# class C
|
|
23
|
+
# def initialize(x, y)
|
|
24
|
+
# @x, @y = x, y
|
|
25
|
+
# end
|
|
26
|
+
# end
|
|
27
|
+
#
|
|
28
|
+
# C.new(0, 1).instance_variable_names # => ["@y", "@x"]
|
|
29
|
+
def instance_variable_names
|
|
30
|
+
instance_variables.map(&:name)
|
|
39
31
|
end
|
|
40
32
|
end
|
|
@@ -46,7 +46,7 @@ module ActiveSupport
|
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
[Enumerable, Object, Array, FalseClass, Float, Hash, Integer, NilClass, String, TrueClass].reverse_each do |klass|
|
|
49
|
-
klass.
|
|
49
|
+
klass.include(ActiveSupport::ToJsonWithActiveSupportEncoder)
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
class Module
|
|
@@ -65,11 +65,9 @@ class Object
|
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
to_h.as_json(options)
|
|
72
|
-
end
|
|
68
|
+
class Data # :nodoc:
|
|
69
|
+
def as_json(options = nil)
|
|
70
|
+
to_h.as_json(options)
|
|
73
71
|
end
|
|
74
72
|
end
|
|
75
73
|
|
|
@@ -105,7 +103,7 @@ end
|
|
|
105
103
|
|
|
106
104
|
class Symbol
|
|
107
105
|
def as_json(options = nil) # :nodoc:
|
|
108
|
-
|
|
106
|
+
name
|
|
109
107
|
end
|
|
110
108
|
end
|
|
111
109
|
|
|
@@ -164,7 +162,12 @@ end
|
|
|
164
162
|
|
|
165
163
|
class Array
|
|
166
164
|
def as_json(options = nil) # :nodoc:
|
|
167
|
-
|
|
165
|
+
if options
|
|
166
|
+
options = options.dup.freeze unless options.frozen?
|
|
167
|
+
map { |v| v.as_json(options) }
|
|
168
|
+
else
|
|
169
|
+
map { |v| v.as_json }
|
|
170
|
+
end
|
|
168
171
|
end
|
|
169
172
|
end
|
|
170
173
|
|
|
@@ -184,8 +187,11 @@ class Hash
|
|
|
184
187
|
end
|
|
185
188
|
|
|
186
189
|
result = {}
|
|
187
|
-
|
|
188
|
-
|
|
190
|
+
if options
|
|
191
|
+
options = options.dup.freeze unless options.frozen?
|
|
192
|
+
subset.each { |k, v| result[k.to_s] = v.as_json(options) }
|
|
193
|
+
else
|
|
194
|
+
subset.each { |k, v| result[k.to_s] = v.as_json }
|
|
189
195
|
end
|
|
190
196
|
result
|
|
191
197
|
end
|
|
@@ -234,9 +240,16 @@ class Pathname # :nodoc:
|
|
|
234
240
|
end
|
|
235
241
|
|
|
236
242
|
unless IPAddr.method_defined?(:as_json, false)
|
|
243
|
+
# Use `IPAddr#as_json` from the IPAddr gem if the version is 1.2.7 or higher.
|
|
237
244
|
class IPAddr # :nodoc:
|
|
238
245
|
def as_json(options = nil)
|
|
239
|
-
|
|
246
|
+
if ipv4? && prefix == 32
|
|
247
|
+
to_s
|
|
248
|
+
elsif ipv6? && prefix == 128
|
|
249
|
+
to_s
|
|
250
|
+
else
|
|
251
|
+
"#{self}/#{prefix}"
|
|
252
|
+
end
|
|
240
253
|
end
|
|
241
254
|
end
|
|
242
255
|
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "cgi"
|
|
3
|
+
require "cgi/escape"
|
|
4
|
+
require "cgi/util" if RUBY_VERSION < "3.5"
|
|
4
5
|
|
|
5
6
|
class Object
|
|
6
7
|
# Alias of <tt>to_s</tt>.
|
|
@@ -16,6 +17,11 @@ class Object
|
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
class NilClass
|
|
20
|
+
# Returns a CGI-escaped +key+.
|
|
21
|
+
def to_query(key)
|
|
22
|
+
CGI.escape(key.to_param)
|
|
23
|
+
end
|
|
24
|
+
|
|
19
25
|
# Returns +self+.
|
|
20
26
|
def to_param
|
|
21
27
|
self
|
|
@@ -145,14 +145,14 @@ class NilClass
|
|
|
145
145
|
#
|
|
146
146
|
# With +try+
|
|
147
147
|
# @person.try(:children).try(:first).try(:name)
|
|
148
|
-
def try(
|
|
148
|
+
def try(*, &)
|
|
149
149
|
nil
|
|
150
150
|
end
|
|
151
151
|
|
|
152
152
|
# Calling +try!+ on +nil+ always returns +nil+.
|
|
153
153
|
#
|
|
154
154
|
# nil.try!(:name) # => nil
|
|
155
|
-
def try!(
|
|
155
|
+
def try!(*, &)
|
|
156
156
|
nil
|
|
157
157
|
end
|
|
158
158
|
end
|