omg-activesupport 8.0.0.alpha1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +86 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +40 -0
- data/lib/active_support/actionable_error.rb +50 -0
- data/lib/active_support/all.rb +5 -0
- data/lib/active_support/array_inquirer.rb +50 -0
- data/lib/active_support/backtrace_cleaner.rb +163 -0
- data/lib/active_support/benchmark.rb +21 -0
- data/lib/active_support/benchmarkable.rb +53 -0
- data/lib/active_support/broadcast_logger.rb +251 -0
- data/lib/active_support/builder.rb +8 -0
- 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 +244 -0
- data/lib/active_support/cache/mem_cache_store.rb +290 -0
- data/lib/active_support/cache/memory_store.rb +262 -0
- data/lib/active_support/cache/null_store.rb +62 -0
- data/lib/active_support/cache/redis_cache_store.rb +492 -0
- data/lib/active_support/cache/serializer_with_fallback.rb +152 -0
- data/lib/active_support/cache/strategy/local_cache.rb +201 -0
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +45 -0
- data/lib/active_support/cache.rb +1104 -0
- data/lib/active_support/callbacks.rb +944 -0
- data/lib/active_support/class_attribute.rb +26 -0
- data/lib/active_support/code_generator.rb +79 -0
- data/lib/active_support/concern.rb +217 -0
- data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +72 -0
- data/lib/active_support/concurrency/null_lock.rb +13 -0
- data/lib/active_support/concurrency/share_lock.rb +225 -0
- data/lib/active_support/configurable.rb +159 -0
- data/lib/active_support/configuration_file.rb +60 -0
- data/lib/active_support/core_ext/array/access.rb +100 -0
- data/lib/active_support/core_ext/array/conversions.rb +213 -0
- data/lib/active_support/core_ext/array/extract.rb +21 -0
- data/lib/active_support/core_ext/array/extract_options.rb +31 -0
- data/lib/active_support/core_ext/array/grouping.rb +109 -0
- data/lib/active_support/core_ext/array/inquiry.rb +19 -0
- data/lib/active_support/core_ext/array/wrap.rb +48 -0
- data/lib/active_support/core_ext/array.rb +9 -0
- data/lib/active_support/core_ext/benchmark.rb +13 -0
- data/lib/active_support/core_ext/big_decimal/conversions.rb +14 -0
- data/lib/active_support/core_ext/big_decimal.rb +3 -0
- data/lib/active_support/core_ext/class/attribute.rb +122 -0
- data/lib/active_support/core_ext/class/attribute_accessors.rb +6 -0
- data/lib/active_support/core_ext/class/subclasses.rb +24 -0
- data/lib/active_support/core_ext/class.rb +4 -0
- data/lib/active_support/core_ext/date/acts_like.rb +10 -0
- data/lib/active_support/core_ext/date/blank.rb +18 -0
- data/lib/active_support/core_ext/date/calculations.rb +161 -0
- data/lib/active_support/core_ext/date/conversions.rb +98 -0
- data/lib/active_support/core_ext/date/zones.rb +8 -0
- data/lib/active_support/core_ext/date.rb +7 -0
- data/lib/active_support/core_ext/date_and_time/calculations.rb +374 -0
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +58 -0
- data/lib/active_support/core_ext/date_and_time/zones.rb +40 -0
- data/lib/active_support/core_ext/date_time/acts_like.rb +16 -0
- data/lib/active_support/core_ext/date_time/blank.rb +18 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +215 -0
- data/lib/active_support/core_ext/date_time/compatibility.rb +18 -0
- data/lib/active_support/core_ext/date_time/conversions.rb +106 -0
- data/lib/active_support/core_ext/date_time.rb +7 -0
- data/lib/active_support/core_ext/digest/uuid.rb +76 -0
- data/lib/active_support/core_ext/digest.rb +3 -0
- data/lib/active_support/core_ext/enumerable.rb +267 -0
- data/lib/active_support/core_ext/erb/util.rb +201 -0
- data/lib/active_support/core_ext/file/atomic.rb +72 -0
- data/lib/active_support/core_ext/file.rb +3 -0
- data/lib/active_support/core_ext/hash/conversions.rb +262 -0
- data/lib/active_support/core_ext/hash/deep_merge.rb +42 -0
- data/lib/active_support/core_ext/hash/deep_transform_values.rb +46 -0
- data/lib/active_support/core_ext/hash/except.rb +12 -0
- data/lib/active_support/core_ext/hash/indifferent_access.rb +24 -0
- data/lib/active_support/core_ext/hash/keys.rb +143 -0
- data/lib/active_support/core_ext/hash/reverse_merge.rb +25 -0
- data/lib/active_support/core_ext/hash/slice.rb +27 -0
- data/lib/active_support/core_ext/hash.rb +10 -0
- data/lib/active_support/core_ext/integer/inflections.rb +31 -0
- data/lib/active_support/core_ext/integer/multiple.rb +12 -0
- data/lib/active_support/core_ext/integer/time.rb +22 -0
- data/lib/active_support/core_ext/integer.rb +5 -0
- data/lib/active_support/core_ext/kernel/concern.rb +14 -0
- data/lib/active_support/core_ext/kernel/reporting.rb +45 -0
- data/lib/active_support/core_ext/kernel/singleton_class.rb +8 -0
- data/lib/active_support/core_ext/kernel.rb +5 -0
- data/lib/active_support/core_ext/load_error.rb +9 -0
- data/lib/active_support/core_ext/module/aliasing.rb +31 -0
- data/lib/active_support/core_ext/module/anonymous.rb +30 -0
- data/lib/active_support/core_ext/module/attr_internal.rb +49 -0
- data/lib/active_support/core_ext/module/attribute_accessors.rb +214 -0
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +175 -0
- data/lib/active_support/core_ext/module/concerning.rb +140 -0
- data/lib/active_support/core_ext/module/delegation.rb +225 -0
- data/lib/active_support/core_ext/module/deprecation.rb +25 -0
- data/lib/active_support/core_ext/module/introspection.rb +62 -0
- data/lib/active_support/core_ext/module/redefine_method.rb +40 -0
- data/lib/active_support/core_ext/module/remove_method.rb +17 -0
- data/lib/active_support/core_ext/module.rb +13 -0
- data/lib/active_support/core_ext/name_error.rb +59 -0
- data/lib/active_support/core_ext/numeric/bytes.rb +75 -0
- data/lib/active_support/core_ext/numeric/conversions.rb +145 -0
- data/lib/active_support/core_ext/numeric/time.rb +66 -0
- data/lib/active_support/core_ext/numeric.rb +5 -0
- data/lib/active_support/core_ext/object/acts_like.rb +45 -0
- data/lib/active_support/core_ext/object/blank.rb +199 -0
- data/lib/active_support/core_ext/object/conversions.rb +6 -0
- data/lib/active_support/core_ext/object/deep_dup.rb +71 -0
- data/lib/active_support/core_ext/object/duplicable.rb +69 -0
- data/lib/active_support/core_ext/object/inclusion.rb +37 -0
- data/lib/active_support/core_ext/object/instance_variables.rb +32 -0
- data/lib/active_support/core_ext/object/json.rb +260 -0
- data/lib/active_support/core_ext/object/to_param.rb +3 -0
- data/lib/active_support/core_ext/object/to_query.rb +87 -0
- data/lib/active_support/core_ext/object/try.rb +158 -0
- data/lib/active_support/core_ext/object/with.rb +46 -0
- data/lib/active_support/core_ext/object/with_options.rb +101 -0
- data/lib/active_support/core_ext/object.rb +17 -0
- data/lib/active_support/core_ext/pathname/blank.rb +20 -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 +57 -0
- data/lib/active_support/core_ext/range/conversions.rb +62 -0
- data/lib/active_support/core_ext/range/each.rb +24 -0
- data/lib/active_support/core_ext/range/overlap.rb +40 -0
- data/lib/active_support/core_ext/range.rb +6 -0
- data/lib/active_support/core_ext/regexp.rb +14 -0
- data/lib/active_support/core_ext/securerandom.rb +41 -0
- data/lib/active_support/core_ext/string/access.rb +95 -0
- data/lib/active_support/core_ext/string/behavior.rb +8 -0
- data/lib/active_support/core_ext/string/conversions.rb +60 -0
- data/lib/active_support/core_ext/string/exclude.rb +13 -0
- data/lib/active_support/core_ext/string/filters.rb +151 -0
- data/lib/active_support/core_ext/string/indent.rb +45 -0
- data/lib/active_support/core_ext/string/inflections.rb +300 -0
- data/lib/active_support/core_ext/string/inquiry.rb +16 -0
- data/lib/active_support/core_ext/string/multibyte.rb +58 -0
- data/lib/active_support/core_ext/string/output_safety.rb +228 -0
- data/lib/active_support/core_ext/string/starts_ends_with.rb +6 -0
- data/lib/active_support/core_ext/string/strip.rb +27 -0
- data/lib/active_support/core_ext/string/zones.rb +16 -0
- data/lib/active_support/core_ext/string.rb +15 -0
- 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/acts_like.rb +10 -0
- data/lib/active_support/core_ext/time/calculations.rb +386 -0
- data/lib/active_support/core_ext/time/compatibility.rb +32 -0
- data/lib/active_support/core_ext/time/conversions.rb +75 -0
- data/lib/active_support/core_ext/time/zones.rb +97 -0
- data/lib/active_support/core_ext/time.rb +7 -0
- data/lib/active_support/core_ext.rb +5 -0
- data/lib/active_support/current_attributes/test_helper.rb +13 -0
- data/lib/active_support/current_attributes.rb +233 -0
- data/lib/active_support/deep_mergeable.rb +53 -0
- data/lib/active_support/delegation.rb +202 -0
- data/lib/active_support/dependencies/autoload.rb +72 -0
- data/lib/active_support/dependencies/interlock.rb +49 -0
- data/lib/active_support/dependencies/require_dependency.rb +28 -0
- data/lib/active_support/dependencies.rb +98 -0
- data/lib/active_support/deprecation/behaviors.rb +148 -0
- data/lib/active_support/deprecation/constant_accessor.rb +74 -0
- data/lib/active_support/deprecation/deprecators.rb +104 -0
- data/lib/active_support/deprecation/disallowed.rb +54 -0
- data/lib/active_support/deprecation/method_wrappers.rb +68 -0
- data/lib/active_support/deprecation/proxy_wrappers.rb +189 -0
- data/lib/active_support/deprecation/reporting.rb +179 -0
- data/lib/active_support/deprecation.rb +81 -0
- data/lib/active_support/deprecator.rb +7 -0
- data/lib/active_support/descendants_tracker.rb +112 -0
- data/lib/active_support/digest.rb +22 -0
- data/lib/active_support/duration/iso8601_parser.rb +123 -0
- data/lib/active_support/duration/iso8601_serializer.rb +64 -0
- data/lib/active_support/duration.rb +520 -0
- data/lib/active_support/encrypted_configuration.rb +126 -0
- data/lib/active_support/encrypted_file.rb +133 -0
- 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 +265 -0
- data/lib/active_support/evented_file_update_checker.rb +182 -0
- 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 +150 -0
- data/lib/active_support/executor/test_helper.rb +7 -0
- data/lib/active_support/executor.rb +8 -0
- data/lib/active_support/file_update_checker.rb +164 -0
- data/lib/active_support/fork_tracker.rb +43 -0
- data/lib/active_support/gem_version.rb +17 -0
- data/lib/active_support/gzip.rb +40 -0
- data/lib/active_support/hash_with_indifferent_access.rb +445 -0
- data/lib/active_support/html_safe_translation.rb +56 -0
- data/lib/active_support/i18n.rb +17 -0
- data/lib/active_support/i18n_railtie.rb +138 -0
- data/lib/active_support/inflections.rb +72 -0
- data/lib/active_support/inflector/inflections.rb +273 -0
- data/lib/active_support/inflector/methods.rb +387 -0
- data/lib/active_support/inflector/transliterate.rb +149 -0
- data/lib/active_support/inflector.rb +9 -0
- data/lib/active_support/isolated_execution_state.rb +75 -0
- data/lib/active_support/json/decoding.rb +76 -0
- data/lib/active_support/json/encoding.rb +120 -0
- data/lib/active_support/json.rb +4 -0
- data/lib/active_support/key_generator.rb +66 -0
- data/lib/active_support/lazy_load_hooks.rb +107 -0
- data/lib/active_support/locale/en.rb +33 -0
- data/lib/active_support/locale/en.yml +141 -0
- data/lib/active_support/log_subscriber/test_helper.rb +106 -0
- data/lib/active_support/log_subscriber.rb +192 -0
- data/lib/active_support/logger.rb +55 -0
- data/lib/active_support/logger_silence.rb +21 -0
- data/lib/active_support/logger_thread_safe_level.rb +47 -0
- data/lib/active_support/message_encryptor.rb +374 -0
- 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 +305 -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 +368 -0
- 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 +146 -0
- data/lib/active_support/messages/rotation_configuration.rb +23 -0
- data/lib/active_support/messages/rotation_coordinator.rb +93 -0
- data/lib/active_support/messages/rotator.rb +59 -0
- data/lib/active_support/messages/serializer_with_fallback.rb +158 -0
- data/lib/active_support/multibyte/chars.rb +178 -0
- data/lib/active_support/multibyte/unicode.rb +42 -0
- data/lib/active_support/multibyte.rb +23 -0
- data/lib/active_support/notifications/fanout.rb +446 -0
- data/lib/active_support/notifications/instrumenter.rb +240 -0
- data/lib/active_support/notifications.rb +281 -0
- data/lib/active_support/number_helper/number_converter.rb +190 -0
- data/lib/active_support/number_helper/number_to_currency_converter.rb +46 -0
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +30 -0
- data/lib/active_support/number_helper/number_to_human_converter.rb +69 -0
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +60 -0
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +16 -0
- data/lib/active_support/number_helper/number_to_phone_converter.rb +60 -0
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +59 -0
- data/lib/active_support/number_helper/rounding_helper.rb +46 -0
- data/lib/active_support/number_helper.rb +479 -0
- data/lib/active_support/option_merger.rb +38 -0
- data/lib/active_support/ordered_hash.rb +50 -0
- data/lib/active_support/ordered_options.rb +147 -0
- data/lib/active_support/parameter_filter.rb +157 -0
- data/lib/active_support/proxy_object.rb +20 -0
- data/lib/active_support/rails.rb +26 -0
- data/lib/active_support/railtie.rb +161 -0
- data/lib/active_support/reloader.rb +138 -0
- data/lib/active_support/rescuable.rb +176 -0
- data/lib/active_support/secure_compare_rotator.rb +58 -0
- data/lib/active_support/security_utils.rb +38 -0
- data/lib/active_support/string_inquirer.rb +35 -0
- data/lib/active_support/subscriber.rb +146 -0
- data/lib/active_support/syntax_error_proxy.rb +60 -0
- data/lib/active_support/tagged_logging.rb +152 -0
- data/lib/active_support/test_case.rb +304 -0
- data/lib/active_support/testing/assertions.rb +332 -0
- data/lib/active_support/testing/autorun.rb +5 -0
- data/lib/active_support/testing/constant_lookup.rb +51 -0
- data/lib/active_support/testing/constant_stubbing.rb +54 -0
- data/lib/active_support/testing/declarative.rb +28 -0
- data/lib/active_support/testing/deprecation.rb +82 -0
- data/lib/active_support/testing/error_reporter_assertions.rb +107 -0
- data/lib/active_support/testing/file_fixtures.rb +38 -0
- data/lib/active_support/testing/isolation.rb +121 -0
- data/lib/active_support/testing/method_call_assertions.rb +69 -0
- data/lib/active_support/testing/parallelization/server.rb +85 -0
- data/lib/active_support/testing/parallelization/worker.rb +103 -0
- data/lib/active_support/testing/parallelization.rb +55 -0
- data/lib/active_support/testing/parallelize_executor.rb +81 -0
- data/lib/active_support/testing/setup_and_teardown.rb +57 -0
- data/lib/active_support/testing/stream.rb +41 -0
- data/lib/active_support/testing/strict_warnings.rb +43 -0
- data/lib/active_support/testing/tagged_logging.rb +27 -0
- data/lib/active_support/testing/tests_without_assertions.rb +19 -0
- data/lib/active_support/testing/time_helpers.rb +269 -0
- data/lib/active_support/time.rb +20 -0
- data/lib/active_support/time_with_zone.rb +609 -0
- data/lib/active_support/values/time_zone.rb +614 -0
- data/lib/active_support/version.rb +10 -0
- data/lib/active_support/xml_mini/jdom.rb +175 -0
- data/lib/active_support/xml_mini/libxml.rb +80 -0
- data/lib/active_support/xml_mini/libxmlsax.rb +83 -0
- data/lib/active_support/xml_mini/nokogiri.rb +83 -0
- data/lib/active_support/xml_mini/nokogirisax.rb +86 -0
- data/lib/active_support/xml_mini/rexml.rb +137 -0
- data/lib/active_support/xml_mini.rb +211 -0
- data/lib/active_support.rb +144 -0
- metadata +526 -0
@@ -0,0 +1,189 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
class Deprecation
|
5
|
+
class DeprecationProxy # :nodoc:
|
6
|
+
def self.new(*args, **kwargs, &block)
|
7
|
+
object = args.first
|
8
|
+
|
9
|
+
return object unless object
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
instance_methods.each { |m| undef_method m unless /^__|^object_id$/.match?(m) }
|
14
|
+
|
15
|
+
# Don't give a deprecation warning on inspect since test/unit and error
|
16
|
+
# logs rely on it for diagnostics.
|
17
|
+
def inspect
|
18
|
+
target.inspect
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def method_missing(called, *args, &block)
|
23
|
+
warn caller_locations, called, args
|
24
|
+
target.__send__(called, *args, &block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# DeprecatedObjectProxy transforms an object into a deprecated one. It takes an object, a deprecation message, and
|
29
|
+
# a deprecator.
|
30
|
+
#
|
31
|
+
# deprecated_object = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(Object.new, "This object is now deprecated", ActiveSupport::Deprecation.new)
|
32
|
+
# # => #<Object:0x007fb9b34c34b0>
|
33
|
+
#
|
34
|
+
# deprecated_object.to_s
|
35
|
+
# DEPRECATION WARNING: This object is now deprecated.
|
36
|
+
# (Backtrace)
|
37
|
+
# # => "#<Object:0x007fb9b34c34b0>"
|
38
|
+
class DeprecatedObjectProxy < DeprecationProxy
|
39
|
+
def initialize(object, message, deprecator)
|
40
|
+
@object = object
|
41
|
+
@message = message
|
42
|
+
@deprecator = deprecator
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
def target
|
47
|
+
@object
|
48
|
+
end
|
49
|
+
|
50
|
+
def warn(callstack, called, args)
|
51
|
+
@deprecator.warn(@message, callstack)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# DeprecatedInstanceVariableProxy transforms an instance variable into a deprecated one. It takes an instance of a
|
56
|
+
# class, a method on that class, an instance variable, and a deprecator as the last argument.
|
57
|
+
#
|
58
|
+
# Trying to use the deprecated instance variable will result in a deprecation warning, pointing to the method as a
|
59
|
+
# replacement.
|
60
|
+
#
|
61
|
+
# class Example
|
62
|
+
# def initialize
|
63
|
+
# @request = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :request, :@request, ActiveSupport::Deprecation.new)
|
64
|
+
# @_request = :special_request
|
65
|
+
# end
|
66
|
+
#
|
67
|
+
# def request
|
68
|
+
# @_request
|
69
|
+
# end
|
70
|
+
#
|
71
|
+
# def old_request
|
72
|
+
# @request
|
73
|
+
# end
|
74
|
+
# end
|
75
|
+
#
|
76
|
+
# example = Example.new
|
77
|
+
# # => #<Example:0x007fb9b31090b8 @_request=:special_request, @request=:special_request>
|
78
|
+
#
|
79
|
+
# example.old_request.to_s
|
80
|
+
# # => DEPRECATION WARNING: @request is deprecated! Call request.to_s instead of
|
81
|
+
# @request.to_s
|
82
|
+
# (Backtrace information…)
|
83
|
+
# "special_request"
|
84
|
+
#
|
85
|
+
# example.request.to_s
|
86
|
+
# # => "special_request"
|
87
|
+
class DeprecatedInstanceVariableProxy < DeprecationProxy
|
88
|
+
def initialize(instance, method, var = "@#{method}", deprecator:)
|
89
|
+
@instance = instance
|
90
|
+
@method = method
|
91
|
+
@var = var
|
92
|
+
@deprecator = deprecator
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
def target
|
97
|
+
@instance.__send__(@method)
|
98
|
+
end
|
99
|
+
|
100
|
+
def warn(callstack, called, args)
|
101
|
+
@deprecator.warn("#{@var} is deprecated! Call #{@method}.#{called} instead of #{@var}.#{called}. Args: #{args.inspect}", callstack)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
# DeprecatedConstantProxy transforms a constant into a deprecated one. It takes the full names of an old
|
106
|
+
# (deprecated) constant and of a new constant (both in string form) and a deprecator. The deprecated constant now
|
107
|
+
# returns the value of the new one.
|
108
|
+
#
|
109
|
+
# PLANETS = %w(mercury venus earth mars jupiter saturn uranus neptune pluto)
|
110
|
+
#
|
111
|
+
# # (In a later update, the original implementation of `PLANETS` has been removed.)
|
112
|
+
#
|
113
|
+
# PLANETS_POST_2006 = %w(mercury venus earth mars jupiter saturn uranus neptune)
|
114
|
+
# PLANETS = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("PLANETS", "PLANETS_POST_2006", ActiveSupport::Deprecation.new)
|
115
|
+
#
|
116
|
+
# PLANETS.map { |planet| planet.capitalize }
|
117
|
+
# # => DEPRECATION WARNING: PLANETS is deprecated! Use PLANETS_POST_2006 instead.
|
118
|
+
# (Backtrace information…)
|
119
|
+
# ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"]
|
120
|
+
class DeprecatedConstantProxy < Module
|
121
|
+
def self.new(*args, **options, &block)
|
122
|
+
object = args.first
|
123
|
+
|
124
|
+
return object unless object
|
125
|
+
super
|
126
|
+
end
|
127
|
+
|
128
|
+
def initialize(old_const, new_const, deprecator, message: "#{old_const} is deprecated! Use #{new_const} instead.")
|
129
|
+
Kernel.require "active_support/inflector/methods"
|
130
|
+
|
131
|
+
@old_const = old_const
|
132
|
+
@new_const = new_const
|
133
|
+
@deprecator = deprecator
|
134
|
+
@message = message
|
135
|
+
end
|
136
|
+
|
137
|
+
instance_methods.each { |m| undef_method m unless /^__|^object_id$/.match?(m) }
|
138
|
+
|
139
|
+
# Don't give a deprecation warning on inspect since test/unit and error
|
140
|
+
# logs rely on it for diagnostics.
|
141
|
+
def inspect
|
142
|
+
target.inspect
|
143
|
+
end
|
144
|
+
|
145
|
+
# Don't give a deprecation warning on methods that IRB may invoke
|
146
|
+
# during tab-completion.
|
147
|
+
delegate :hash, :instance_methods, :name, :respond_to?, to: :target
|
148
|
+
|
149
|
+
# Returns the class of the new constant.
|
150
|
+
#
|
151
|
+
# PLANETS_POST_2006 = %w(mercury venus earth mars jupiter saturn uranus neptune)
|
152
|
+
# PLANETS = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('PLANETS', 'PLANETS_POST_2006')
|
153
|
+
# PLANETS.class # => Array
|
154
|
+
def class
|
155
|
+
target.class
|
156
|
+
end
|
157
|
+
|
158
|
+
def append_features(base)
|
159
|
+
@deprecator.warn(@message, caller_locations)
|
160
|
+
base.include(target)
|
161
|
+
end
|
162
|
+
|
163
|
+
def prepend_features(base)
|
164
|
+
@deprecator.warn(@message, caller_locations)
|
165
|
+
base.prepend(target)
|
166
|
+
end
|
167
|
+
|
168
|
+
def extended(base)
|
169
|
+
@deprecator.warn(@message, caller_locations)
|
170
|
+
base.extend(target)
|
171
|
+
end
|
172
|
+
|
173
|
+
private
|
174
|
+
def target
|
175
|
+
ActiveSupport::Inflector.constantize(@new_const.to_s)
|
176
|
+
end
|
177
|
+
|
178
|
+
def const_missing(name)
|
179
|
+
@deprecator.warn(@message, caller_locations)
|
180
|
+
target.const_get(name)
|
181
|
+
end
|
182
|
+
|
183
|
+
def method_missing(...)
|
184
|
+
@deprecator.warn(@message, caller_locations)
|
185
|
+
target.__send__(...)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
@@ -0,0 +1,179 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rbconfig"
|
4
|
+
|
5
|
+
module ActiveSupport
|
6
|
+
class Deprecation
|
7
|
+
module Reporting
|
8
|
+
# Whether to print a message (silent mode)
|
9
|
+
attr_writer :silenced
|
10
|
+
# Name of gem where method is deprecated
|
11
|
+
attr_accessor :gem_name
|
12
|
+
|
13
|
+
# Outputs a deprecation warning to the output configured by
|
14
|
+
# ActiveSupport::Deprecation#behavior.
|
15
|
+
#
|
16
|
+
# ActiveSupport::Deprecation.new.warn('something broke!')
|
17
|
+
# # => "DEPRECATION WARNING: something broke! (called from your_code.rb:1)"
|
18
|
+
def warn(message = nil, callstack = nil)
|
19
|
+
return if silenced
|
20
|
+
|
21
|
+
callstack ||= caller_locations(2)
|
22
|
+
deprecation_message(callstack, message).tap do |full_message|
|
23
|
+
if deprecation_disallowed?(message)
|
24
|
+
disallowed_behavior.each { |b| b.call(full_message, callstack, self) }
|
25
|
+
else
|
26
|
+
behavior.each { |b| b.call(full_message, callstack, self) }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Silence deprecation warnings within the block.
|
32
|
+
#
|
33
|
+
# deprecator = ActiveSupport::Deprecation.new
|
34
|
+
# deprecator.warn('something broke!')
|
35
|
+
# # => "DEPRECATION WARNING: something broke! (called from your_code.rb:1)"
|
36
|
+
#
|
37
|
+
# deprecator.silence do
|
38
|
+
# deprecator.warn('something broke!')
|
39
|
+
# end
|
40
|
+
# # => nil
|
41
|
+
def silence(&block)
|
42
|
+
begin_silence
|
43
|
+
block.call
|
44
|
+
ensure
|
45
|
+
end_silence
|
46
|
+
end
|
47
|
+
|
48
|
+
def begin_silence # :nodoc:
|
49
|
+
@silence_counter.value += 1
|
50
|
+
end
|
51
|
+
|
52
|
+
def end_silence # :nodoc:
|
53
|
+
@silence_counter.value -= 1
|
54
|
+
end
|
55
|
+
|
56
|
+
def silenced
|
57
|
+
@silenced || @silence_counter.value.nonzero?
|
58
|
+
end
|
59
|
+
|
60
|
+
# Allow previously disallowed deprecation warnings within the block.
|
61
|
+
# <tt>allowed_warnings</tt> can be an array containing strings, symbols, or regular
|
62
|
+
# expressions. (Symbols are treated as strings). These are compared against
|
63
|
+
# the text of deprecation warning messages generated within the block.
|
64
|
+
# Matching warnings will be exempt from the rules set by
|
65
|
+
# ActiveSupport::Deprecation#disallowed_warnings.
|
66
|
+
#
|
67
|
+
# The optional <tt>if:</tt> argument accepts a truthy/falsy value or an object that
|
68
|
+
# responds to <tt>.call</tt>. If truthy, then matching warnings will be allowed.
|
69
|
+
# If falsey then the method yields to the block without allowing the warning.
|
70
|
+
#
|
71
|
+
# deprecator = ActiveSupport::Deprecation.new
|
72
|
+
# deprecator.disallowed_behavior = :raise
|
73
|
+
# deprecator.disallowed_warnings = [
|
74
|
+
# "something broke"
|
75
|
+
# ]
|
76
|
+
#
|
77
|
+
# deprecator.warn('something broke!')
|
78
|
+
# # => ActiveSupport::DeprecationException
|
79
|
+
#
|
80
|
+
# deprecator.allow ['something broke'] do
|
81
|
+
# deprecator.warn('something broke!')
|
82
|
+
# end
|
83
|
+
# # => nil
|
84
|
+
#
|
85
|
+
# deprecator.allow ['something broke'], if: Rails.env.production? do
|
86
|
+
# deprecator.warn('something broke!')
|
87
|
+
# end
|
88
|
+
# # => ActiveSupport::DeprecationException for dev/test, nil for production
|
89
|
+
def allow(allowed_warnings = :all, if: true, &block)
|
90
|
+
conditional = binding.local_variable_get(:if)
|
91
|
+
conditional = conditional.call if conditional.respond_to?(:call)
|
92
|
+
if conditional
|
93
|
+
@explicitly_allowed_warnings.bind(allowed_warnings, &block)
|
94
|
+
else
|
95
|
+
yield
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def deprecation_warning(deprecated_method_name, message = nil, caller_backtrace = nil)
|
100
|
+
caller_backtrace ||= caller_locations(2)
|
101
|
+
deprecated_method_warning(deprecated_method_name, message).tap do |msg|
|
102
|
+
warn(msg, caller_backtrace)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
# Outputs a deprecation warning message
|
108
|
+
#
|
109
|
+
# deprecated_method_warning(:method_name)
|
110
|
+
# # => "method_name is deprecated and will be removed from Rails #{deprecation_horizon}"
|
111
|
+
# deprecated_method_warning(:method_name, :another_method)
|
112
|
+
# # => "method_name is deprecated and will be removed from Rails #{deprecation_horizon} (use another_method instead)"
|
113
|
+
# deprecated_method_warning(:method_name, "Optional message")
|
114
|
+
# # => "method_name is deprecated and will be removed from Rails #{deprecation_horizon} (Optional message)"
|
115
|
+
def deprecated_method_warning(method_name, message = nil)
|
116
|
+
warning = "#{method_name} is deprecated and will be removed from #{gem_name} #{deprecation_horizon}"
|
117
|
+
case message
|
118
|
+
when Symbol then "#{warning} (use #{message} instead)"
|
119
|
+
when String then "#{warning} (#{message})"
|
120
|
+
else warning
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def deprecation_message(callstack, message = nil)
|
125
|
+
message ||= "You are using deprecated behavior which will be removed from the next major or minor release."
|
126
|
+
"DEPRECATION WARNING: #{message} #{deprecation_caller_message(callstack)}"
|
127
|
+
end
|
128
|
+
|
129
|
+
def deprecation_caller_message(callstack)
|
130
|
+
file, line, method = extract_callstack(callstack)
|
131
|
+
if file
|
132
|
+
if line && method
|
133
|
+
"(called from #{method} at #{file}:#{line})"
|
134
|
+
else
|
135
|
+
"(called from #{file}:#{line})"
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def extract_callstack(callstack)
|
141
|
+
return [] if callstack.empty?
|
142
|
+
return _extract_callstack(callstack) if callstack.first.is_a? String
|
143
|
+
|
144
|
+
offending_line = callstack.find { |frame|
|
145
|
+
# Code generated with `eval` doesn't have an `absolute_path`, e.g. templates.
|
146
|
+
path = frame.absolute_path || frame.path
|
147
|
+
path && !ignored_callstack?(path)
|
148
|
+
} || callstack.first
|
149
|
+
|
150
|
+
[offending_line.path, offending_line.lineno, offending_line.label]
|
151
|
+
end
|
152
|
+
|
153
|
+
def _extract_callstack(callstack)
|
154
|
+
ActiveSupport.deprecator.warn(<<~MESSAGE)
|
155
|
+
Passing the result of `caller` to ActiveSupport::Deprecation#warn is deprecated and will be removed in Rails 8.0.
|
156
|
+
|
157
|
+
Please pass the result of `caller_locations` instead.
|
158
|
+
MESSAGE
|
159
|
+
|
160
|
+
offending_line = callstack.find { |line| !ignored_callstack?(line) } || callstack.first
|
161
|
+
|
162
|
+
if offending_line
|
163
|
+
if md = offending_line.match(/^(.+?):(\d+)(?::in `(.*?)')?/)
|
164
|
+
md.captures
|
165
|
+
else
|
166
|
+
offending_line
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
RAILS_GEM_ROOT = File.expand_path("../../../..", __dir__) + "/" # :nodoc:
|
172
|
+
LIB_DIR = RbConfig::CONFIG["libdir"] # :nodoc:
|
173
|
+
|
174
|
+
def ignored_callstack?(path)
|
175
|
+
path.start_with?(RAILS_GEM_ROOT, LIB_DIR) || path.include?("<internal:")
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
# = Active Support \Deprecation
|
5
|
+
#
|
6
|
+
# \Deprecation specifies the API used by \Rails to deprecate methods, instance variables, objects, and constants. It's
|
7
|
+
# also available for gems or applications.
|
8
|
+
#
|
9
|
+
# For a gem, use Deprecation.new to create a Deprecation object and store it in your module or class (in order for
|
10
|
+
# users to be able to configure it).
|
11
|
+
#
|
12
|
+
# module MyLibrary
|
13
|
+
# def self.deprecator
|
14
|
+
# @deprecator ||= ActiveSupport::Deprecation.new("2.0", "MyLibrary")
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# For a Railtie or Engine, you may also want to add it to the application's deprecators, so that the application's
|
19
|
+
# configuration can be applied to it.
|
20
|
+
#
|
21
|
+
# module MyLibrary
|
22
|
+
# class Railtie < Rails::Railtie
|
23
|
+
# initializer "my_library.deprecator" do |app|
|
24
|
+
# app.deprecators[:my_library] = MyLibrary.deprecator
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
#
|
29
|
+
# With the above initializer, configuration settings like the following will affect +MyLibrary.deprecator+:
|
30
|
+
#
|
31
|
+
# # in config/environments/test.rb
|
32
|
+
# config.active_support.deprecation = :raise
|
33
|
+
class Deprecation
|
34
|
+
# active_support.rb sets an autoload for ActiveSupport::Deprecation.
|
35
|
+
#
|
36
|
+
# If these requires were at the top of the file the constant would not be
|
37
|
+
# defined by the time their files were loaded. Since some of them reopen
|
38
|
+
# ActiveSupport::Deprecation its autoload would be triggered, resulting in
|
39
|
+
# a circular require warning for active_support/deprecation.rb.
|
40
|
+
#
|
41
|
+
# So, we define the constant first, and load dependencies later.
|
42
|
+
require "active_support/deprecation/behaviors"
|
43
|
+
require "active_support/deprecation/reporting"
|
44
|
+
require "active_support/deprecation/disallowed"
|
45
|
+
require "active_support/deprecation/constant_accessor"
|
46
|
+
require "active_support/deprecation/method_wrappers"
|
47
|
+
require "active_support/deprecation/proxy_wrappers"
|
48
|
+
require "active_support/deprecation/deprecators"
|
49
|
+
require "active_support/core_ext/module/deprecation"
|
50
|
+
require "concurrent/atomic/thread_local_var"
|
51
|
+
|
52
|
+
include Behavior
|
53
|
+
include Reporting
|
54
|
+
include Disallowed
|
55
|
+
include MethodWrapper
|
56
|
+
|
57
|
+
MUTEX = Mutex.new # :nodoc:
|
58
|
+
private_constant :MUTEX
|
59
|
+
|
60
|
+
def self._instance # :nodoc:
|
61
|
+
@_instance ||= MUTEX.synchronize { @_instance ||= new }
|
62
|
+
end
|
63
|
+
|
64
|
+
# The version number in which the deprecated behavior will be removed, by default.
|
65
|
+
attr_accessor :deprecation_horizon
|
66
|
+
|
67
|
+
# It accepts two parameters on initialization. The first is a version of library
|
68
|
+
# and the second is a library name.
|
69
|
+
#
|
70
|
+
# ActiveSupport::Deprecation.new('2.0', 'MyLibrary')
|
71
|
+
def initialize(deprecation_horizon = "8.1", gem_name = "Rails")
|
72
|
+
self.gem_name = gem_name
|
73
|
+
self.deprecation_horizon = deprecation_horizon
|
74
|
+
# By default, warnings are not silenced and debugging is off.
|
75
|
+
self.silenced = false
|
76
|
+
self.debug = false
|
77
|
+
@silence_counter = Concurrent::ThreadLocalVar.new(0)
|
78
|
+
@explicitly_allowed_warnings = Concurrent::ThreadLocalVar.new(nil)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "weakref"
|
4
|
+
|
5
|
+
module ActiveSupport
|
6
|
+
# = Active Support Descendants Tracker
|
7
|
+
#
|
8
|
+
# This module provides an internal implementation to track descendants
|
9
|
+
# which is faster than iterating through +ObjectSpace+.
|
10
|
+
#
|
11
|
+
# However Ruby 3.1 provide a fast native +Class#subclasses+ method,
|
12
|
+
# so if you know your code won't be executed on older rubies, including
|
13
|
+
# +ActiveSupport::DescendantsTracker+ does not provide any benefit.
|
14
|
+
module DescendantsTracker
|
15
|
+
@clear_disabled = false
|
16
|
+
|
17
|
+
if RUBY_ENGINE == "ruby"
|
18
|
+
# On MRI `ObjectSpace::WeakMap` keys are weak references.
|
19
|
+
# So we can simply use WeakMap as a `Set`.
|
20
|
+
class WeakSet < ObjectSpace::WeakMap # :nodoc:
|
21
|
+
alias_method :to_a, :keys
|
22
|
+
|
23
|
+
def <<(object)
|
24
|
+
self[object] = true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
else
|
28
|
+
# On TruffleRuby `ObjectSpace::WeakMap` keys are strong references.
|
29
|
+
# So we use `object_id` as a key and the actual object as a value.
|
30
|
+
#
|
31
|
+
# JRuby for now doesn't have Class#descendant, but when it will, it will likely
|
32
|
+
# have the same WeakMap semantic than Truffle so we future proof this as much as possible.
|
33
|
+
class WeakSet # :nodoc:
|
34
|
+
def initialize
|
35
|
+
@map = ObjectSpace::WeakMap.new
|
36
|
+
end
|
37
|
+
|
38
|
+
def [](object)
|
39
|
+
@map.key?(object.object_id)
|
40
|
+
end
|
41
|
+
alias_method :include?, :[]
|
42
|
+
|
43
|
+
def []=(object, _present)
|
44
|
+
@map[object.object_id] = object
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_a
|
48
|
+
@map.values
|
49
|
+
end
|
50
|
+
|
51
|
+
def <<(object)
|
52
|
+
self[object] = true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
@excluded_descendants = WeakSet.new
|
57
|
+
|
58
|
+
module ReloadedClassesFiltering # :nodoc:
|
59
|
+
def subclasses
|
60
|
+
DescendantsTracker.reject!(super)
|
61
|
+
end
|
62
|
+
|
63
|
+
def descendants
|
64
|
+
DescendantsTracker.reject!(super)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
class << self
|
69
|
+
def disable_clear! # :nodoc:
|
70
|
+
unless @clear_disabled
|
71
|
+
@clear_disabled = true
|
72
|
+
ReloadedClassesFiltering.remove_method(:subclasses)
|
73
|
+
ReloadedClassesFiltering.remove_method(:descendants)
|
74
|
+
@excluded_descendants = nil
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def clear(classes) # :nodoc:
|
79
|
+
raise "DescendantsTracker.clear was disabled because config.enable_reloading is false" if @clear_disabled
|
80
|
+
|
81
|
+
classes.each do |klass|
|
82
|
+
@excluded_descendants << klass
|
83
|
+
klass.descendants.each do |descendant|
|
84
|
+
@excluded_descendants << descendant
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def reject!(classes) # :nodoc:
|
90
|
+
if @excluded_descendants
|
91
|
+
classes.reject! { |d| @excluded_descendants.include?(d) }
|
92
|
+
end
|
93
|
+
classes
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
class << self
|
98
|
+
def subclasses(klass)
|
99
|
+
klass.subclasses
|
100
|
+
end
|
101
|
+
|
102
|
+
def descendants(klass)
|
103
|
+
klass.descendants
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def descendants
|
108
|
+
subclasses = DescendantsTracker.reject!(self.subclasses)
|
109
|
+
subclasses.concat(subclasses.flat_map(&:descendants))
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "openssl"
|
4
|
+
|
5
|
+
module ActiveSupport
|
6
|
+
class Digest # :nodoc:
|
7
|
+
class << self
|
8
|
+
def hash_digest_class
|
9
|
+
@hash_digest_class ||= OpenSSL::Digest::MD5
|
10
|
+
end
|
11
|
+
|
12
|
+
def hash_digest_class=(klass)
|
13
|
+
raise ArgumentError, "#{klass} is expected to implement hexdigest class method" unless klass.respond_to?(:hexdigest)
|
14
|
+
@hash_digest_class = klass
|
15
|
+
end
|
16
|
+
|
17
|
+
def hexdigest(arg)
|
18
|
+
hash_digest_class.hexdigest(arg)[0...32]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|