activesupport 4.2.11.1 → 5.2.4.3
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 +403 -433
- data/MIT-LICENSE +2 -2
- data/README.rdoc +4 -5
- data/lib/active_support/all.rb +5 -3
- data/lib/active_support/array_inquirer.rb +48 -0
- data/lib/active_support/backtrace_cleaner.rb +7 -5
- data/lib/active_support/benchmarkable.rb +6 -4
- data/lib/active_support/builder.rb +3 -1
- data/lib/active_support/cache/file_store.rb +41 -35
- data/lib/active_support/cache/mem_cache_store.rb +90 -91
- data/lib/active_support/cache/memory_store.rb +27 -30
- data/lib/active_support/cache/null_store.rb +7 -8
- data/lib/active_support/cache/redis_cache_store.rb +466 -0
- data/lib/active_support/cache/strategy/local_cache.rb +67 -34
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +10 -9
- data/lib/active_support/cache.rb +287 -196
- data/lib/active_support/callbacks.rb +640 -590
- data/lib/active_support/concern.rb +11 -5
- data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +17 -0
- data/lib/active_support/concurrency/share_lock.rb +227 -0
- data/lib/active_support/configurable.rb +8 -5
- data/lib/active_support/core_ext/array/access.rb +29 -1
- data/lib/active_support/core_ext/array/conversions.rb +22 -18
- 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 +5 -3
- 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 +41 -22
- 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 +11 -9
- 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 +170 -58
- 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 -12
- 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 +36 -18
- data/lib/active_support/core_ext/date_time/compatibility.rb +8 -6
- data/lib/active_support/core_ext/date_time/conversions.rb +16 -12
- 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 +101 -33
- 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 +14 -9
- 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/except.rb +11 -8
- data/lib/active_support/core_ext/hash/indifferent_access.rb +4 -3
- data/lib/active_support/core_ext/hash/keys.rb +33 -27
- data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
- data/lib/active_support/core_ext/hash/slice.rb +8 -8
- data/lib/active_support/core_ext/hash/transform_values.rb +14 -5
- data/lib/active_support/core_ext/hash.rb +11 -9
- data/lib/active_support/core_ext/integer/inflections.rb +3 -1
- data/lib/active_support/core_ext/integer/multiple.rb +2 -0
- 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/agnostics.rb +2 -0
- 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 +6 -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 +43 -40
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +150 -0
- data/lib/active_support/core_ext/module/concerning.rb +11 -12
- data/lib/active_support/core_ext/module/delegation.rb +99 -29
- data/lib/active_support/core_ext/module/deprecation.rb +4 -2
- data/lib/active_support/core_ext/module/introspection.rb +9 -9
- data/lib/active_support/core_ext/module/reachable.rb +5 -2
- data/lib/active_support/core_ext/module/redefine_method.rb +49 -0
- data/lib/active_support/core_ext/module/remove_method.rb +8 -3
- data/lib/active_support/core_ext/module.rb +14 -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 +78 -81
- data/lib/active_support/core_ext/numeric/inquiry.rb +28 -0
- data/lib/active_support/core_ext/numeric/time.rb +35 -23
- data/lib/active_support/core_ext/numeric.rb +6 -3
- data/lib/active_support/core_ext/object/acts_like.rb +12 -1
- data/lib/active_support/core_ext/object/blank.rb +27 -2
- 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 +41 -14
- 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 +49 -19
- 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 +69 -21
- 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 +61 -0
- data/lib/active_support/core_ext/range/conversions.rb +27 -7
- data/lib/active_support/core_ext/range/each.rb +19 -17
- data/lib/active_support/core_ext/range/include_range.rb +2 -22
- 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 +6 -0
- data/lib/active_support/core_ext/securerandom.rb +25 -0
- data/lib/active_support/core_ext/string/access.rb +8 -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 +6 -5
- data/lib/active_support/core_ext/string/indent.rb +6 -4
- data/lib/active_support/core_ext/string/inflections.rb +61 -24
- data/lib/active_support/core_ext/string/inquiry.rb +3 -1
- data/lib/active_support/core_ext/string/multibyte.rb +15 -7
- data/lib/active_support/core_ext/string/output_safety.rb +34 -38
- data/lib/active_support/core_ext/string/starts_ends_with.rb +2 -0
- data/lib/active_support/core_ext/string/strip.rb +4 -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 +85 -51
- 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 -8
- data/lib/active_support/core_ext.rb +3 -1
- data/lib/active_support/current_attributes.rb +195 -0
- data/lib/active_support/dependencies/autoload.rb +2 -0
- data/lib/active_support/dependencies/interlock.rb +57 -0
- data/lib/active_support/dependencies.rb +152 -161
- 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 +66 -20
- data/lib/active_support/deprecation/proxy_wrappers.rb +56 -28
- data/lib/active_support/deprecation/reporting.rb +32 -12
- data/lib/active_support/deprecation.rb +12 -9
- data/lib/active_support/descendants_tracker.rb +2 -0
- data/lib/active_support/digest.rb +20 -0
- data/lib/active_support/duration/iso8601_parser.rb +125 -0
- data/lib/active_support/duration/iso8601_serializer.rb +55 -0
- data/lib/active_support/duration.rb +307 -35
- data/lib/active_support/encrypted_configuration.rb +49 -0
- data/lib/active_support/encrypted_file.rb +99 -0
- data/lib/active_support/evented_file_update_checker.rb +205 -0
- data/lib/active_support/execution_wrapper.rb +128 -0
- data/lib/active_support/executor.rb +8 -0
- data/lib/active_support/file_update_checker.rb +63 -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 +123 -28
- data/lib/active_support/i18n.rb +8 -6
- data/lib/active_support/i18n_railtie.rb +37 -13
- data/lib/active_support/inflections.rb +13 -11
- data/lib/active_support/inflector/inflections.rb +61 -12
- data/lib/active_support/inflector/methods.rb +163 -136
- data/lib/active_support/inflector/transliterate.rb +48 -27
- data/lib/active_support/inflector.rb +7 -5
- data/lib/active_support/json/decoding.rb +16 -13
- data/lib/active_support/json/encoding.rb +11 -58
- data/lib/active_support/json.rb +4 -2
- data/lib/active_support/key_generator.rb +25 -25
- data/lib/active_support/lazy_load_hooks.rb +50 -20
- 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 +13 -10
- data/lib/active_support/logger.rb +8 -7
- data/lib/active_support/logger_silence.rb +6 -4
- data/lib/active_support/logger_thread_safe_level.rb +7 -5
- data/lib/active_support/message_encryptor.rb +168 -53
- data/lib/active_support/message_verifier.rb +150 -17
- data/lib/active_support/messages/metadata.rb +71 -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 +36 -23
- data/lib/active_support/multibyte/unicode.rb +100 -96
- data/lib/active_support/multibyte.rb +4 -2
- data/lib/active_support/notifications/fanout.rb +11 -9
- data/lib/active_support/notifications/instrumenter.rb +27 -7
- data/lib/active_support/notifications.rb +11 -7
- data/lib/active_support/number_helper/number_converter.rb +13 -11
- data/lib/active_support/number_helper/number_to_currency_converter.rb +9 -9
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +9 -3
- data/lib/active_support/number_helper/number_to_human_converter.rb +11 -9
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +9 -8
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +3 -1
- data/lib/active_support/number_helper/number_to_phone_converter.rb +13 -4
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +23 -56
- data/lib/active_support/number_helper/rounding_helper.rb +66 -0
- data/lib/active_support/number_helper.rb +94 -68
- data/lib/active_support/option_merger.rb +3 -1
- data/lib/active_support/ordered_hash.rb +6 -4
- data/lib/active_support/ordered_options.rb +23 -5
- 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 +16 -8
- data/lib/active_support/railtie.rb +43 -9
- data/lib/active_support/reloader.rb +131 -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 -3
- data/lib/active_support/subscriber.rb +21 -16
- data/lib/active_support/tagged_logging.rb +14 -11
- data/lib/active_support/test_case.rb +19 -47
- data/lib/active_support/testing/assertions.rb +137 -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 +14 -10
- data/lib/active_support/testing/file_fixtures.rb +36 -0
- data/lib/active_support/testing/isolation.rb +34 -25
- data/lib/active_support/testing/method_call_assertions.rb +43 -0
- data/lib/active_support/testing/setup_and_teardown.rb +13 -8
- data/lib/active_support/testing/stream.rb +44 -0
- data/lib/active_support/testing/tagged_logging.rb +3 -1
- data/lib/active_support/testing/time_helpers.rb +81 -15
- data/lib/active_support/time.rb +14 -12
- data/lib/active_support/time_with_zone.rb +169 -39
- data/lib/active_support/values/time_zone.rb +196 -61
- data/lib/active_support/values/unicode_tables.dat +0 -0
- data/lib/active_support/version.rb +3 -1
- data/lib/active_support/xml_mini/jdom.rb +116 -114
- 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 +37 -37
- data/lib/active_support.rb +12 -11
- metadata +54 -24
- 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/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
@@ -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,89 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/module/aliasing"
|
4
|
+
require "active_support/core_ext/array/extract_options"
|
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 = Module.new
|
32
57
|
|
33
58
|
method_names.each do |method_name|
|
34
|
-
target_module.
|
35
|
-
|
59
|
+
if target_module.method_defined?(method_name) || target_module.private_method_defined?(method_name)
|
60
|
+
aliased_method, punctuation = method_name.to_s.sub(/([?!=])$/, ""), $1
|
61
|
+
with_method = "#{aliased_method}_with_deprecation#{punctuation}"
|
62
|
+
without_method = "#{aliased_method}_without_deprecation#{punctuation}"
|
63
|
+
|
64
|
+
target_module.send(:define_method, with_method) do |*args, &block|
|
36
65
|
deprecator.deprecation_warning(method_name, options[method_name])
|
37
|
-
send(
|
66
|
+
send(without_method, *args, &block)
|
67
|
+
end
|
68
|
+
|
69
|
+
target_module.send(:alias_method, without_method, method_name)
|
70
|
+
target_module.send(:alias_method, method_name, with_method)
|
71
|
+
|
72
|
+
case
|
73
|
+
when target_module.protected_method_defined?(without_method)
|
74
|
+
target_module.send(:protected, method_name)
|
75
|
+
when target_module.private_method_defined?(without_method)
|
76
|
+
target_module.send(:private, method_name)
|
77
|
+
end
|
78
|
+
else
|
79
|
+
mod.send(:define_method, method_name) do |*args, &block|
|
80
|
+
deprecator.deprecation_warning(method_name, options[method_name])
|
81
|
+
super(*args, &block)
|
38
82
|
end
|
39
83
|
end
|
40
84
|
end
|
85
|
+
|
86
|
+
target_module.prepend(mod) unless mod.instance_methods(false).empty?
|
41
87
|
end
|
42
88
|
end
|
43
89
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/regexp"
|
2
4
|
|
3
5
|
module ActiveSupport
|
4
6
|
class Deprecation
|
@@ -10,7 +12,7 @@ module ActiveSupport
|
|
10
12
|
super
|
11
13
|
end
|
12
14
|
|
13
|
-
instance_methods.each { |m| undef_method m unless
|
15
|
+
instance_methods.each { |m| undef_method m unless /^__|^object_id$/.match?(m) }
|
14
16
|
|
15
17
|
# Don't give a deprecation warning on inspect since test/unit and error
|
16
18
|
# logs rely on it for diagnostics.
|
@@ -20,20 +22,22 @@ module ActiveSupport
|
|
20
22
|
|
21
23
|
private
|
22
24
|
def method_missing(called, *args, &block)
|
23
|
-
warn
|
25
|
+
warn caller_locations, called, args
|
24
26
|
target.__send__(called, *args, &block)
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
# @old_object = DeprecatedObjectProxy.new(Object.new, "Don't use this object anymore!", deprecator_instance)
|
30
|
+
# DeprecatedObjectProxy transforms an object into a deprecated one. It
|
31
|
+
# takes an object, a deprecation message and optionally a deprecator. The
|
32
|
+
# deprecator defaults to +ActiveSupport::Deprecator+ if none is specified.
|
32
33
|
#
|
33
|
-
#
|
34
|
-
#
|
34
|
+
# deprecated_object = ActiveSupport::Deprecation::DeprecatedObjectProxy.new(Object.new, "This object is now deprecated")
|
35
|
+
# # => #<Object:0x007fb9b34c34b0>
|
35
36
|
#
|
36
|
-
#
|
37
|
+
# deprecated_object.to_s
|
38
|
+
# DEPRECATION WARNING: This object is now deprecated.
|
39
|
+
# (Backtrace)
|
40
|
+
# # => "#<Object:0x007fb9b34c34b0>"
|
37
41
|
class DeprecatedObjectProxy < DeprecationProxy
|
38
42
|
def initialize(object, message, deprecator = ActiveSupport::Deprecation.instance)
|
39
43
|
@object = object
|
@@ -51,13 +55,16 @@ module ActiveSupport
|
|
51
55
|
end
|
52
56
|
end
|
53
57
|
|
54
|
-
#
|
55
|
-
# deprecated instance
|
58
|
+
# DeprecatedInstanceVariableProxy transforms an instance variable into a
|
59
|
+
# deprecated one. It takes an instance of a class, a method on that class
|
60
|
+
# and an instance variable. It optionally takes a deprecator as the last
|
61
|
+
# argument. The deprecator defaults to +ActiveSupport::Deprecator+ if none
|
62
|
+
# is specified.
|
56
63
|
#
|
57
64
|
# class Example
|
58
|
-
# def initialize
|
59
|
-
# @request = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :request, :@request
|
60
|
-
# @_request = :
|
65
|
+
# def initialize
|
66
|
+
# @request = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.new(self, :request, :@request)
|
67
|
+
# @_request = :special_request
|
61
68
|
# end
|
62
69
|
#
|
63
70
|
# def request
|
@@ -69,12 +76,17 @@ module ActiveSupport
|
|
69
76
|
# end
|
70
77
|
# end
|
71
78
|
#
|
72
|
-
#
|
73
|
-
#
|
74
|
-
# variable via +request+ method and execute the same method on non-proxy
|
75
|
-
# instance variable.
|
79
|
+
# example = Example.new
|
80
|
+
# # => #<Example:0x007fb9b31090b8 @_request=:special_request, @request=:special_request>
|
76
81
|
#
|
77
|
-
#
|
82
|
+
# example.old_request.to_s
|
83
|
+
# # => DEPRECATION WARNING: @request is deprecated! Call request.to_s instead of
|
84
|
+
# @request.to_s
|
85
|
+
# (Backtrace information…)
|
86
|
+
# "special_request"
|
87
|
+
#
|
88
|
+
# example.request.to_s
|
89
|
+
# # => "special_request"
|
78
90
|
class DeprecatedInstanceVariableProxy < DeprecationProxy
|
79
91
|
def initialize(instance, method, var = "@#{method}", deprecator = ActiveSupport::Deprecation.instance)
|
80
92
|
@instance = instance
|
@@ -93,22 +105,38 @@ module ActiveSupport
|
|
93
105
|
end
|
94
106
|
end
|
95
107
|
|
96
|
-
#
|
108
|
+
# DeprecatedConstantProxy transforms a constant into a deprecated one. It
|
109
|
+
# takes the names of an old (deprecated) constant and of a new constant
|
110
|
+
# (both in string form) and optionally a deprecator. The deprecator defaults
|
111
|
+
# to +ActiveSupport::Deprecator+ if none is specified. The deprecated constant
|
112
|
+
# now returns the value of the new one.
|
113
|
+
#
|
114
|
+
# PLANETS = %w(mercury venus earth mars jupiter saturn uranus neptune pluto)
|
97
115
|
#
|
98
|
-
#
|
99
|
-
# OLD_CONST = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('OLD_CONST', 'NEW_CONST', deprecator_instance)
|
116
|
+
# # (In a later update, the original implementation of `PLANETS` has been removed.)
|
100
117
|
#
|
101
|
-
#
|
102
|
-
#
|
118
|
+
# PLANETS_POST_2006 = %w(mercury venus earth mars jupiter saturn uranus neptune)
|
119
|
+
# PLANETS = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('PLANETS', 'PLANETS_POST_2006')
|
103
120
|
#
|
104
|
-
#
|
121
|
+
# PLANETS.map { |planet| planet.capitalize }
|
122
|
+
# # => DEPRECATION WARNING: PLANETS is deprecated! Use PLANETS_POST_2006 instead.
|
123
|
+
# (Backtrace information…)
|
124
|
+
# ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"]
|
105
125
|
class DeprecatedConstantProxy < DeprecationProxy
|
106
|
-
def initialize(old_const, new_const, deprecator = ActiveSupport::Deprecation.instance)
|
126
|
+
def initialize(old_const, new_const, deprecator = ActiveSupport::Deprecation.instance, message: "#{old_const} is deprecated! Use #{new_const} instead.")
|
127
|
+
require "active_support/inflector/methods"
|
128
|
+
|
107
129
|
@old_const = old_const
|
108
130
|
@new_const = new_const
|
109
131
|
@deprecator = deprecator
|
132
|
+
@message = message
|
110
133
|
end
|
111
134
|
|
135
|
+
# Returns the class of the new constant.
|
136
|
+
#
|
137
|
+
# PLANETS_POST_2006 = %w(mercury venus earth mars jupiter saturn uranus neptune)
|
138
|
+
# PLANETS = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('PLANETS', 'PLANETS_POST_2006')
|
139
|
+
# PLANETS.class # => Array
|
112
140
|
def class
|
113
141
|
target.class
|
114
142
|
end
|
@@ -119,7 +147,7 @@ module ActiveSupport
|
|
119
147
|
end
|
120
148
|
|
121
149
|
def warn(callstack, called, args)
|
122
|
-
@deprecator.warn(
|
150
|
+
@deprecator.warn(@message, callstack)
|
123
151
|
end
|
124
152
|
end
|
125
153
|
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.0", 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.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
class Digest #:nodoc:
|
5
|
+
class <<self
|
6
|
+
def hash_digest_class
|
7
|
+
@hash_digest_class ||= ::Digest::MD5
|
8
|
+
end
|
9
|
+
|
10
|
+
def hash_digest_class=(klass)
|
11
|
+
raise ArgumentError, "#{klass} is expected to implement hexdigest class method" unless klass.respond_to?(:hexdigest)
|
12
|
+
@hash_digest_class = klass
|
13
|
+
end
|
14
|
+
|
15
|
+
def hexdigest(arg)
|
16
|
+
hash_digest_class.hexdigest(arg)[0...32]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|