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,98 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "set"
|
4
|
+
require "active_support/dependencies/interlock"
|
5
|
+
|
6
|
+
module ActiveSupport # :nodoc:
|
7
|
+
module Dependencies # :nodoc:
|
8
|
+
require_relative "dependencies/require_dependency"
|
9
|
+
|
10
|
+
singleton_class.attr_accessor :interlock
|
11
|
+
@interlock = Interlock.new
|
12
|
+
|
13
|
+
# :doc:
|
14
|
+
|
15
|
+
# Execute the supplied block without interference from any
|
16
|
+
# concurrent loads.
|
17
|
+
def self.run_interlock(&block)
|
18
|
+
interlock.running(&block)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Execute the supplied block while holding an exclusive lock,
|
22
|
+
# preventing any other thread from being inside a #run_interlock
|
23
|
+
# block at the same time.
|
24
|
+
def self.load_interlock(&block)
|
25
|
+
interlock.loading(&block)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Execute the supplied block while holding an exclusive lock,
|
29
|
+
# preventing any other thread from being inside a #run_interlock
|
30
|
+
# block at the same time.
|
31
|
+
def self.unload_interlock(&block)
|
32
|
+
interlock.unloading(&block)
|
33
|
+
end
|
34
|
+
|
35
|
+
# :nodoc:
|
36
|
+
|
37
|
+
# The array of directories from which we autoload and reload, if reloading
|
38
|
+
# is enabled. The public interface to push directories to this collection
|
39
|
+
# from applications or engines is config.autoload_paths.
|
40
|
+
#
|
41
|
+
# This collection is allowed to have intersection with autoload_once_paths.
|
42
|
+
# Common directories are not reloaded.
|
43
|
+
singleton_class.attr_accessor :autoload_paths
|
44
|
+
self.autoload_paths = []
|
45
|
+
|
46
|
+
# The array of directories from which we autoload and never reload, even if
|
47
|
+
# reloading is enabled. The public interface to push directories to this
|
48
|
+
# collection from applications or engines is config.autoload_once_paths.
|
49
|
+
singleton_class.attr_accessor :autoload_once_paths
|
50
|
+
self.autoload_once_paths = []
|
51
|
+
|
52
|
+
# This is a private set that collects all eager load paths during bootstrap.
|
53
|
+
# Useful for Zeitwerk integration. The public interface to push custom
|
54
|
+
# directories to this collection from applications or engines is
|
55
|
+
# config.eager_load_paths.
|
56
|
+
singleton_class.attr_accessor :_eager_load_paths
|
57
|
+
self._eager_load_paths = Set.new
|
58
|
+
|
59
|
+
# If reloading is enabled, this private set holds autoloaded classes tracked
|
60
|
+
# by the descendants tracker. It is populated by an on_load callback in the
|
61
|
+
# main autoloader. Used to clear state.
|
62
|
+
singleton_class.attr_accessor :_autoloaded_tracked_classes
|
63
|
+
self._autoloaded_tracked_classes = Set.new
|
64
|
+
|
65
|
+
# If reloading is enabled, this private attribute stores the main autoloader
|
66
|
+
# of a Rails application. It is `nil` otherwise.
|
67
|
+
#
|
68
|
+
# The public interface for this autoloader is `Rails.autoloaders.main`.
|
69
|
+
singleton_class.attr_accessor :autoloader
|
70
|
+
|
71
|
+
# Private method that reloads constants autoloaded by the main autoloader.
|
72
|
+
#
|
73
|
+
# Rails.application.reloader.reload! is the public interface for application
|
74
|
+
# reload. That involves more things, like deleting unloaded classes from the
|
75
|
+
# internal state of the descendants tracker, or reloading routes.
|
76
|
+
def self.clear
|
77
|
+
unload_interlock do
|
78
|
+
_autoloaded_tracked_classes.clear
|
79
|
+
autoloader.reload
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# Private method used by require_dependency.
|
84
|
+
def self.search_for_file(relpath)
|
85
|
+
relpath += ".rb" unless relpath.end_with?(".rb")
|
86
|
+
autoload_paths.each do |autoload_path|
|
87
|
+
abspath = File.join(autoload_path, relpath)
|
88
|
+
return abspath if File.file?(abspath)
|
89
|
+
end
|
90
|
+
nil
|
91
|
+
end
|
92
|
+
|
93
|
+
# Private method that helps configuring the autoloaders.
|
94
|
+
def self.eager_load?(path)
|
95
|
+
_eager_load_paths.member?(path)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/notifications"
|
4
|
+
|
5
|
+
module ActiveSupport
|
6
|
+
# Raised when ActiveSupport::Deprecation::Behavior#behavior 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.
|
8
|
+
class DeprecationException < StandardError
|
9
|
+
end
|
10
|
+
|
11
|
+
class Deprecation
|
12
|
+
# Default warning behaviors per Rails.env.
|
13
|
+
DEFAULT_BEHAVIORS = {
|
14
|
+
raise: ->(message, callstack, deprecator) do
|
15
|
+
e = DeprecationException.new(message)
|
16
|
+
e.set_backtrace(callstack.map(&:to_s))
|
17
|
+
raise e
|
18
|
+
end,
|
19
|
+
|
20
|
+
stderr: ->(message, callstack, deprecator) do
|
21
|
+
$stderr.puts(message)
|
22
|
+
$stderr.puts callstack.join("\n ") if deprecator.debug
|
23
|
+
end,
|
24
|
+
|
25
|
+
log: ->(message, callstack, deprecator) do
|
26
|
+
logger =
|
27
|
+
if defined?(Rails.logger) && Rails.logger
|
28
|
+
Rails.logger
|
29
|
+
else
|
30
|
+
require "active_support/logger"
|
31
|
+
ActiveSupport::Logger.new($stderr)
|
32
|
+
end
|
33
|
+
logger.warn message
|
34
|
+
logger.debug callstack.join("\n ") if deprecator.debug
|
35
|
+
end,
|
36
|
+
|
37
|
+
notify: ->(message, callstack, deprecator) do
|
38
|
+
ActiveSupport::Notifications.instrument(
|
39
|
+
"deprecation.#{deprecator.gem_name.underscore.tr("/", "_")}",
|
40
|
+
message: message,
|
41
|
+
callstack: callstack,
|
42
|
+
gem_name: deprecator.gem_name,
|
43
|
+
deprecation_horizon: deprecator.deprecation_horizon,
|
44
|
+
)
|
45
|
+
end,
|
46
|
+
|
47
|
+
silence: ->(message, callstack, deprecator) { },
|
48
|
+
|
49
|
+
report: ->(message, callstack, deprecator) do
|
50
|
+
error = DeprecationException.new(message)
|
51
|
+
error.set_backtrace(callstack.map(&:to_s))
|
52
|
+
ActiveSupport.error_reporter.report(error)
|
53
|
+
end
|
54
|
+
}
|
55
|
+
|
56
|
+
# Behavior module allows to determine how to display deprecation messages.
|
57
|
+
# You can create a custom behavior or set any from the +DEFAULT_BEHAVIORS+
|
58
|
+
# constant. Available behaviors are:
|
59
|
+
#
|
60
|
+
# [+:raise+] Raise ActiveSupport::DeprecationException.
|
61
|
+
# [+:stderr+] Log all deprecation warnings to <tt>$stderr</tt>.
|
62
|
+
# [+:log+] Log all deprecation warnings to +Rails.logger+.
|
63
|
+
# [+:notify+] Use ActiveSupport::Notifications to notify +deprecation.rails+.
|
64
|
+
# [+:report+] Use ActiveSupport::ErrorReporter to report deprecations.
|
65
|
+
# [+:silence+] Do nothing. On \Rails, set <tt>config.active_support.report_deprecations = false</tt> to disable all behaviors.
|
66
|
+
#
|
67
|
+
# Setting behaviors only affects deprecations that happen after boot time.
|
68
|
+
# For more information you can read the documentation of the #behavior= method.
|
69
|
+
module Behavior
|
70
|
+
# Whether to print a backtrace along with the warning.
|
71
|
+
attr_accessor :debug
|
72
|
+
|
73
|
+
# Returns the current behavior or if one isn't set, defaults to +:stderr+.
|
74
|
+
def behavior
|
75
|
+
@behavior ||= [DEFAULT_BEHAVIORS[:stderr]]
|
76
|
+
end
|
77
|
+
|
78
|
+
# Returns the current behavior for disallowed deprecations or if one isn't set, defaults to +:raise+.
|
79
|
+
def disallowed_behavior
|
80
|
+
@disallowed_behavior ||= [DEFAULT_BEHAVIORS[:raise]]
|
81
|
+
end
|
82
|
+
|
83
|
+
# Sets the behavior to the specified value. Can be a single value, array,
|
84
|
+
# or an object that responds to +call+.
|
85
|
+
#
|
86
|
+
# Available behaviors:
|
87
|
+
#
|
88
|
+
# [+:raise+] Raise ActiveSupport::DeprecationException.
|
89
|
+
# [+:stderr+] Log all deprecation warnings to <tt>$stderr</tt>.
|
90
|
+
# [+:log+] Log all deprecation warnings to +Rails.logger+.
|
91
|
+
# [+:notify+] Use ActiveSupport::Notifications to notify +deprecation.rails+.
|
92
|
+
# [+:report+] Use ActiveSupport::ErrorReporter to report deprecations.
|
93
|
+
# [+:silence+] Do nothing.
|
94
|
+
#
|
95
|
+
# Setting behaviors only affects deprecations that happen after boot time.
|
96
|
+
# Deprecation warnings raised by gems are not affected by this setting
|
97
|
+
# because they happen before \Rails boots up.
|
98
|
+
#
|
99
|
+
# deprecator = ActiveSupport::Deprecation.new
|
100
|
+
# deprecator.behavior = :stderr
|
101
|
+
# deprecator.behavior = [:stderr, :log]
|
102
|
+
# deprecator.behavior = MyCustomHandler
|
103
|
+
# deprecator.behavior = ->(message, callstack, deprecation_horizon, gem_name) {
|
104
|
+
# # custom stuff
|
105
|
+
# }
|
106
|
+
#
|
107
|
+
# If you are using \Rails, you can set
|
108
|
+
# <tt>config.active_support.report_deprecations = false</tt> to disable
|
109
|
+
# all deprecation behaviors. This is similar to the +:silence+ option but
|
110
|
+
# more performant.
|
111
|
+
def behavior=(behavior)
|
112
|
+
@behavior = Array(behavior).map { |b| DEFAULT_BEHAVIORS[b] || arity_coerce(b) }
|
113
|
+
end
|
114
|
+
|
115
|
+
# Sets the behavior for disallowed deprecations (those configured by
|
116
|
+
# ActiveSupport::Deprecation#disallowed_warnings=) to the specified
|
117
|
+
# value. As with #behavior=, this can be a single value, array, or an
|
118
|
+
# object that responds to +call+.
|
119
|
+
def disallowed_behavior=(behavior)
|
120
|
+
@disallowed_behavior = Array(behavior).map { |b| DEFAULT_BEHAVIORS[b] || arity_coerce(b) }
|
121
|
+
end
|
122
|
+
|
123
|
+
private
|
124
|
+
def arity_coerce(behavior)
|
125
|
+
unless behavior.respond_to?(:call)
|
126
|
+
raise ArgumentError, "#{behavior.inspect} is not a valid deprecation behavior."
|
127
|
+
end
|
128
|
+
|
129
|
+
case arity_of_callable(behavior)
|
130
|
+
when 2
|
131
|
+
->(message, callstack, deprecator) do
|
132
|
+
behavior.call(message, callstack)
|
133
|
+
end
|
134
|
+
when -2..3
|
135
|
+
behavior
|
136
|
+
else
|
137
|
+
->(message, callstack, deprecator) do
|
138
|
+
behavior.call(message, callstack, deprecator.deprecation_horizon, deprecator.gem_name)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def arity_of_callable(callable)
|
144
|
+
callable.respond_to?(:arity) ? callable.arity : callable.method(:call).arity
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
class Deprecation
|
5
|
+
module DeprecatedConstantAccessor
|
6
|
+
def self.included(base)
|
7
|
+
require "active_support/inflector/methods"
|
8
|
+
|
9
|
+
extension = Module.new do
|
10
|
+
def const_missing(missing_const_name)
|
11
|
+
if class_variable_defined?(:@@_deprecated_constants)
|
12
|
+
if (replacement = class_variable_get(:@@_deprecated_constants)[missing_const_name.to_s])
|
13
|
+
replacement[:deprecator].warn(replacement[:message] || "#{name}::#{missing_const_name} is deprecated! Use #{replacement[:new]} instead.", caller_locations)
|
14
|
+
return ActiveSupport::Inflector.constantize(replacement[:new].to_s)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
# Provides a way to rename constants with a deprecation cycle in which
|
21
|
+
# both the old and new names work, but using the old one prints a
|
22
|
+
# deprecation message.
|
23
|
+
#
|
24
|
+
# In order to rename <tt>A::B</tt> to <tt>C::D</tt>, you need to delete the
|
25
|
+
# definition of <tt>A::B</tt> and declare the deprecation in +A+:
|
26
|
+
#
|
27
|
+
# require "active_support/deprecation"
|
28
|
+
#
|
29
|
+
# module A
|
30
|
+
# include ActiveSupport::Deprecation::DeprecatedConstantAccessor
|
31
|
+
#
|
32
|
+
# deprecate_constant "B", "C::D", deprecator: ActiveSupport::Deprecation.new
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# The first argument is a constant name (no colons). It is the name of
|
36
|
+
# the constant you want to deprecate in the enclosing class or module.
|
37
|
+
#
|
38
|
+
# The second argument is the constant path of the replacement. That
|
39
|
+
# has to be a full path even if the replacement is defined in the same
|
40
|
+
# namespace as the deprecated one was.
|
41
|
+
#
|
42
|
+
# In both cases, strings and symbols are supported.
|
43
|
+
#
|
44
|
+
# The +deprecator+ keyword argument is the object that will print the
|
45
|
+
# deprecation message, an instance of ActiveSupport::Deprecation.
|
46
|
+
#
|
47
|
+
# With that in place, references to <tt>A::B</tt> still work, they
|
48
|
+
# evaluate to <tt>C::D</tt> now, and trigger a deprecation warning:
|
49
|
+
#
|
50
|
+
# DEPRECATION WARNING: A::B is deprecated! Use C::D instead.
|
51
|
+
# (called from ...)
|
52
|
+
#
|
53
|
+
# The message can be customized with the optional +message+ keyword
|
54
|
+
# argument.
|
55
|
+
#
|
56
|
+
# For this to work, a +const_missing+ hook is installed. When client
|
57
|
+
# code references the deprecated constant, the callback prints the
|
58
|
+
# message and constantizes the replacement.
|
59
|
+
#
|
60
|
+
# Caveat: If the deprecated constant name is reachable in a different
|
61
|
+
# namespace and Ruby constant lookup finds it, the hook won't be
|
62
|
+
# called and the deprecation won't work as intended. This may happen,
|
63
|
+
# for example, if an ancestor of the enclosing namespace has a
|
64
|
+
# constant with the same name. This is an unsupported edge case.
|
65
|
+
def deprecate_constant(old_constant_name, new_constant_path, deprecator:, message: nil)
|
66
|
+
class_variable_set(:@@_deprecated_constants, {}) unless class_variable_defined?(:@@_deprecated_constants)
|
67
|
+
class_variable_get(:@@_deprecated_constants)[old_constant_name.to_s] = { new: new_constant_path, message: message, deprecator: deprecator }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
base.singleton_class.prepend extension
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
class Deprecation
|
5
|
+
# A managed collection of deprecators. Configuration methods, such as
|
6
|
+
# #behavior=, affect all deprecators in the collection. Additionally, the
|
7
|
+
# #silence method silences all deprecators in the collection for the
|
8
|
+
# duration of a given block.
|
9
|
+
class Deprecators
|
10
|
+
def initialize
|
11
|
+
@options = {}
|
12
|
+
@deprecators = {}
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns a deprecator added to this collection via #[]=.
|
16
|
+
def [](name)
|
17
|
+
@deprecators[name]
|
18
|
+
end
|
19
|
+
|
20
|
+
# Adds a given +deprecator+ to this collection. The deprecator will be
|
21
|
+
# immediately configured with any options previously set on this
|
22
|
+
# collection.
|
23
|
+
#
|
24
|
+
# deprecators = ActiveSupport::Deprecation::Deprecators.new
|
25
|
+
# deprecators.debug = true
|
26
|
+
#
|
27
|
+
# foo_deprecator = ActiveSupport::Deprecation.new("2.0", "Foo")
|
28
|
+
# foo_deprecator.debug # => false
|
29
|
+
#
|
30
|
+
# deprecators[:foo] = foo_deprecator
|
31
|
+
# deprecators[:foo].debug # => true
|
32
|
+
# foo_deprecator.debug # => true
|
33
|
+
#
|
34
|
+
def []=(name, deprecator)
|
35
|
+
apply_options(deprecator)
|
36
|
+
@deprecators[name] = deprecator
|
37
|
+
end
|
38
|
+
|
39
|
+
# Iterates over all deprecators in this collection. If no block is given,
|
40
|
+
# returns an +Enumerator+.
|
41
|
+
def each(&block)
|
42
|
+
return to_enum(__method__) unless block
|
43
|
+
@deprecators.each_value(&block)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Sets the silenced flag for all deprecators in this collection.
|
47
|
+
def silenced=(silenced)
|
48
|
+
set_option(:silenced, silenced)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Sets the debug flag for all deprecators in this collection.
|
52
|
+
def debug=(debug)
|
53
|
+
set_option(:debug, debug)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Sets the deprecation warning behavior for all deprecators in this
|
57
|
+
# collection.
|
58
|
+
#
|
59
|
+
# See ActiveSupport::Deprecation#behavior=.
|
60
|
+
def behavior=(behavior)
|
61
|
+
set_option(:behavior, behavior)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Sets the disallowed deprecation warning behavior for all deprecators in
|
65
|
+
# this collection.
|
66
|
+
#
|
67
|
+
# See ActiveSupport::Deprecation#disallowed_behavior=.
|
68
|
+
def disallowed_behavior=(disallowed_behavior)
|
69
|
+
set_option(:disallowed_behavior, disallowed_behavior)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Sets the disallowed deprecation warnings for all deprecators in this
|
73
|
+
# collection.
|
74
|
+
#
|
75
|
+
# See ActiveSupport::Deprecation#disallowed_warnings=.
|
76
|
+
def disallowed_warnings=(disallowed_warnings)
|
77
|
+
set_option(:disallowed_warnings, disallowed_warnings)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Silences all deprecators in this collection for the duration of the
|
81
|
+
# given block.
|
82
|
+
#
|
83
|
+
# See ActiveSupport::Deprecation#silence.
|
84
|
+
def silence(&block)
|
85
|
+
each { |deprecator| deprecator.begin_silence }
|
86
|
+
block.call
|
87
|
+
ensure
|
88
|
+
each { |deprecator| deprecator.end_silence }
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
def set_option(name, value)
|
93
|
+
@options[name] = value
|
94
|
+
each { |deprecator| deprecator.public_send("#{name}=", value) }
|
95
|
+
end
|
96
|
+
|
97
|
+
def apply_options(deprecator)
|
98
|
+
@options.each do |name, value|
|
99
|
+
deprecator.public_send("#{name}=", value)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
class Deprecation
|
5
|
+
module Disallowed
|
6
|
+
# Sets the criteria used to identify deprecation messages which should be
|
7
|
+
# disallowed. Can be an array containing strings, symbols, or regular
|
8
|
+
# expressions. (Symbols are treated as strings.) These are compared against
|
9
|
+
# the text of the generated deprecation warning.
|
10
|
+
#
|
11
|
+
# Additionally the scalar symbol +:all+ may be used to treat all
|
12
|
+
# deprecations as disallowed.
|
13
|
+
#
|
14
|
+
# Deprecations matching a substring or regular expression will be handled
|
15
|
+
# using the configured Behavior#disallowed_behavior rather than
|
16
|
+
# Behavior#behavior.
|
17
|
+
attr_writer :disallowed_warnings
|
18
|
+
|
19
|
+
# Returns the configured criteria used to identify deprecation messages
|
20
|
+
# which should be treated as disallowed.
|
21
|
+
def disallowed_warnings
|
22
|
+
@disallowed_warnings ||= []
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def deprecation_disallowed?(message)
|
27
|
+
return false if explicitly_allowed?(message)
|
28
|
+
return true if disallowed_warnings == :all
|
29
|
+
message && disallowed_warnings.any? do |rule|
|
30
|
+
case rule
|
31
|
+
when String, Symbol
|
32
|
+
message.include?(rule.to_s)
|
33
|
+
when Regexp
|
34
|
+
rule.match?(message)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def explicitly_allowed?(message)
|
40
|
+
allowances = @explicitly_allowed_warnings.value
|
41
|
+
return false unless allowances
|
42
|
+
return true if allowances == :all
|
43
|
+
message && Array(allowances).any? do |rule|
|
44
|
+
case rule
|
45
|
+
when String, Symbol
|
46
|
+
message.include?(rule.to_s)
|
47
|
+
when Regexp
|
48
|
+
rule.match?(message)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/array/extract_options"
|
4
|
+
require "active_support/core_ext/module/redefine_method"
|
5
|
+
|
6
|
+
module ActiveSupport
|
7
|
+
class Deprecation
|
8
|
+
module MethodWrapper
|
9
|
+
# Declare that a method has been deprecated.
|
10
|
+
#
|
11
|
+
# class Fred
|
12
|
+
# def aaa; end
|
13
|
+
# def bbb; end
|
14
|
+
# def ccc; end
|
15
|
+
# def ddd; end
|
16
|
+
# def eee; end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# deprecator = ActiveSupport::Deprecation.new('next-release', 'MyGem')
|
20
|
+
#
|
21
|
+
# deprecator.deprecate_methods(Fred, :aaa, bbb: :zzz, ccc: 'use Bar#ccc instead')
|
22
|
+
# # => Fred
|
23
|
+
#
|
24
|
+
# Fred.new.aaa
|
25
|
+
# # DEPRECATION WARNING: aaa is deprecated and will be removed from MyGem next-release. (called from irb_binding at (irb):10)
|
26
|
+
# # => nil
|
27
|
+
#
|
28
|
+
# Fred.new.bbb
|
29
|
+
# # DEPRECATION WARNING: bbb is deprecated and will be removed from MyGem next-release (use zzz instead). (called from irb_binding at (irb):11)
|
30
|
+
# # => nil
|
31
|
+
#
|
32
|
+
# Fred.new.ccc
|
33
|
+
# # DEPRECATION WARNING: ccc is deprecated and will be removed from MyGem next-release (use Bar#ccc instead). (called from irb_binding at (irb):12)
|
34
|
+
# # => nil
|
35
|
+
def deprecate_methods(target_module, *method_names)
|
36
|
+
options = method_names.extract_options!
|
37
|
+
deprecator = options.delete(:deprecator) || self
|
38
|
+
method_names += options.keys
|
39
|
+
mod = nil
|
40
|
+
|
41
|
+
method_names.each do |method_name|
|
42
|
+
message = options[method_name]
|
43
|
+
if target_module.method_defined?(method_name) || target_module.private_method_defined?(method_name)
|
44
|
+
method = target_module.instance_method(method_name)
|
45
|
+
target_module.module_eval do
|
46
|
+
redefine_method(method_name) do |*args, &block|
|
47
|
+
deprecator.deprecation_warning(method_name, message)
|
48
|
+
method.bind_call(self, *args, &block)
|
49
|
+
end
|
50
|
+
ruby2_keywords(method_name)
|
51
|
+
end
|
52
|
+
else
|
53
|
+
mod ||= Module.new
|
54
|
+
mod.module_eval do
|
55
|
+
define_method(method_name) do |*args, &block|
|
56
|
+
deprecator.deprecation_warning(method_name, message)
|
57
|
+
super(*args, &block)
|
58
|
+
end
|
59
|
+
ruby2_keywords(method_name)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
target_module.prepend(mod) if mod
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|