activesupport 4.2.11.1 → 6.0.3.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activesupport might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +399 -411
- data/MIT-LICENSE +2 -2
- data/README.rdoc +7 -7
- data/lib/active_support/actionable_error.rb +48 -0
- data/lib/active_support/all.rb +5 -3
- data/lib/active_support/array_inquirer.rb +48 -0
- data/lib/active_support/backtrace_cleaner.rb +34 -6
- data/lib/active_support/benchmarkable.rb +6 -4
- data/lib/active_support/builder.rb +3 -1
- data/lib/active_support/cache/file_store.rb +58 -53
- data/lib/active_support/cache/mem_cache_store.rb +95 -91
- data/lib/active_support/cache/memory_store.rb +39 -36
- data/lib/active_support/cache/null_store.rb +11 -7
- data/lib/active_support/cache/redis_cache_store.rb +493 -0
- data/lib/active_support/cache/strategy/local_cache.rb +75 -42
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +10 -9
- data/lib/active_support/cache.rb +331 -217
- data/lib/active_support/callbacks.rb +650 -592
- data/lib/active_support/concern.rb +35 -6
- data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +35 -0
- data/lib/active_support/concurrency/share_lock.rb +226 -0
- data/lib/active_support/configurable.rb +13 -14
- data/lib/active_support/core_ext/array/access.rb +41 -1
- data/lib/active_support/core_ext/array/conversions.rb +24 -20
- data/lib/active_support/core_ext/array/extract.rb +21 -0
- data/lib/active_support/core_ext/array/extract_options.rb +2 -0
- data/lib/active_support/core_ext/array/grouping.rb +11 -18
- data/lib/active_support/core_ext/array/inquiry.rb +19 -0
- data/lib/active_support/core_ext/array/prepend_and_append.rb +4 -6
- data/lib/active_support/core_ext/array/wrap.rb +7 -4
- data/lib/active_support/core_ext/array.rb +9 -6
- data/lib/active_support/core_ext/benchmark.rb +3 -1
- data/lib/active_support/core_ext/big_decimal/conversions.rb +10 -12
- data/lib/active_support/core_ext/big_decimal.rb +3 -1
- data/lib/active_support/core_ext/class/attribute.rb +45 -31
- data/lib/active_support/core_ext/class/attribute_accessors.rb +3 -1
- data/lib/active_support/core_ext/class/subclasses.rb +20 -6
- data/lib/active_support/core_ext/class.rb +4 -3
- data/lib/active_support/core_ext/date/acts_like.rb +3 -1
- data/lib/active_support/core_ext/date/blank.rb +14 -0
- data/lib/active_support/core_ext/date/calculations.rb +17 -14
- data/lib/active_support/core_ext/date/conversions.rb +25 -23
- data/lib/active_support/core_ext/date/zones.rb +4 -2
- data/lib/active_support/core_ext/date.rb +6 -4
- data/lib/active_support/core_ext/date_and_time/calculations.rb +154 -65
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +4 -3
- data/lib/active_support/core_ext/date_and_time/zones.rb +12 -13
- data/lib/active_support/core_ext/date_time/acts_like.rb +4 -2
- data/lib/active_support/core_ext/date_time/blank.rb +14 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +37 -19
- data/lib/active_support/core_ext/date_time/compatibility.rb +8 -6
- data/lib/active_support/core_ext/date_time/conversions.rb +16 -13
- data/lib/active_support/core_ext/date_time.rb +7 -5
- data/lib/active_support/core_ext/digest/uuid.rb +7 -5
- data/lib/active_support/core_ext/digest.rb +3 -0
- data/lib/active_support/core_ext/enumerable.rb +114 -22
- data/lib/active_support/core_ext/file/atomic.rb +38 -31
- data/lib/active_support/core_ext/file.rb +3 -1
- data/lib/active_support/core_ext/hash/compact.rb +4 -23
- data/lib/active_support/core_ext/hash/conversions.rb +62 -41
- data/lib/active_support/core_ext/hash/deep_merge.rb +9 -13
- data/lib/active_support/core_ext/hash/deep_transform_values.rb +46 -0
- data/lib/active_support/core_ext/hash/except.rb +12 -9
- data/lib/active_support/core_ext/hash/indifferent_access.rb +4 -3
- data/lib/active_support/core_ext/hash/keys.rb +19 -42
- data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
- data/lib/active_support/core_ext/hash/slice.rb +5 -27
- data/lib/active_support/core_ext/hash/transform_values.rb +4 -22
- data/lib/active_support/core_ext/hash.rb +10 -9
- data/lib/active_support/core_ext/integer/inflections.rb +3 -1
- data/lib/active_support/core_ext/integer/multiple.rb +3 -1
- data/lib/active_support/core_ext/integer/time.rb +11 -18
- data/lib/active_support/core_ext/integer.rb +5 -3
- data/lib/active_support/core_ext/kernel/concern.rb +5 -1
- data/lib/active_support/core_ext/kernel/reporting.rb +4 -84
- data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
- data/lib/active_support/core_ext/kernel.rb +5 -5
- data/lib/active_support/core_ext/load_error.rb +3 -22
- data/lib/active_support/core_ext/marshal.rb +8 -8
- data/lib/active_support/core_ext/module/aliasing.rb +6 -44
- data/lib/active_support/core_ext/module/anonymous.rb +12 -1
- data/lib/active_support/core_ext/module/attr_internal.rb +8 -9
- data/lib/active_support/core_ext/module/attribute_accessors.rb +46 -46
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +144 -0
- data/lib/active_support/core_ext/module/concerning.rb +11 -12
- data/lib/active_support/core_ext/module/delegation.rb +133 -30
- data/lib/active_support/core_ext/module/deprecation.rb +4 -2
- data/lib/active_support/core_ext/module/introspection.rb +44 -19
- data/lib/active_support/core_ext/module/reachable.rb +5 -7
- data/lib/active_support/core_ext/module/redefine_method.rb +40 -0
- data/lib/active_support/core_ext/module/remove_method.rb +8 -3
- data/lib/active_support/core_ext/module.rb +13 -11
- data/lib/active_support/core_ext/name_error.rb +22 -2
- data/lib/active_support/core_ext/numeric/bytes.rb +22 -0
- data/lib/active_support/core_ext/numeric/conversions.rb +129 -136
- data/lib/active_support/core_ext/numeric/inquiry.rb +5 -0
- data/lib/active_support/core_ext/numeric/time.rb +35 -23
- data/lib/active_support/core_ext/numeric.rb +5 -3
- data/lib/active_support/core_ext/object/acts_like.rb +12 -1
- data/lib/active_support/core_ext/object/blank.rb +27 -3
- data/lib/active_support/core_ext/object/conversions.rb +6 -4
- data/lib/active_support/core_ext/object/deep_dup.rb +13 -4
- data/lib/active_support/core_ext/object/duplicable.rb +13 -93
- data/lib/active_support/core_ext/object/inclusion.rb +5 -3
- data/lib/active_support/core_ext/object/instance_variables.rb +3 -1
- data/lib/active_support/core_ext/object/json.rb +51 -20
- data/lib/active_support/core_ext/object/to_param.rb +3 -1
- data/lib/active_support/core_ext/object/to_query.rb +10 -5
- data/lib/active_support/core_ext/object/try.rb +81 -23
- data/lib/active_support/core_ext/object/with_options.rb +16 -3
- data/lib/active_support/core_ext/object.rb +14 -13
- data/lib/active_support/core_ext/range/compare_range.rb +76 -0
- data/lib/active_support/core_ext/range/conversions.rb +37 -15
- data/lib/active_support/core_ext/range/each.rb +18 -17
- data/lib/active_support/core_ext/range/include_range.rb +7 -21
- data/lib/active_support/core_ext/range/include_time_with_zone.rb +23 -0
- data/lib/active_support/core_ext/range/overlaps.rb +2 -0
- data/lib/active_support/core_ext/range.rb +7 -4
- data/lib/active_support/core_ext/regexp.rb +2 -0
- data/lib/active_support/core_ext/securerandom.rb +45 -0
- data/lib/active_support/core_ext/string/access.rb +16 -6
- data/lib/active_support/core_ext/string/behavior.rb +3 -1
- data/lib/active_support/core_ext/string/conversions.rb +7 -4
- data/lib/active_support/core_ext/string/exclude.rb +2 -0
- data/lib/active_support/core_ext/string/filters.rb +48 -6
- data/lib/active_support/core_ext/string/indent.rb +6 -4
- data/lib/active_support/core_ext/string/inflections.rb +66 -24
- data/lib/active_support/core_ext/string/inquiry.rb +3 -1
- data/lib/active_support/core_ext/string/multibyte.rb +16 -7
- data/lib/active_support/core_ext/string/output_safety.rb +93 -40
- data/lib/active_support/core_ext/string/starts_ends_with.rb +2 -0
- data/lib/active_support/core_ext/string/strip.rb +6 -5
- data/lib/active_support/core_ext/string/zones.rb +4 -2
- data/lib/active_support/core_ext/string.rb +15 -13
- data/lib/active_support/core_ext/time/acts_like.rb +3 -1
- data/lib/active_support/core_ext/time/calculations.rb +115 -52
- data/lib/active_support/core_ext/time/compatibility.rb +4 -2
- data/lib/active_support/core_ext/time/conversions.rb +20 -13
- data/lib/active_support/core_ext/time/zones.rb +41 -7
- data/lib/active_support/core_ext/time.rb +7 -6
- data/lib/active_support/core_ext/uri.rb +6 -7
- data/lib/active_support/core_ext.rb +3 -1
- data/lib/active_support/current_attributes.rb +203 -0
- data/lib/active_support/dependencies/autoload.rb +2 -0
- data/lib/active_support/dependencies/interlock.rb +57 -0
- data/lib/active_support/dependencies/zeitwerk_integration.rb +117 -0
- data/lib/active_support/dependencies.rb +208 -166
- data/lib/active_support/deprecation/behaviors.rb +44 -11
- data/lib/active_support/deprecation/constant_accessor.rb +52 -0
- data/lib/active_support/deprecation/instance_delegator.rb +17 -2
- data/lib/active_support/deprecation/method_wrappers.rb +61 -21
- data/lib/active_support/deprecation/proxy_wrappers.rb +81 -30
- data/lib/active_support/deprecation/reporting.rb +32 -12
- data/lib/active_support/deprecation.rb +12 -9
- data/lib/active_support/descendants_tracker.rb +57 -9
- data/lib/active_support/digest.rb +20 -0
- data/lib/active_support/duration/iso8601_parser.rb +123 -0
- data/lib/active_support/duration/iso8601_serializer.rb +53 -0
- data/lib/active_support/duration.rb +315 -40
- data/lib/active_support/encrypted_configuration.rb +45 -0
- data/lib/active_support/encrypted_file.rb +100 -0
- data/lib/active_support/evented_file_update_checker.rb +234 -0
- data/lib/active_support/execution_wrapper.rb +129 -0
- data/lib/active_support/executor.rb +8 -0
- data/lib/active_support/file_update_checker.rb +62 -37
- data/lib/active_support/gem_version.rb +6 -4
- data/lib/active_support/gzip.rb +7 -5
- data/lib/active_support/hash_with_indifferent_access.rb +129 -30
- data/lib/active_support/i18n.rb +9 -6
- data/lib/active_support/i18n_railtie.rb +50 -14
- data/lib/active_support/inflections.rb +13 -11
- data/lib/active_support/inflector/inflections.rb +58 -13
- data/lib/active_support/inflector/methods.rb +159 -145
- data/lib/active_support/inflector/transliterate.rb +84 -34
- data/lib/active_support/inflector.rb +7 -5
- data/lib/active_support/json/decoding.rb +32 -30
- data/lib/active_support/json/encoding.rb +17 -60
- data/lib/active_support/json.rb +4 -2
- data/lib/active_support/key_generator.rb +11 -43
- data/lib/active_support/lazy_load_hooks.rb +53 -20
- data/lib/active_support/locale/en.rb +33 -0
- data/lib/active_support/locale/en.yml +2 -0
- data/lib/active_support/log_subscriber/test_helper.rb +14 -12
- data/lib/active_support/log_subscriber.rb +44 -19
- data/lib/active_support/logger.rb +9 -23
- data/lib/active_support/logger_silence.rb +32 -14
- data/lib/active_support/logger_thread_safe_level.rb +32 -8
- data/lib/active_support/message_encryptor.rb +166 -53
- data/lib/active_support/message_verifier.rb +149 -16
- data/lib/active_support/messages/metadata.rb +72 -0
- data/lib/active_support/messages/rotation_configuration.rb +22 -0
- data/lib/active_support/messages/rotator.rb +56 -0
- data/lib/active_support/multibyte/chars.rb +56 -63
- data/lib/active_support/multibyte/unicode.rb +56 -290
- data/lib/active_support/multibyte.rb +4 -2
- data/lib/active_support/notifications/fanout.rb +109 -22
- data/lib/active_support/notifications/instrumenter.rb +107 -16
- data/lib/active_support/notifications.rb +51 -10
- data/lib/active_support/number_helper/number_converter.rb +16 -15
- data/lib/active_support/number_helper/number_to_currency_converter.rb +14 -15
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +11 -4
- data/lib/active_support/number_helper/number_to_human_converter.rb +13 -10
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +11 -9
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +5 -1
- data/lib/active_support/number_helper/number_to_phone_converter.rb +15 -5
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +25 -57
- data/lib/active_support/number_helper/rounding_helper.rb +66 -0
- data/lib/active_support/number_helper.rb +105 -68
- data/lib/active_support/option_merger.rb +24 -4
- data/lib/active_support/ordered_hash.rb +7 -5
- data/lib/active_support/ordered_options.rb +27 -5
- data/lib/active_support/parameter_filter.rb +128 -0
- data/lib/active_support/per_thread_registry.rb +9 -4
- data/lib/active_support/proxy_object.rb +2 -0
- data/lib/active_support/rails.rb +10 -8
- data/lib/active_support/railtie.rb +43 -9
- data/lib/active_support/reloader.rb +130 -0
- data/lib/active_support/rescuable.rb +108 -53
- data/lib/active_support/security_utils.rb +15 -11
- data/lib/active_support/string_inquirer.rb +11 -4
- data/lib/active_support/subscriber.rb +74 -30
- data/lib/active_support/tagged_logging.rb +25 -13
- data/lib/active_support/test_case.rb +107 -44
- data/lib/active_support/testing/assertions.rb +151 -20
- data/lib/active_support/testing/autorun.rb +4 -2
- data/lib/active_support/testing/constant_lookup.rb +2 -1
- data/lib/active_support/testing/declarative.rb +3 -1
- data/lib/active_support/testing/deprecation.rb +13 -10
- data/lib/active_support/testing/file_fixtures.rb +38 -0
- data/lib/active_support/testing/isolation.rb +35 -26
- data/lib/active_support/testing/method_call_assertions.rb +70 -0
- data/lib/active_support/testing/parallelization.rb +134 -0
- data/lib/active_support/testing/setup_and_teardown.rb +13 -8
- data/lib/active_support/testing/stream.rb +43 -0
- data/lib/active_support/testing/tagged_logging.rb +3 -1
- data/lib/active_support/testing/time_helpers.rb +84 -20
- data/lib/active_support/time.rb +14 -12
- data/lib/active_support/time_with_zone.rb +179 -39
- data/lib/active_support/values/time_zone.rb +203 -63
- data/lib/active_support/version.rb +3 -1
- data/lib/active_support/xml_mini/jdom.rb +116 -115
- data/lib/active_support/xml_mini/libxml.rb +16 -13
- data/lib/active_support/xml_mini/libxmlsax.rb +15 -14
- data/lib/active_support/xml_mini/nokogiri.rb +14 -12
- data/lib/active_support/xml_mini/nokogirisax.rb +14 -13
- data/lib/active_support/xml_mini/rexml.rb +11 -9
- data/lib/active_support/xml_mini.rb +38 -46
- data/lib/active_support.rb +13 -11
- metadata +84 -26
- data/lib/active_support/concurrency/latch.rb +0 -27
- data/lib/active_support/core_ext/big_decimal/yaml_conversions.rb +0 -16
- data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -45
- data/lib/active_support/core_ext/date_time/zones.rb +0 -6
- data/lib/active_support/core_ext/kernel/agnostics.rb +0 -11
- data/lib/active_support/core_ext/kernel/debugger.rb +0 -10
- data/lib/active_support/core_ext/module/method_transplanting.rb +0 -13
- data/lib/active_support/core_ext/module/qualified_const.rb +0 -52
- data/lib/active_support/core_ext/object/itself.rb +0 -15
- data/lib/active_support/core_ext/struct.rb +0 -6
- data/lib/active_support/core_ext/thread.rb +0 -86
- data/lib/active_support/core_ext/time/marshal.rb +0 -30
- data/lib/active_support/values/unicode_tables.dat +0 -0
@@ -1,43 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support/notifications"
|
2
4
|
|
3
5
|
module ActiveSupport
|
6
|
+
# Raised when <tt>ActiveSupport::Deprecation::Behavior#behavior</tt> is set with <tt>:raise</tt>.
|
7
|
+
# You would set <tt>:raise</tt>, as a behavior to raise errors and proactively report exceptions from deprecations.
|
4
8
|
class DeprecationException < StandardError
|
5
9
|
end
|
6
10
|
|
7
11
|
class Deprecation
|
8
12
|
# Default warning behaviors per Rails.env.
|
9
13
|
DEFAULT_BEHAVIORS = {
|
10
|
-
raise: ->(message, callstack) {
|
14
|
+
raise: ->(message, callstack, deprecation_horizon, gem_name) {
|
11
15
|
e = DeprecationException.new(message)
|
12
|
-
e.set_backtrace(callstack)
|
16
|
+
e.set_backtrace(callstack.map(&:to_s))
|
13
17
|
raise e
|
14
18
|
},
|
15
19
|
|
16
|
-
stderr: ->(message, callstack) {
|
20
|
+
stderr: ->(message, callstack, deprecation_horizon, gem_name) {
|
17
21
|
$stderr.puts(message)
|
18
22
|
$stderr.puts callstack.join("\n ") if debug
|
19
23
|
},
|
20
24
|
|
21
|
-
log: ->(message, callstack) {
|
25
|
+
log: ->(message, callstack, deprecation_horizon, gem_name) {
|
22
26
|
logger =
|
23
27
|
if defined?(Rails.logger) && Rails.logger
|
24
28
|
Rails.logger
|
25
29
|
else
|
26
|
-
require
|
30
|
+
require "active_support/logger"
|
27
31
|
ActiveSupport::Logger.new($stderr)
|
28
32
|
end
|
29
33
|
logger.warn message
|
30
34
|
logger.debug callstack.join("\n ") if debug
|
31
35
|
},
|
32
36
|
|
33
|
-
notify: ->(message, callstack) {
|
34
|
-
|
35
|
-
|
37
|
+
notify: ->(message, callstack, deprecation_horizon, gem_name) {
|
38
|
+
notification_name = "deprecation.#{gem_name.underscore.tr('/', '_')}"
|
39
|
+
ActiveSupport::Notifications.instrument(notification_name,
|
40
|
+
message: message,
|
41
|
+
callstack: callstack,
|
42
|
+
gem_name: gem_name,
|
43
|
+
deprecation_horizon: deprecation_horizon)
|
36
44
|
},
|
37
45
|
|
38
|
-
silence: ->(message, callstack) {},
|
46
|
+
silence: ->(message, callstack, deprecation_horizon, gem_name) { },
|
39
47
|
}
|
40
48
|
|
49
|
+
# Behavior module allows to determine how to display deprecation messages.
|
50
|
+
# You can create a custom behavior or set any from the +DEFAULT_BEHAVIORS+
|
51
|
+
# constant. Available behaviors are:
|
52
|
+
#
|
53
|
+
# [+raise+] Raise <tt>ActiveSupport::DeprecationException</tt>.
|
54
|
+
# [+stderr+] Log all deprecation warnings to +$stderr+.
|
55
|
+
# [+log+] Log all deprecation warnings to +Rails.logger+.
|
56
|
+
# [+notify+] Use +ActiveSupport::Notifications+ to notify +deprecation.rails+.
|
57
|
+
# [+silence+] Do nothing.
|
58
|
+
#
|
59
|
+
# Setting behaviors only affects deprecations that happen after boot time.
|
60
|
+
# For more information you can read the documentation of the +behavior=+ method.
|
41
61
|
module Behavior
|
42
62
|
# Whether to print a backtrace along with the warning.
|
43
63
|
attr_accessor :debug
|
@@ -65,12 +85,25 @@ module ActiveSupport
|
|
65
85
|
# ActiveSupport::Deprecation.behavior = :stderr
|
66
86
|
# ActiveSupport::Deprecation.behavior = [:stderr, :log]
|
67
87
|
# ActiveSupport::Deprecation.behavior = MyCustomHandler
|
68
|
-
# ActiveSupport::Deprecation.behavior = ->(message, callstack) {
|
88
|
+
# ActiveSupport::Deprecation.behavior = ->(message, callstack, deprecation_horizon, gem_name) {
|
69
89
|
# # custom stuff
|
70
90
|
# }
|
71
91
|
def behavior=(behavior)
|
72
|
-
@behavior = Array(behavior).map { |b| DEFAULT_BEHAVIORS[b] || b }
|
92
|
+
@behavior = Array(behavior).map { |b| DEFAULT_BEHAVIORS[b] || arity_coerce(b) }
|
73
93
|
end
|
94
|
+
|
95
|
+
private
|
96
|
+
def arity_coerce(behavior)
|
97
|
+
unless behavior.respond_to?(:call)
|
98
|
+
raise ArgumentError, "#{behavior.inspect} is not a valid deprecation behavior."
|
99
|
+
end
|
100
|
+
|
101
|
+
if behavior.arity == 4 || behavior.arity == -1
|
102
|
+
behavior
|
103
|
+
else
|
104
|
+
-> message, callstack, _, _ { behavior.call(message, callstack) }
|
105
|
+
end
|
106
|
+
end
|
74
107
|
end
|
75
108
|
end
|
76
109
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
class Deprecation
|
5
|
+
# DeprecatedConstantAccessor transforms a constant into a deprecated one by
|
6
|
+
# hooking +const_missing+.
|
7
|
+
#
|
8
|
+
# It takes the names of an old (deprecated) constant and of a new constant
|
9
|
+
# (both in string form) and optionally a deprecator. The deprecator defaults
|
10
|
+
# to +ActiveSupport::Deprecator+ if none is specified.
|
11
|
+
#
|
12
|
+
# The deprecated constant now returns the same object as the new one rather
|
13
|
+
# than a proxy object, so it can be used transparently in +rescue+ blocks
|
14
|
+
# etc.
|
15
|
+
#
|
16
|
+
# PLANETS = %w(mercury venus earth mars jupiter saturn uranus neptune pluto)
|
17
|
+
#
|
18
|
+
# # (In a later update, the original implementation of `PLANETS` has been removed.)
|
19
|
+
#
|
20
|
+
# PLANETS_POST_2006 = %w(mercury venus earth mars jupiter saturn uranus neptune)
|
21
|
+
# include ActiveSupport::Deprecation::DeprecatedConstantAccessor
|
22
|
+
# deprecate_constant 'PLANETS', 'PLANETS_POST_2006'
|
23
|
+
#
|
24
|
+
# PLANETS.map { |planet| planet.capitalize }
|
25
|
+
# # => DEPRECATION WARNING: PLANETS is deprecated! Use PLANETS_POST_2006 instead.
|
26
|
+
# (Backtrace information…)
|
27
|
+
# ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"]
|
28
|
+
module DeprecatedConstantAccessor
|
29
|
+
def self.included(base)
|
30
|
+
require "active_support/inflector/methods"
|
31
|
+
|
32
|
+
extension = Module.new do
|
33
|
+
def const_missing(missing_const_name)
|
34
|
+
if class_variable_defined?(:@@_deprecated_constants)
|
35
|
+
if (replacement = class_variable_get(:@@_deprecated_constants)[missing_const_name.to_s])
|
36
|
+
replacement[:deprecator].warn(replacement[:message] || "#{name}::#{missing_const_name} is deprecated! Use #{replacement[:new]} instead.", caller_locations)
|
37
|
+
return ActiveSupport::Inflector.constantize(replacement[:new].to_s)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
super
|
41
|
+
end
|
42
|
+
|
43
|
+
def deprecate_constant(const_name, new_constant, message: nil, deprecator: ActiveSupport::Deprecation.instance)
|
44
|
+
class_variable_set(:@@_deprecated_constants, {}) unless class_variable_defined?(:@@_deprecated_constants)
|
45
|
+
class_variable_get(:@@_deprecated_constants)[const_name.to_s] = { new: new_constant, message: message, deprecator: deprecator }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
base.singleton_class.prepend extension
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,11 +1,14 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/kernel/singleton_class"
|
4
|
+
require "active_support/core_ext/module/delegation"
|
3
5
|
|
4
6
|
module ActiveSupport
|
5
7
|
class Deprecation
|
6
8
|
module InstanceDelegator # :nodoc:
|
7
9
|
def self.included(base)
|
8
10
|
base.extend(ClassMethods)
|
11
|
+
base.singleton_class.prepend(OverrideDelegators)
|
9
12
|
base.public_class_method :new
|
10
13
|
end
|
11
14
|
|
@@ -19,6 +22,18 @@ module ActiveSupport
|
|
19
22
|
singleton_class.delegate(method_name, to: :instance)
|
20
23
|
end
|
21
24
|
end
|
25
|
+
|
26
|
+
module OverrideDelegators # :nodoc:
|
27
|
+
def warn(message = nil, callstack = nil)
|
28
|
+
callstack ||= caller_locations(2)
|
29
|
+
super
|
30
|
+
end
|
31
|
+
|
32
|
+
def deprecation_warning(deprecated_method_name, message = nil, caller_backtrace = nil)
|
33
|
+
caller_backtrace ||= caller_locations(2)
|
34
|
+
super
|
35
|
+
end
|
36
|
+
end
|
22
37
|
end
|
23
38
|
end
|
24
39
|
end
|
@@ -1,43 +1,83 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/array/extract_options"
|
4
|
+
require "active_support/core_ext/module/redefine_method"
|
3
5
|
|
4
6
|
module ActiveSupport
|
5
7
|
class Deprecation
|
6
8
|
module MethodWrapper
|
7
9
|
# Declare that a method has been deprecated.
|
8
10
|
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# def
|
13
|
-
# def
|
14
|
-
# def
|
11
|
+
# class Fred
|
12
|
+
# def aaa; end
|
13
|
+
# def bbb; end
|
14
|
+
# def ccc; end
|
15
|
+
# def ddd; end
|
16
|
+
# def eee; end
|
15
17
|
# end
|
16
18
|
#
|
17
|
-
#
|
18
|
-
#
|
19
|
+
# Using the default deprecator:
|
20
|
+
# ActiveSupport::Deprecation.deprecate_methods(Fred, :aaa, bbb: :zzz, ccc: 'use Bar#ccc instead')
|
21
|
+
# # => Fred
|
22
|
+
#
|
23
|
+
# Fred.new.aaa
|
24
|
+
# # DEPRECATION WARNING: aaa is deprecated and will be removed from Rails 5.1. (called from irb_binding at (irb):10)
|
25
|
+
# # => nil
|
26
|
+
#
|
27
|
+
# Fred.new.bbb
|
28
|
+
# # DEPRECATION WARNING: bbb is deprecated and will be removed from Rails 5.1 (use zzz instead). (called from irb_binding at (irb):11)
|
29
|
+
# # => nil
|
19
30
|
#
|
20
|
-
# Fred.
|
21
|
-
# #
|
31
|
+
# Fred.new.ccc
|
32
|
+
# # DEPRECATION WARNING: ccc is deprecated and will be removed from Rails 5.1 (use Bar#ccc instead). (called from irb_binding at (irb):12)
|
33
|
+
# # => nil
|
22
34
|
#
|
23
|
-
#
|
24
|
-
#
|
35
|
+
# Passing in a custom deprecator:
|
36
|
+
# custom_deprecator = ActiveSupport::Deprecation.new('next-release', 'MyGem')
|
37
|
+
# ActiveSupport::Deprecation.deprecate_methods(Fred, ddd: :zzz, deprecator: custom_deprecator)
|
38
|
+
# # => [:ddd]
|
25
39
|
#
|
26
|
-
# Fred.
|
27
|
-
#
|
40
|
+
# Fred.new.ddd
|
41
|
+
# DEPRECATION WARNING: ddd is deprecated and will be removed from MyGem next-release (use zzz instead). (called from irb_binding at (irb):15)
|
42
|
+
# # => nil
|
43
|
+
#
|
44
|
+
# Using a custom deprecator directly:
|
45
|
+
# custom_deprecator = ActiveSupport::Deprecation.new('next-release', 'MyGem')
|
46
|
+
# custom_deprecator.deprecate_methods(Fred, eee: :zzz)
|
47
|
+
# # => [:eee]
|
48
|
+
#
|
49
|
+
# Fred.new.eee
|
50
|
+
# DEPRECATION WARNING: eee is deprecated and will be removed from MyGem next-release (use zzz instead). (called from irb_binding at (irb):18)
|
51
|
+
# # => nil
|
28
52
|
def deprecate_methods(target_module, *method_names)
|
29
53
|
options = method_names.extract_options!
|
30
|
-
deprecator = options.delete(:deprecator) ||
|
54
|
+
deprecator = options.delete(:deprecator) || self
|
31
55
|
method_names += options.keys
|
56
|
+
mod = nil
|
32
57
|
|
33
58
|
method_names.each do |method_name|
|
34
|
-
target_module.
|
35
|
-
target_module.
|
36
|
-
|
37
|
-
|
59
|
+
if target_module.method_defined?(method_name) || target_module.private_method_defined?(method_name)
|
60
|
+
method = target_module.instance_method(method_name)
|
61
|
+
target_module.module_eval do
|
62
|
+
redefine_method(method_name) do |*args, &block|
|
63
|
+
deprecator.deprecation_warning(method_name, options[method_name])
|
64
|
+
method.bind(self).call(*args, &block)
|
65
|
+
end
|
66
|
+
ruby2_keywords(method_name) if respond_to?(:ruby2_keywords, true)
|
67
|
+
end
|
68
|
+
else
|
69
|
+
mod ||= Module.new
|
70
|
+
mod.module_eval do
|
71
|
+
define_method(method_name) do |*args, &block|
|
72
|
+
deprecator.deprecation_warning(method_name, options[method_name])
|
73
|
+
super(*args, &block)
|
74
|
+
end
|
75
|
+
ruby2_keywords(method_name) if respond_to?(:ruby2_keywords, true)
|
38
76
|
end
|
39
77
|
end
|
40
78
|
end
|
79
|
+
|
80
|
+
target_module.prepend(mod) if mod
|
41
81
|
end
|
42
82
|
end
|
43
83
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module ActiveSupport
|
4
4
|
class Deprecation
|
@@ -10,7 +10,7 @@ module ActiveSupport
|
|
10
10
|
super
|
11
11
|
end
|
12
12
|
|
13
|
-
instance_methods.each { |m| undef_method m unless
|
13
|
+
instance_methods.each { |m| undef_method m unless /^__|^object_id$/.match?(m) }
|
14
14
|
|
15
15
|
# Don't give a deprecation warning on inspect since test/unit and error
|
16
16
|
# logs rely on it for diagnostics.
|
@@ -20,20 +20,22 @@ module ActiveSupport
|
|
20
20
|
|
21
21
|
private
|
22
22
|
def method_missing(called, *args, &block)
|
23
|
-
warn
|
23
|
+
warn caller_locations, called, args
|
24
24
|
target.__send__(called, *args, &block)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
#
|
28
|
+
# DeprecatedObjectProxy transforms an object into a deprecated one. It
|
29
|
+
# takes an object, a deprecation message and optionally a deprecator. The
|
30
|
+
# deprecator defaults to +ActiveSupport::Deprecator+ if none is specified.
|
29
31
|
#
|
30
|
-
#
|
31
|
-
#
|
32
|
+
# deprecated_object = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(Object.new, "This object is now deprecated")
|
33
|
+
# # => #<Object:0x007fb9b34c34b0>
|
32
34
|
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
35
|
+
# deprecated_object.to_s
|
36
|
+
# DEPRECATION WARNING: This object is now deprecated.
|
37
|
+
# (Backtrace)
|
38
|
+
# # => "#<Object:0x007fb9b34c34b0>"
|
37
39
|
class DeprecatedObjectProxy < DeprecationProxy
|
38
40
|
def initialize(object, message, deprecator = ActiveSupport::Deprecation.instance)
|
39
41
|
@object = object
|
@@ -51,13 +53,16 @@ module ActiveSupport
|
|
51
53
|
end
|
52
54
|
end
|
53
55
|
|
54
|
-
#
|
55
|
-
# deprecated instance
|
56
|
+
# DeprecatedInstanceVariableProxy transforms an instance variable into a
|
57
|
+
# deprecated one. It takes an instance of a class, a method on that class
|
58
|
+
# and an instance variable. It optionally takes a deprecator as the last
|
59
|
+
# argument. The deprecator defaults to +ActiveSupport::Deprecator+ if none
|
60
|
+
# is specified.
|
56
61
|
#
|
57
62
|
# class Example
|
58
|
-
# def initialize
|
59
|
-
# @request = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :request, :@request
|
60
|
-
# @_request = :
|
63
|
+
# def initialize
|
64
|
+
# @request = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :request, :@request)
|
65
|
+
# @_request = :special_request
|
61
66
|
# end
|
62
67
|
#
|
63
68
|
# def request
|
@@ -69,12 +74,17 @@ module ActiveSupport
|
|
69
74
|
# end
|
70
75
|
# end
|
71
76
|
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
#
|
75
|
-
#
|
77
|
+
# example = Example.new
|
78
|
+
# # => #<Example:0x007fb9b31090b8 @_request=:special_request, @request=:special_request>
|
79
|
+
#
|
80
|
+
# example.old_request.to_s
|
81
|
+
# # => DEPRECATION WARNING: @request is deprecated! Call request.to_s instead of
|
82
|
+
# @request.to_s
|
83
|
+
# (Backtrace information…)
|
84
|
+
# "special_request"
|
76
85
|
#
|
77
|
-
#
|
86
|
+
# example.request.to_s
|
87
|
+
# # => "special_request"
|
78
88
|
class DeprecatedInstanceVariableProxy < DeprecationProxy
|
79
89
|
def initialize(instance, method, var = "@#{method}", deprecator = ActiveSupport::Deprecation.instance)
|
80
90
|
@instance = instance
|
@@ -93,22 +103,57 @@ module ActiveSupport
|
|
93
103
|
end
|
94
104
|
end
|
95
105
|
|
96
|
-
#
|
106
|
+
# DeprecatedConstantProxy transforms a constant into a deprecated one. It
|
107
|
+
# takes the names of an old (deprecated) constant and of a new constant
|
108
|
+
# (both in string form) and optionally a deprecator. The deprecator defaults
|
109
|
+
# to +ActiveSupport::Deprecator+ if none is specified. The deprecated constant
|
110
|
+
# now returns the value of the new one.
|
111
|
+
#
|
112
|
+
# PLANETS = %w(mercury venus earth mars jupiter saturn uranus neptune pluto)
|
97
113
|
#
|
98
|
-
#
|
99
|
-
# OLD_CONST = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('OLD_CONST', 'NEW_CONST', deprecator_instance)
|
114
|
+
# # (In a later update, the original implementation of `PLANETS` has been removed.)
|
100
115
|
#
|
101
|
-
#
|
102
|
-
#
|
116
|
+
# PLANETS_POST_2006 = %w(mercury venus earth mars jupiter saturn uranus neptune)
|
117
|
+
# PLANETS = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('PLANETS', 'PLANETS_POST_2006')
|
103
118
|
#
|
104
|
-
#
|
105
|
-
|
106
|
-
|
119
|
+
# PLANETS.map { |planet| planet.capitalize }
|
120
|
+
# # => DEPRECATION WARNING: PLANETS is deprecated! Use PLANETS_POST_2006 instead.
|
121
|
+
# (Backtrace information…)
|
122
|
+
# ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"]
|
123
|
+
class DeprecatedConstantProxy < Module
|
124
|
+
def self.new(*args, **kwargs, &block)
|
125
|
+
object = args.first
|
126
|
+
|
127
|
+
return object unless object
|
128
|
+
super
|
129
|
+
end
|
130
|
+
|
131
|
+
def initialize(old_const, new_const, deprecator = ActiveSupport::Deprecation.instance, message: "#{old_const} is deprecated! Use #{new_const} instead.")
|
132
|
+
require "active_support/inflector/methods"
|
133
|
+
|
107
134
|
@old_const = old_const
|
108
135
|
@new_const = new_const
|
109
136
|
@deprecator = deprecator
|
137
|
+
@message = message
|
138
|
+
end
|
139
|
+
|
140
|
+
instance_methods.each { |m| undef_method m unless /^__|^object_id$/.match?(m) }
|
141
|
+
|
142
|
+
# Don't give a deprecation warning on inspect since test/unit and error
|
143
|
+
# logs rely on it for diagnostics.
|
144
|
+
def inspect
|
145
|
+
target.inspect
|
110
146
|
end
|
111
147
|
|
148
|
+
# Don't give a deprecation warning on methods that IRB may invoke
|
149
|
+
# during tab-completion.
|
150
|
+
delegate :hash, :instance_methods, :name, to: :target
|
151
|
+
|
152
|
+
# Returns the class of the new constant.
|
153
|
+
#
|
154
|
+
# PLANETS_POST_2006 = %w(mercury venus earth mars jupiter saturn uranus neptune)
|
155
|
+
# PLANETS = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('PLANETS', 'PLANETS_POST_2006')
|
156
|
+
# PLANETS.class # => Array
|
112
157
|
def class
|
113
158
|
target.class
|
114
159
|
end
|
@@ -118,8 +163,14 @@ module ActiveSupport
|
|
118
163
|
ActiveSupport::Inflector.constantize(@new_const.to_s)
|
119
164
|
end
|
120
165
|
|
121
|
-
def
|
122
|
-
@deprecator.warn(
|
166
|
+
def const_missing(name)
|
167
|
+
@deprecator.warn(@message, caller_locations)
|
168
|
+
target.const_get(name)
|
169
|
+
end
|
170
|
+
|
171
|
+
def method_missing(called, *args, &block)
|
172
|
+
@deprecator.warn(@message, caller_locations)
|
173
|
+
target.__send__(called, *args, &block)
|
123
174
|
end
|
124
175
|
end
|
125
176
|
end
|
@@ -1,3 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rbconfig"
|
4
|
+
|
1
5
|
module ActiveSupport
|
2
6
|
class Deprecation
|
3
7
|
module Reporting
|
@@ -14,9 +18,9 @@ module ActiveSupport
|
|
14
18
|
def warn(message = nil, callstack = nil)
|
15
19
|
return if silenced
|
16
20
|
|
17
|
-
callstack ||=
|
21
|
+
callstack ||= caller_locations(2)
|
18
22
|
deprecation_message(callstack, message).tap do |m|
|
19
|
-
behavior.each { |b| b.call(m, callstack) }
|
23
|
+
behavior.each { |b| b.call(m, callstack, deprecation_horizon, gem_name) }
|
20
24
|
end
|
21
25
|
end
|
22
26
|
|
@@ -37,7 +41,7 @@ module ActiveSupport
|
|
37
41
|
end
|
38
42
|
|
39
43
|
def deprecation_warning(deprecated_method_name, message = nil, caller_backtrace = nil)
|
40
|
-
caller_backtrace ||=
|
44
|
+
caller_backtrace ||= caller_locations(2)
|
41
45
|
deprecated_method_warning(deprecated_method_name, message).tap do |msg|
|
42
46
|
warn(msg, caller_backtrace)
|
43
47
|
end
|
@@ -46,24 +50,23 @@ module ActiveSupport
|
|
46
50
|
private
|
47
51
|
# Outputs a deprecation warning message
|
48
52
|
#
|
49
|
-
#
|
53
|
+
# deprecated_method_warning(:method_name)
|
50
54
|
# # => "method_name is deprecated and will be removed from Rails #{deprecation_horizon}"
|
51
|
-
#
|
55
|
+
# deprecated_method_warning(:method_name, :another_method)
|
52
56
|
# # => "method_name is deprecated and will be removed from Rails #{deprecation_horizon} (use another_method instead)"
|
53
|
-
#
|
57
|
+
# deprecated_method_warning(:method_name, "Optional message")
|
54
58
|
# # => "method_name is deprecated and will be removed from Rails #{deprecation_horizon} (Optional message)"
|
55
59
|
def deprecated_method_warning(method_name, message = nil)
|
56
60
|
warning = "#{method_name} is deprecated and will be removed from #{gem_name} #{deprecation_horizon}"
|
57
61
|
case message
|
58
|
-
|
59
|
-
|
60
|
-
|
62
|
+
when Symbol then "#{warning} (use #{message} instead)"
|
63
|
+
when String then "#{warning} (#{message})"
|
64
|
+
else warning
|
61
65
|
end
|
62
66
|
end
|
63
67
|
|
64
68
|
def deprecation_message(callstack, message = nil)
|
65
69
|
message ||= "You are using deprecated behavior which will be removed from the next major or minor release."
|
66
|
-
message += '.' unless message =~ /\.$/
|
67
70
|
"DEPRECATION WARNING: #{message} #{deprecation_caller_message(callstack)}"
|
68
71
|
end
|
69
72
|
|
@@ -79,8 +82,19 @@ module ActiveSupport
|
|
79
82
|
end
|
80
83
|
|
81
84
|
def extract_callstack(callstack)
|
82
|
-
|
83
|
-
|
85
|
+
return _extract_callstack(callstack) if callstack.first.is_a? String
|
86
|
+
|
87
|
+
offending_line = callstack.find { |frame|
|
88
|
+
frame.absolute_path && !ignored_callstack(frame.absolute_path)
|
89
|
+
} || callstack.first
|
90
|
+
|
91
|
+
[offending_line.path, offending_line.lineno, offending_line.label]
|
92
|
+
end
|
93
|
+
|
94
|
+
def _extract_callstack(callstack)
|
95
|
+
warn "Please pass `caller_locations` to the deprecation API" if $VERBOSE
|
96
|
+
offending_line = callstack.find { |line| !ignored_callstack(line) } || callstack.first
|
97
|
+
|
84
98
|
if offending_line
|
85
99
|
if md = offending_line.match(/^(.+?):(\d+)(?::in `(.*?)')?/)
|
86
100
|
md.captures
|
@@ -89,6 +103,12 @@ module ActiveSupport
|
|
89
103
|
end
|
90
104
|
end
|
91
105
|
end
|
106
|
+
|
107
|
+
RAILS_GEM_ROOT = File.expand_path("../../../..", __dir__) + "/"
|
108
|
+
|
109
|
+
def ignored_callstack(path)
|
110
|
+
path.start_with?(RAILS_GEM_ROOT) || path.start_with?(RbConfig::CONFIG["rubylibdir"])
|
111
|
+
end
|
92
112
|
end
|
93
113
|
end
|
94
114
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "singleton"
|
2
4
|
|
3
5
|
module ActiveSupport
|
4
6
|
# \Deprecation specifies the API used by Rails to deprecate methods, instance
|
@@ -12,12 +14,13 @@ module ActiveSupport
|
|
12
14
|
# a circular require warning for active_support/deprecation.rb.
|
13
15
|
#
|
14
16
|
# So, we define the constant first, and load dependencies later.
|
15
|
-
require
|
16
|
-
require
|
17
|
-
require
|
18
|
-
require
|
19
|
-
require
|
20
|
-
require
|
17
|
+
require "active_support/deprecation/instance_delegator"
|
18
|
+
require "active_support/deprecation/behaviors"
|
19
|
+
require "active_support/deprecation/reporting"
|
20
|
+
require "active_support/deprecation/constant_accessor"
|
21
|
+
require "active_support/deprecation/method_wrappers"
|
22
|
+
require "active_support/deprecation/proxy_wrappers"
|
23
|
+
require "active_support/core_ext/module/deprecation"
|
21
24
|
|
22
25
|
include Singleton
|
23
26
|
include InstanceDelegator
|
@@ -29,10 +32,10 @@ module ActiveSupport
|
|
29
32
|
attr_accessor :deprecation_horizon
|
30
33
|
|
31
34
|
# It accepts two parameters on initialization. The first is a version of library
|
32
|
-
# and the second is a library name
|
35
|
+
# and the second is a library name.
|
33
36
|
#
|
34
37
|
# ActiveSupport::Deprecation.new('2.0', 'MyLibrary')
|
35
|
-
def initialize(deprecation_horizon =
|
38
|
+
def initialize(deprecation_horizon = "6.1", gem_name = "Rails")
|
36
39
|
self.gem_name = gem_name
|
37
40
|
self.deprecation_horizon = deprecation_horizon
|
38
41
|
# By default, warnings are not silenced and debugging is off.
|