activesupport 5.1.7 → 5.2.7
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 +424 -512
- data/MIT-LICENSE +1 -1
- data/README.rdoc +3 -3
- data/lib/active_support/all.rb +2 -0
- data/lib/active_support/array_inquirer.rb +2 -0
- data/lib/active_support/backtrace_cleaner.rb +2 -0
- data/lib/active_support/benchmarkable.rb +2 -0
- data/lib/active_support/builder.rb +2 -0
- data/lib/active_support/cache/file_store.rb +5 -4
- data/lib/active_support/cache/mem_cache_store.rb +39 -38
- data/lib/active_support/cache/memory_store.rb +2 -0
- data/lib/active_support/cache/null_store.rb +2 -0
- data/lib/active_support/cache/redis_cache_store.rb +466 -0
- data/lib/active_support/cache/strategy/local_cache.rb +33 -2
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +2 -0
- data/lib/active_support/cache.rb +197 -83
- data/lib/active_support/callbacks.rb +28 -39
- data/lib/active_support/concern.rb +10 -4
- data/lib/active_support/concurrency/share_lock.rb +2 -0
- data/lib/active_support/configurable.rb +2 -0
- data/lib/active_support/core_ext/array/access.rb +4 -2
- data/lib/active_support/core_ext/array/conversions.rb +2 -0
- data/lib/active_support/core_ext/array/extract_options.rb +2 -0
- data/lib/active_support/core_ext/array/grouping.rb +2 -0
- data/lib/active_support/core_ext/array/inquiry.rb +2 -0
- data/lib/active_support/core_ext/array/prepend_and_append.rb +4 -2
- data/lib/active_support/core_ext/array/wrap.rb +2 -0
- data/lib/active_support/core_ext/array.rb +2 -0
- data/lib/active_support/core_ext/benchmark.rb +2 -0
- data/lib/active_support/core_ext/big_decimal/conversions.rb +2 -0
- data/lib/active_support/core_ext/big_decimal.rb +2 -0
- data/lib/active_support/core_ext/class/attribute.rb +34 -16
- data/lib/active_support/core_ext/class/attribute_accessors.rb +2 -0
- data/lib/active_support/core_ext/class/subclasses.rb +1 -2
- data/lib/active_support/core_ext/class.rb +2 -0
- data/lib/active_support/core_ext/date/acts_like.rb +2 -0
- data/lib/active_support/core_ext/date/blank.rb +2 -0
- data/lib/active_support/core_ext/date/calculations.rb +2 -0
- data/lib/active_support/core_ext/date/conversions.rb +10 -9
- data/lib/active_support/core_ext/date/zones.rb +2 -0
- data/lib/active_support/core_ext/date.rb +2 -0
- data/lib/active_support/core_ext/date_and_time/calculations.rb +50 -16
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +3 -1
- data/lib/active_support/core_ext/date_and_time/zones.rb +2 -0
- data/lib/active_support/core_ext/date_time/acts_like.rb +2 -0
- data/lib/active_support/core_ext/date_time/blank.rb +2 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +2 -0
- data/lib/active_support/core_ext/date_time/compatibility.rb +7 -5
- data/lib/active_support/core_ext/date_time/conversions.rb +2 -0
- data/lib/active_support/core_ext/date_time.rb +2 -0
- data/lib/active_support/core_ext/digest/uuid.rb +3 -1
- data/lib/active_support/core_ext/digest.rb +3 -0
- data/lib/active_support/core_ext/enumerable.rb +8 -1
- data/lib/active_support/core_ext/file/atomic.rb +3 -1
- data/lib/active_support/core_ext/file.rb +2 -0
- data/lib/active_support/core_ext/hash/compact.rb +2 -0
- data/lib/active_support/core_ext/hash/conversions.rb +4 -2
- data/lib/active_support/core_ext/hash/deep_merge.rb +8 -12
- data/lib/active_support/core_ext/hash/except.rb +2 -0
- data/lib/active_support/core_ext/hash/indifferent_access.rb +2 -0
- data/lib/active_support/core_ext/hash/keys.rb +2 -0
- data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
- data/lib/active_support/core_ext/hash/slice.rb +4 -4
- data/lib/active_support/core_ext/hash/transform_values.rb +2 -0
- data/lib/active_support/core_ext/hash.rb +2 -0
- data/lib/active_support/core_ext/integer/inflections.rb +2 -0
- data/lib/active_support/core_ext/integer/multiple.rb +2 -0
- data/lib/active_support/core_ext/integer/time.rb +7 -14
- data/lib/active_support/core_ext/integer.rb +2 -0
- data/lib/active_support/core_ext/kernel/agnostics.rb +2 -0
- data/lib/active_support/core_ext/kernel/concern.rb +2 -0
- data/lib/active_support/core_ext/kernel/reporting.rb +2 -0
- data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
- data/lib/active_support/core_ext/kernel.rb +2 -0
- data/lib/active_support/core_ext/load_error.rb +2 -7
- data/lib/active_support/core_ext/marshal.rb +2 -0
- data/lib/active_support/core_ext/module/aliasing.rb +2 -0
- data/lib/active_support/core_ext/module/anonymous.rb +2 -0
- data/lib/active_support/core_ext/module/attr_internal.rb +2 -0
- data/lib/active_support/core_ext/module/attribute_accessors.rb +21 -24
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +2 -0
- data/lib/active_support/core_ext/module/concerning.rb +7 -8
- data/lib/active_support/core_ext/module/delegation.rb +31 -29
- data/lib/active_support/core_ext/module/deprecation.rb +2 -0
- data/lib/active_support/core_ext/module/introspection.rb +2 -0
- data/lib/active_support/core_ext/module/reachable.rb +3 -0
- data/lib/active_support/core_ext/module/redefine_method.rb +49 -0
- data/lib/active_support/core_ext/module/remove_method.rb +5 -23
- data/lib/active_support/core_ext/module.rb +3 -0
- data/lib/active_support/core_ext/name_error.rb +7 -0
- data/lib/active_support/core_ext/numeric/bytes.rb +2 -0
- data/lib/active_support/core_ext/numeric/conversions.rb +9 -7
- data/lib/active_support/core_ext/numeric/inquiry.rb +2 -0
- data/lib/active_support/core_ext/numeric/time.rb +7 -15
- data/lib/active_support/core_ext/numeric.rb +2 -0
- data/lib/active_support/core_ext/object/acts_like.rb +12 -1
- data/lib/active_support/core_ext/object/blank.rb +12 -1
- data/lib/active_support/core_ext/object/conversions.rb +2 -0
- data/lib/active_support/core_ext/object/deep_dup.rb +2 -0
- data/lib/active_support/core_ext/object/duplicable.rb +10 -8
- data/lib/active_support/core_ext/object/inclusion.rb +2 -0
- data/lib/active_support/core_ext/object/instance_variables.rb +2 -0
- data/lib/active_support/core_ext/object/json.rb +8 -0
- data/lib/active_support/core_ext/object/to_param.rb +2 -0
- data/lib/active_support/core_ext/object/to_query.rb +2 -0
- data/lib/active_support/core_ext/object/try.rb +2 -0
- data/lib/active_support/core_ext/object/with_options.rb +3 -1
- data/lib/active_support/core_ext/object.rb +2 -0
- data/lib/active_support/core_ext/range/compare_range.rb +61 -0
- data/lib/active_support/core_ext/range/conversions.rb +9 -1
- data/lib/active_support/core_ext/range/each.rb +5 -1
- 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 +4 -1
- data/lib/active_support/core_ext/regexp.rb +2 -0
- data/lib/active_support/core_ext/securerandom.rb +2 -0
- data/lib/active_support/core_ext/string/access.rb +2 -0
- data/lib/active_support/core_ext/string/behavior.rb +2 -0
- data/lib/active_support/core_ext/string/conversions.rb +2 -0
- data/lib/active_support/core_ext/string/exclude.rb +2 -0
- data/lib/active_support/core_ext/string/filters.rb +2 -0
- data/lib/active_support/core_ext/string/indent.rb +2 -0
- data/lib/active_support/core_ext/string/inflections.rb +26 -12
- data/lib/active_support/core_ext/string/inquiry.rb +2 -0
- data/lib/active_support/core_ext/string/multibyte.rb +4 -0
- data/lib/active_support/core_ext/string/output_safety.rb +6 -7
- data/lib/active_support/core_ext/string/starts_ends_with.rb +2 -0
- data/lib/active_support/core_ext/string/strip.rb +2 -0
- data/lib/active_support/core_ext/string/zones.rb +2 -0
- data/lib/active_support/core_ext/string.rb +2 -0
- data/lib/active_support/core_ext/time/acts_like.rb +2 -0
- data/lib/active_support/core_ext/time/calculations.rb +23 -15
- data/lib/active_support/core_ext/time/compatibility.rb +4 -2
- data/lib/active_support/core_ext/time/conversions.rb +2 -0
- data/lib/active_support/core_ext/time/zones.rb +6 -4
- data/lib/active_support/core_ext/time.rb +2 -0
- data/lib/active_support/core_ext/uri.rb +6 -6
- 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 +2 -0
- data/lib/active_support/dependencies.rb +25 -26
- data/lib/active_support/deprecation/behaviors.rb +28 -9
- data/lib/active_support/deprecation/constant_accessor.rb +4 -2
- data/lib/active_support/deprecation/instance_delegator.rb +2 -0
- data/lib/active_support/deprecation/method_wrappers.rb +30 -17
- data/lib/active_support/deprecation/proxy_wrappers.rb +5 -2
- data/lib/active_support/deprecation/reporting.rb +5 -3
- data/lib/active_support/deprecation.rb +4 -2
- 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 +4 -2
- data/lib/active_support/duration/iso8601_serializer.rb +4 -2
- data/lib/active_support/duration.rb +22 -14
- 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 +2 -0
- data/lib/active_support/execution_wrapper.rb +18 -13
- data/lib/active_support/executor.rb +2 -0
- data/lib/active_support/file_update_checker.rb +2 -0
- data/lib/active_support/gem_version.rb +3 -1
- data/lib/active_support/gzip.rb +2 -0
- data/lib/active_support/hash_with_indifferent_access.rb +55 -1
- data/lib/active_support/i18n.rb +3 -1
- data/lib/active_support/i18n_railtie.rb +4 -6
- data/lib/active_support/inflections.rb +2 -0
- data/lib/active_support/inflector/inflections.rb +20 -4
- data/lib/active_support/inflector/methods.rb +43 -24
- data/lib/active_support/inflector/transliterate.rb +17 -8
- data/lib/active_support/inflector.rb +2 -0
- data/lib/active_support/json/decoding.rb +2 -0
- data/lib/active_support/json/encoding.rb +2 -0
- data/lib/active_support/json.rb +2 -0
- data/lib/active_support/key_generator.rb +3 -1
- data/lib/active_support/lazy_load_hooks.rb +2 -0
- data/lib/active_support/log_subscriber/test_helper.rb +2 -0
- data/lib/active_support/log_subscriber.rb +3 -2
- data/lib/active_support/logger.rb +2 -0
- data/lib/active_support/logger_silence.rb +3 -2
- data/lib/active_support/logger_thread_safe_level.rb +4 -1
- data/lib/active_support/message_encryptor.rb +95 -22
- data/lib/active_support/message_verifier.rb +78 -7
- 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 +2 -0
- data/lib/active_support/multibyte/unicode.rb +4 -2
- data/lib/active_support/multibyte.rb +2 -0
- data/lib/active_support/notifications/fanout.rb +4 -2
- data/lib/active_support/notifications/instrumenter.rb +2 -0
- data/lib/active_support/notifications.rb +2 -0
- data/lib/active_support/number_helper/number_converter.rb +2 -0
- data/lib/active_support/number_helper/number_to_currency_converter.rb +2 -0
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +2 -0
- data/lib/active_support/number_helper/number_to_human_converter.rb +2 -0
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +2 -0
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +2 -0
- data/lib/active_support/number_helper/number_to_phone_converter.rb +3 -1
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +2 -20
- data/lib/active_support/number_helper/rounding_helper.rb +6 -4
- data/lib/active_support/number_helper.rb +2 -0
- data/lib/active_support/option_merger.rb +2 -0
- data/lib/active_support/ordered_hash.rb +2 -0
- data/lib/active_support/ordered_options.rb +5 -3
- data/lib/active_support/per_thread_registry.rb +2 -0
- data/lib/active_support/proxy_object.rb +2 -0
- data/lib/active_support/rails.rb +2 -0
- data/lib/active_support/railtie.rb +37 -8
- data/lib/active_support/reloader.rb +8 -6
- data/lib/active_support/rescuable.rb +3 -2
- data/lib/active_support/security_utils.rb +15 -11
- data/lib/active_support/string_inquirer.rb +2 -0
- data/lib/active_support/subscriber.rb +8 -2
- data/lib/active_support/tagged_logging.rb +2 -0
- data/lib/active_support/test_case.rb +3 -2
- data/lib/active_support/testing/assertions.rb +31 -14
- data/lib/active_support/testing/autorun.rb +2 -0
- data/lib/active_support/testing/constant_lookup.rb +2 -0
- data/lib/active_support/testing/declarative.rb +2 -0
- data/lib/active_support/testing/deprecation.rb +2 -0
- data/lib/active_support/testing/file_fixtures.rb +2 -0
- data/lib/active_support/testing/isolation.rb +3 -1
- data/lib/active_support/testing/method_call_assertions.rb +2 -0
- data/lib/active_support/testing/setup_and_teardown.rb +12 -7
- data/lib/active_support/testing/stream.rb +2 -0
- data/lib/active_support/testing/tagged_logging.rb +2 -0
- data/lib/active_support/testing/time_helpers.rb +33 -3
- data/lib/active_support/time.rb +2 -0
- data/lib/active_support/time_with_zone.rb +38 -0
- data/lib/active_support/values/time_zone.rb +20 -8
- data/lib/active_support/version.rb +2 -0
- data/lib/active_support/xml_mini/jdom.rb +4 -2
- data/lib/active_support/xml_mini/libxml.rb +3 -1
- data/lib/active_support/xml_mini/libxmlsax.rb +4 -2
- data/lib/active_support/xml_mini/nokogiri.rb +3 -1
- data/lib/active_support/xml_mini/nokogirisax.rb +3 -1
- data/lib/active_support/xml_mini/rexml.rb +3 -1
- data/lib/active_support/xml_mini.rb +4 -2
- data/lib/active_support.rb +5 -13
- metadata +17 -5
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support/core_ext/module/aliasing"
|
2
4
|
require "active_support/core_ext/array/extract_options"
|
3
5
|
|
@@ -6,9 +8,7 @@ module ActiveSupport
|
|
6
8
|
module MethodWrapper
|
7
9
|
# Declare that a method has been deprecated.
|
8
10
|
#
|
9
|
-
#
|
10
|
-
# extend self
|
11
|
-
#
|
11
|
+
# class Fred
|
12
12
|
# def aaa; end
|
13
13
|
# def bbb; end
|
14
14
|
# def ccc; end
|
@@ -20,15 +20,15 @@ module ActiveSupport
|
|
20
20
|
# ActiveSupport::Deprecation.deprecate_methods(Fred, :aaa, bbb: :zzz, ccc: 'use Bar#ccc instead')
|
21
21
|
# # => Fred
|
22
22
|
#
|
23
|
-
# Fred.aaa
|
23
|
+
# Fred.new.aaa
|
24
24
|
# # DEPRECATION WARNING: aaa is deprecated and will be removed from Rails 5.1. (called from irb_binding at (irb):10)
|
25
25
|
# # => nil
|
26
26
|
#
|
27
|
-
# Fred.bbb
|
27
|
+
# Fred.new.bbb
|
28
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
29
|
# # => nil
|
30
30
|
#
|
31
|
-
# Fred.ccc
|
31
|
+
# Fred.new.ccc
|
32
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
33
|
# # => nil
|
34
34
|
#
|
@@ -37,7 +37,7 @@ module ActiveSupport
|
|
37
37
|
# ActiveSupport::Deprecation.deprecate_methods(Fred, ddd: :zzz, deprecator: custom_deprecator)
|
38
38
|
# # => [:ddd]
|
39
39
|
#
|
40
|
-
# Fred.ddd
|
40
|
+
# Fred.new.ddd
|
41
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
42
|
# # => nil
|
43
43
|
#
|
@@ -46,31 +46,44 @@ module ActiveSupport
|
|
46
46
|
# custom_deprecator.deprecate_methods(Fred, eee: :zzz)
|
47
47
|
# # => [:eee]
|
48
48
|
#
|
49
|
-
# Fred.eee
|
49
|
+
# Fred.new.eee
|
50
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
51
|
# # => nil
|
52
52
|
def deprecate_methods(target_module, *method_names)
|
53
53
|
options = method_names.extract_options!
|
54
54
|
deprecator = options.delete(:deprecator) || self
|
55
55
|
method_names += options.keys
|
56
|
+
mod = Module.new
|
56
57
|
|
57
|
-
|
58
|
-
|
59
|
-
|
58
|
+
method_names.each do |method_name|
|
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|
|
60
65
|
deprecator.deprecation_warning(method_name, options[method_name])
|
61
|
-
|
66
|
+
send(without_method, *args, &block)
|
62
67
|
end
|
63
68
|
|
69
|
+
target_module.send(:alias_method, without_method, method_name)
|
70
|
+
target_module.send(:alias_method, method_name, with_method)
|
71
|
+
|
64
72
|
case
|
65
|
-
when target_module.protected_method_defined?(
|
66
|
-
protected method_name
|
67
|
-
when target_module.private_method_defined?(
|
68
|
-
private method_name
|
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)
|
69
82
|
end
|
70
83
|
end
|
71
84
|
end
|
72
85
|
|
73
|
-
target_module.prepend(mod)
|
86
|
+
target_module.prepend(mod) unless mod.instance_methods(false).empty?
|
74
87
|
end
|
75
88
|
end
|
76
89
|
end
|
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require "active_support/core_ext/regexp"
|
3
4
|
|
4
5
|
module ActiveSupport
|
@@ -112,7 +113,7 @@ module ActiveSupport
|
|
112
113
|
#
|
113
114
|
# PLANETS = %w(mercury venus earth mars jupiter saturn uranus neptune pluto)
|
114
115
|
#
|
115
|
-
# (In a later update, the original implementation of `PLANETS` has been removed.)
|
116
|
+
# # (In a later update, the original implementation of `PLANETS` has been removed.)
|
116
117
|
#
|
117
118
|
# PLANETS_POST_2006 = %w(mercury venus earth mars jupiter saturn uranus neptune)
|
118
119
|
# PLANETS = ActiveSupport::Deprecation::DeprecatedConstantProxy.new('PLANETS', 'PLANETS_POST_2006')
|
@@ -123,6 +124,8 @@ module ActiveSupport
|
|
123
124
|
# ["Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune"]
|
124
125
|
class DeprecatedConstantProxy < DeprecationProxy
|
125
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
|
+
|
126
129
|
@old_const = old_const
|
127
130
|
@new_const = new_const
|
128
131
|
@deprecator = deprecator
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "rbconfig"
|
2
4
|
|
3
5
|
module ActiveSupport
|
@@ -18,7 +20,7 @@ module ActiveSupport
|
|
18
20
|
|
19
21
|
callstack ||= caller_locations(2)
|
20
22
|
deprecation_message(callstack, message).tap do |m|
|
21
|
-
behavior.each { |b| b.call(m, callstack) }
|
23
|
+
behavior.each { |b| b.call(m, callstack, deprecation_horizon, gem_name) }
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
@@ -59,7 +61,7 @@ module ActiveSupport
|
|
59
61
|
case message
|
60
62
|
when Symbol then "#{warning} (use #{message} instead)"
|
61
63
|
when String then "#{warning} (#{message})"
|
62
|
-
|
64
|
+
else warning
|
63
65
|
end
|
64
66
|
end
|
65
67
|
|
@@ -102,7 +104,7 @@ module ActiveSupport
|
|
102
104
|
end
|
103
105
|
end
|
104
106
|
|
105
|
-
RAILS_GEM_ROOT = File.expand_path("
|
107
|
+
RAILS_GEM_ROOT = File.expand_path("../../../..", __dir__) + "/"
|
106
108
|
|
107
109
|
def ignored_callstack(path)
|
108
110
|
path.start_with?(RAILS_GEM_ROOT) || path.start_with?(RbConfig::CONFIG["rubylibdir"])
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "singleton"
|
2
4
|
|
3
5
|
module ActiveSupport
|
@@ -30,10 +32,10 @@ module ActiveSupport
|
|
30
32
|
attr_accessor :deprecation_horizon
|
31
33
|
|
32
34
|
# It accepts two parameters on initialization. The first is a version of library
|
33
|
-
# and the second is a library name
|
35
|
+
# and the second is a library name.
|
34
36
|
#
|
35
37
|
# ActiveSupport::Deprecation.new('2.0', 'MyLibrary')
|
36
|
-
def initialize(deprecation_horizon = "
|
38
|
+
def initialize(deprecation_horizon = "6.0", gem_name = "Rails")
|
37
39
|
self.gem_name = gem_name
|
38
40
|
self.deprecation_horizon = deprecation_horizon
|
39
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
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "strscan"
|
2
4
|
require "active_support/core_ext/regexp"
|
3
5
|
|
@@ -5,7 +7,7 @@ module ActiveSupport
|
|
5
7
|
class Duration
|
6
8
|
# Parses a string formatted according to ISO 8601 Duration into the hash.
|
7
9
|
#
|
8
|
-
# See {ISO 8601}[
|
10
|
+
# See {ISO 8601}[https://en.wikipedia.org/wiki/ISO_8601#Durations] for more information.
|
9
11
|
#
|
10
12
|
# This parser allows negative parts to be present in pattern.
|
11
13
|
class ISO8601Parser # :nodoc:
|
@@ -116,7 +118,7 @@ module ActiveSupport
|
|
116
118
|
raise_parsing_error "(only last part can be fractional)"
|
117
119
|
end
|
118
120
|
|
119
|
-
|
121
|
+
true
|
120
122
|
end
|
121
123
|
end
|
122
124
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support/core_ext/object/blank"
|
2
4
|
require "active_support/core_ext/hash/transform_values"
|
3
5
|
|
@@ -15,12 +17,12 @@ module ActiveSupport
|
|
15
17
|
parts, sign = normalize
|
16
18
|
return "PT0S".freeze if parts.empty?
|
17
19
|
|
18
|
-
output = "P"
|
20
|
+
output = "P".dup
|
19
21
|
output << "#{parts[:years]}Y" if parts.key?(:years)
|
20
22
|
output << "#{parts[:months]}M" if parts.key?(:months)
|
21
23
|
output << "#{parts[:weeks]}W" if parts.key?(:weeks)
|
22
24
|
output << "#{parts[:days]}D" if parts.key?(:days)
|
23
|
-
time = ""
|
25
|
+
time = "".dup
|
24
26
|
time << "#{parts[:hours]}H" if parts.key?(:hours)
|
25
27
|
time << "#{parts[:minutes]}M" if parts.key?(:minutes)
|
26
28
|
if parts.key?(:seconds)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support/core_ext/array/conversions"
|
2
4
|
require "active_support/core_ext/module/delegation"
|
3
5
|
require "active_support/core_ext/object/acts_like"
|
@@ -131,7 +133,7 @@ module ActiveSupport
|
|
131
133
|
class << self
|
132
134
|
# Creates a new Duration from string formatted according to ISO 8601 Duration.
|
133
135
|
#
|
134
|
-
# See {ISO 8601}[
|
136
|
+
# See {ISO 8601}[https://en.wikipedia.org/wiki/ISO_8601#Durations] for more information.
|
135
137
|
# This method allows negative parts to be present in pattern.
|
136
138
|
# If invalid string is provided, it will raise +ActiveSupport::Duration::ISO8601Parser::ParsingError+.
|
137
139
|
def parse(iso8601duration)
|
@@ -181,18 +183,17 @@ module ActiveSupport
|
|
181
183
|
#
|
182
184
|
def build(value)
|
183
185
|
parts = {}
|
184
|
-
remainder = value.
|
186
|
+
remainder = value.round(9)
|
185
187
|
|
186
188
|
PARTS.each do |part|
|
187
189
|
unless part == :seconds
|
188
190
|
part_in_seconds = PARTS_IN_SECONDS[part]
|
189
191
|
parts[part] = remainder.div(part_in_seconds)
|
190
|
-
remainder
|
192
|
+
remainder %= part_in_seconds
|
191
193
|
end
|
192
|
-
end
|
194
|
+
end unless value == 0
|
193
195
|
|
194
196
|
parts[:seconds] = remainder
|
195
|
-
parts.reject! { |k, v| v.zero? }
|
196
197
|
|
197
198
|
new(value, parts)
|
198
199
|
end
|
@@ -209,6 +210,7 @@ module ActiveSupport
|
|
209
210
|
def initialize(value, parts) #:nodoc:
|
210
211
|
@value, @parts = value, parts.to_h
|
211
212
|
@parts.default = 0
|
213
|
+
@parts.reject! { |k, v| v.zero? } unless value == 0
|
212
214
|
end
|
213
215
|
|
214
216
|
def coerce(other) #:nodoc:
|
@@ -368,6 +370,8 @@ module ActiveSupport
|
|
368
370
|
alias :before :ago
|
369
371
|
|
370
372
|
def inspect #:nodoc:
|
373
|
+
return "0 seconds" if parts.empty?
|
374
|
+
|
371
375
|
parts.
|
372
376
|
reduce(::Hash.new(0)) { |h, (l, r)| h[l] += r; h }.
|
373
377
|
sort_by { |unit, _ | PARTS.index(unit) }.
|
@@ -379,10 +383,6 @@ module ActiveSupport
|
|
379
383
|
to_i
|
380
384
|
end
|
381
385
|
|
382
|
-
def respond_to_missing?(method, include_private = false) #:nodoc:
|
383
|
-
@value.respond_to?(method, include_private)
|
384
|
-
end
|
385
|
-
|
386
386
|
def init_with(coder) #:nodoc:
|
387
387
|
initialize(coder["value"], coder["parts"])
|
388
388
|
end
|
@@ -400,8 +400,14 @@ module ActiveSupport
|
|
400
400
|
private
|
401
401
|
|
402
402
|
def sum(sign, time = ::Time.current)
|
403
|
-
|
404
|
-
|
403
|
+
unless time.acts_like?(:time) || time.acts_like?(:date)
|
404
|
+
raise ::ArgumentError, "expected a time or date, got #{time.inspect}"
|
405
|
+
end
|
406
|
+
|
407
|
+
if parts.empty?
|
408
|
+
time.since(sign * value)
|
409
|
+
else
|
410
|
+
parts.inject(time) do |t, (type, number)|
|
405
411
|
if type == :seconds
|
406
412
|
t.since(sign * number)
|
407
413
|
elsif type == :minutes
|
@@ -411,14 +417,16 @@ module ActiveSupport
|
|
411
417
|
else
|
412
418
|
t.advance(type => sign * number)
|
413
419
|
end
|
414
|
-
else
|
415
|
-
raise ::ArgumentError, "expected a time or date, got #{time.inspect}"
|
416
420
|
end
|
417
421
|
end
|
418
422
|
end
|
419
423
|
|
424
|
+
def respond_to_missing?(method, _)
|
425
|
+
value.respond_to?(method)
|
426
|
+
end
|
427
|
+
|
420
428
|
def method_missing(method, *args, &block)
|
421
|
-
value.
|
429
|
+
value.public_send(method, *args, &block)
|
422
430
|
end
|
423
431
|
|
424
432
|
def raise_type_error(other)
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "yaml"
|
4
|
+
require "active_support/encrypted_file"
|
5
|
+
require "active_support/ordered_options"
|
6
|
+
require "active_support/core_ext/object/inclusion"
|
7
|
+
require "active_support/core_ext/module/delegation"
|
8
|
+
|
9
|
+
module ActiveSupport
|
10
|
+
class EncryptedConfiguration < EncryptedFile
|
11
|
+
delegate :[], :fetch, to: :config
|
12
|
+
delegate_missing_to :options
|
13
|
+
|
14
|
+
def initialize(config_path:, key_path:, env_key:, raise_if_missing_key:)
|
15
|
+
super content_path: config_path, key_path: key_path,
|
16
|
+
env_key: env_key, raise_if_missing_key: raise_if_missing_key
|
17
|
+
end
|
18
|
+
|
19
|
+
# Allow a config to be started without a file present
|
20
|
+
def read
|
21
|
+
super
|
22
|
+
rescue ActiveSupport::EncryptedFile::MissingContentError
|
23
|
+
""
|
24
|
+
end
|
25
|
+
|
26
|
+
def write(contents)
|
27
|
+
deserialize(contents)
|
28
|
+
|
29
|
+
super
|
30
|
+
end
|
31
|
+
|
32
|
+
def config
|
33
|
+
@config ||= deserialize(read).deep_symbolize_keys
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def options
|
38
|
+
@options ||= ActiveSupport::InheritableOptions.new(config)
|
39
|
+
end
|
40
|
+
|
41
|
+
def serialize(config)
|
42
|
+
config.present? ? YAML.dump(config) : ""
|
43
|
+
end
|
44
|
+
|
45
|
+
def deserialize(config)
|
46
|
+
YAML.load(config).presence || {}
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pathname"
|
4
|
+
require "active_support/message_encryptor"
|
5
|
+
|
6
|
+
module ActiveSupport
|
7
|
+
class EncryptedFile
|
8
|
+
class MissingContentError < RuntimeError
|
9
|
+
def initialize(content_path)
|
10
|
+
super "Missing encrypted content file in #{content_path}."
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class MissingKeyError < RuntimeError
|
15
|
+
def initialize(key_path:, env_key:)
|
16
|
+
super \
|
17
|
+
"Missing encryption key to decrypt file with. " +
|
18
|
+
"Ask your team for your master key and write it to #{key_path} or put it in the ENV['#{env_key}']."
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
CIPHER = "aes-128-gcm"
|
23
|
+
|
24
|
+
def self.generate_key
|
25
|
+
SecureRandom.hex(ActiveSupport::MessageEncryptor.key_len(CIPHER))
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
attr_reader :content_path, :key_path, :env_key, :raise_if_missing_key
|
30
|
+
|
31
|
+
def initialize(content_path:, key_path:, env_key:, raise_if_missing_key:)
|
32
|
+
@content_path, @key_path = Pathname.new(content_path), Pathname.new(key_path)
|
33
|
+
@env_key, @raise_if_missing_key = env_key, raise_if_missing_key
|
34
|
+
end
|
35
|
+
|
36
|
+
def key
|
37
|
+
read_env_key || read_key_file || handle_missing_key
|
38
|
+
end
|
39
|
+
|
40
|
+
def read
|
41
|
+
if !key.nil? && content_path.exist?
|
42
|
+
decrypt content_path.binread
|
43
|
+
else
|
44
|
+
raise MissingContentError, content_path
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def write(contents)
|
49
|
+
IO.binwrite "#{content_path}.tmp", encrypt(contents)
|
50
|
+
FileUtils.mv "#{content_path}.tmp", content_path
|
51
|
+
end
|
52
|
+
|
53
|
+
def change(&block)
|
54
|
+
writing read, &block
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
private
|
59
|
+
def writing(contents)
|
60
|
+
tmp_file = "#{Process.pid}.#{content_path.basename.to_s.chomp('.enc')}"
|
61
|
+
tmp_path = Pathname.new File.join(Dir.tmpdir, tmp_file)
|
62
|
+
tmp_path.binwrite contents
|
63
|
+
|
64
|
+
yield tmp_path
|
65
|
+
|
66
|
+
updated_contents = tmp_path.binread
|
67
|
+
|
68
|
+
write(updated_contents) if updated_contents != contents
|
69
|
+
ensure
|
70
|
+
FileUtils.rm(tmp_path) if tmp_path.exist?
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
def encrypt(contents)
|
75
|
+
encryptor.encrypt_and_sign contents
|
76
|
+
end
|
77
|
+
|
78
|
+
def decrypt(contents)
|
79
|
+
encryptor.decrypt_and_verify contents
|
80
|
+
end
|
81
|
+
|
82
|
+
def encryptor
|
83
|
+
@encryptor ||= ActiveSupport::MessageEncryptor.new([ key ].pack("H*"), cipher: CIPHER)
|
84
|
+
end
|
85
|
+
|
86
|
+
|
87
|
+
def read_env_key
|
88
|
+
ENV[env_key]
|
89
|
+
end
|
90
|
+
|
91
|
+
def read_key_file
|
92
|
+
key_path.binread.strip if key_path.exist?
|
93
|
+
end
|
94
|
+
|
95
|
+
def handle_missing_key
|
96
|
+
raise MissingKeyError, key_path: key_path, env_key: env_key if raise_if_missing_key
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_support/callbacks"
|
2
4
|
|
3
5
|
module ActiveSupport
|
@@ -60,18 +62,21 @@ module ActiveSupport
|
|
60
62
|
# after the work has been performed.
|
61
63
|
#
|
62
64
|
# Where possible, prefer +wrap+.
|
63
|
-
def self.run!
|
64
|
-
if
|
65
|
-
|
65
|
+
def self.run!(reset: false)
|
66
|
+
if reset
|
67
|
+
lost_instance = active.delete(Thread.current)
|
68
|
+
lost_instance.complete! unless lost_instance.nil?
|
66
69
|
else
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
70
|
+
return Null if active?
|
71
|
+
end
|
72
|
+
|
73
|
+
new.tap do |instance|
|
74
|
+
success = nil
|
75
|
+
begin
|
76
|
+
instance.run!
|
77
|
+
success = true
|
78
|
+
ensure
|
79
|
+
instance.complete! unless success
|
75
80
|
end
|
76
81
|
end
|
77
82
|
end
|
@@ -100,11 +105,11 @@ module ActiveSupport
|
|
100
105
|
self.active = Concurrent::Hash.new
|
101
106
|
|
102
107
|
def self.active? # :nodoc:
|
103
|
-
@active
|
108
|
+
@active.key?(Thread.current)
|
104
109
|
end
|
105
110
|
|
106
111
|
def run! # :nodoc:
|
107
|
-
self.class.active[Thread.current] =
|
112
|
+
self.class.active[Thread.current] = self
|
108
113
|
run_callbacks(:run)
|
109
114
|
end
|
110
115
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveSupport
|
2
4
|
# Returns the version of the currently loaded Active Support as a <tt>Gem::Version</tt>.
|
3
5
|
def self.gem_version
|
@@ -6,7 +8,7 @@ module ActiveSupport
|
|
6
8
|
|
7
9
|
module VERSION
|
8
10
|
MAJOR = 5
|
9
|
-
MINOR =
|
11
|
+
MINOR = 2
|
10
12
|
TINY = 7
|
11
13
|
PRE = nil
|
12
14
|
|