activesupport 5.0.0 → 6.1.0
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 +5 -5
- data/CHANGELOG.md +343 -590
- data/MIT-LICENSE +1 -1
- data/README.rdoc +5 -4
- data/lib/active_support/actionable_error.rb +48 -0
- data/lib/active_support/all.rb +5 -3
- data/lib/active_support/array_inquirer.rb +11 -5
- data/lib/active_support/backtrace_cleaner.rb +33 -5
- data/lib/active_support/benchmarkable.rb +5 -3
- data/lib/active_support/builder.rb +3 -1
- data/lib/active_support/cache/file_store.rb +45 -53
- data/lib/active_support/cache/mem_cache_store.rb +81 -79
- data/lib/active_support/cache/memory_store.rb +69 -41
- data/lib/active_support/cache/null_store.rb +11 -4
- data/lib/active_support/cache/redis_cache_store.rb +493 -0
- data/lib/active_support/cache/strategy/local_cache.rb +74 -37
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +10 -9
- data/lib/active_support/cache.rb +332 -161
- data/lib/active_support/callbacks.rb +657 -586
- data/lib/active_support/concern.rb +79 -6
- data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +35 -0
- data/lib/active_support/concurrency/share_lock.rb +59 -19
- data/lib/active_support/configurable.rb +15 -17
- data/lib/active_support/configuration_file.rb +46 -0
- data/lib/active_support/core_ext/array/access.rb +21 -7
- data/lib/active_support/core_ext/array/conversions.rb +20 -18
- data/lib/active_support/core_ext/array/extract.rb +21 -0
- data/lib/active_support/core_ext/array/extract_options.rb +2 -0
- data/lib/active_support/core_ext/array/grouping.rb +3 -1
- data/lib/active_support/core_ext/array/inquiry.rb +3 -1
- data/lib/active_support/core_ext/array/wrap.rb +2 -0
- data/lib/active_support/core_ext/array.rb +9 -7
- data/lib/active_support/core_ext/benchmark.rb +5 -3
- data/lib/active_support/core_ext/big_decimal/conversions.rb +6 -6
- data/lib/active_support/core_ext/big_decimal.rb +3 -1
- data/lib/active_support/core_ext/class/attribute.rb +52 -49
- data/lib/active_support/core_ext/class/attribute_accessors.rb +3 -1
- data/lib/active_support/core_ext/class/subclasses.rb +18 -26
- data/lib/active_support/core_ext/class.rb +4 -2
- data/lib/active_support/core_ext/date/acts_like.rb +3 -1
- data/lib/active_support/core_ext/date/blank.rb +3 -1
- data/lib/active_support/core_ext/date/calculations.rb +16 -13
- data/lib/active_support/core_ext/date/conversions.rb +23 -21
- data/lib/active_support/core_ext/date/zones.rb +4 -2
- data/lib/active_support/core_ext/date.rb +7 -5
- data/lib/active_support/core_ext/date_and_time/calculations.rb +82 -53
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +18 -5
- data/lib/active_support/core_ext/date_and_time/zones.rb +9 -9
- data/lib/active_support/core_ext/date_time/acts_like.rb +4 -2
- data/lib/active_support/core_ext/date_time/blank.rb +3 -1
- data/lib/active_support/core_ext/date_time/calculations.rb +23 -11
- data/lib/active_support/core_ext/date_time/compatibility.rb +15 -2
- data/lib/active_support/core_ext/date_time/conversions.rb +14 -13
- data/lib/active_support/core_ext/date_time.rb +7 -5
- data/lib/active_support/core_ext/digest/uuid.rb +7 -5
- data/lib/active_support/core_ext/digest.rb +3 -0
- data/lib/active_support/core_ext/enumerable.rb +165 -29
- data/lib/active_support/core_ext/file/atomic.rb +7 -5
- data/lib/active_support/core_ext/file.rb +3 -1
- data/lib/active_support/core_ext/hash/conversions.rb +40 -39
- data/lib/active_support/core_ext/hash/deep_merge.rb +8 -12
- data/lib/active_support/core_ext/hash/deep_transform_values.rb +46 -0
- data/lib/active_support/core_ext/hash/except.rb +4 -2
- data/lib/active_support/core_ext/hash/indifferent_access.rb +3 -2
- data/lib/active_support/core_ext/hash/keys.rb +9 -36
- data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
- data/lib/active_support/core_ext/hash/slice.rb +8 -29
- data/lib/active_support/core_ext/hash.rb +10 -9
- data/lib/active_support/core_ext/integer/inflections.rb +3 -1
- data/lib/active_support/core_ext/integer/multiple.rb +3 -1
- data/lib/active_support/core_ext/integer/time.rb +11 -18
- data/lib/active_support/core_ext/integer.rb +5 -3
- data/lib/active_support/core_ext/kernel/concern.rb +3 -1
- data/lib/active_support/core_ext/kernel/reporting.rb +3 -1
- data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
- data/lib/active_support/core_ext/kernel.rb +5 -4
- data/lib/active_support/core_ext/load_error.rb +2 -23
- data/lib/active_support/core_ext/marshal.rb +6 -2
- data/lib/active_support/core_ext/module/aliasing.rb +5 -48
- data/lib/active_support/core_ext/module/anonymous.rb +2 -0
- data/lib/active_support/core_ext/module/attr_internal.rb +7 -5
- data/lib/active_support/core_ext/module/attribute_accessors.rb +53 -59
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +31 -24
- data/lib/active_support/core_ext/module/concerning.rb +16 -11
- data/lib/active_support/core_ext/module/delegation.rb +159 -44
- data/lib/active_support/core_ext/module/deprecation.rb +2 -0
- data/lib/active_support/core_ext/module/introspection.rb +23 -26
- data/lib/active_support/core_ext/module/redefine_method.rb +40 -0
- data/lib/active_support/core_ext/module/remove_method.rb +5 -23
- data/lib/active_support/core_ext/module.rb +13 -12
- data/lib/active_support/core_ext/name_error.rb +36 -2
- data/lib/active_support/core_ext/numeric/bytes.rb +2 -0
- data/lib/active_support/core_ext/numeric/conversions.rb +129 -134
- data/lib/active_support/core_ext/numeric/time.rb +18 -26
- data/lib/active_support/core_ext/numeric.rb +5 -4
- data/lib/active_support/core_ext/object/acts_like.rb +12 -1
- data/lib/active_support/core_ext/object/blank.rb +14 -2
- data/lib/active_support/core_ext/object/conversions.rb +6 -4
- data/lib/active_support/core_ext/object/deep_dup.rb +4 -2
- data/lib/active_support/core_ext/object/duplicable.rb +13 -62
- data/lib/active_support/core_ext/object/inclusion.rb +3 -1
- data/lib/active_support/core_ext/object/instance_variables.rb +2 -0
- data/lib/active_support/core_ext/object/json.rb +42 -15
- 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 +20 -8
- data/lib/active_support/core_ext/object/with_options.rb +15 -2
- data/lib/active_support/core_ext/object.rb +14 -12
- data/lib/active_support/core_ext/range/compare_range.rb +82 -0
- data/lib/active_support/core_ext/range/conversions.rb +35 -25
- data/lib/active_support/core_ext/range/each.rb +5 -2
- data/lib/active_support/core_ext/range/include_time_with_zone.rb +28 -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 +10 -1
- data/lib/active_support/core_ext/securerandom.rb +28 -6
- data/lib/active_support/core_ext/string/access.rb +9 -18
- data/lib/active_support/core_ext/string/behavior.rb +2 -0
- data/lib/active_support/core_ext/string/conversions.rb +5 -2
- data/lib/active_support/core_ext/string/exclude.rb +2 -0
- data/lib/active_support/core_ext/string/filters.rb +47 -4
- data/lib/active_support/core_ext/string/indent.rb +6 -4
- data/lib/active_support/core_ext/string/inflections.rb +78 -29
- data/lib/active_support/core_ext/string/inquiry.rb +4 -1
- data/lib/active_support/core_ext/string/multibyte.rb +10 -5
- data/lib/active_support/core_ext/string/output_safety.rb +86 -31
- data/lib/active_support/core_ext/string/starts_ends_with.rb +4 -2
- data/lib/active_support/core_ext/string/strip.rb +5 -1
- 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/symbol/starts_ends_with.rb +14 -0
- data/lib/active_support/core_ext/symbol.rb +3 -0
- data/lib/active_support/core_ext/time/acts_like.rb +3 -1
- data/lib/active_support/core_ext/time/calculations.rb +117 -45
- data/lib/active_support/core_ext/time/compatibility.rb +13 -2
- data/lib/active_support/core_ext/time/conversions.rb +18 -12
- data/lib/active_support/core_ext/time/zones.rb +9 -7
- data/lib/active_support/core_ext/time.rb +7 -5
- data/lib/active_support/core_ext/uri.rb +12 -7
- data/lib/active_support/core_ext.rb +3 -2
- data/lib/active_support/current_attributes/test_helper.rb +13 -0
- data/lib/active_support/current_attributes.rb +208 -0
- data/lib/active_support/dependencies/autoload.rb +2 -0
- data/lib/active_support/dependencies/interlock.rb +7 -1
- data/lib/active_support/dependencies/zeitwerk_integration.rb +117 -0
- data/lib/active_support/dependencies.rb +172 -98
- data/lib/active_support/deprecation/behaviors.rb +45 -13
- data/lib/active_support/deprecation/constant_accessor.rb +52 -0
- data/lib/active_support/deprecation/disallowed.rb +56 -0
- data/lib/active_support/deprecation/instance_delegator.rb +16 -2
- data/lib/active_support/deprecation/method_wrappers.rb +32 -17
- data/lib/active_support/deprecation/proxy_wrappers.rb +35 -7
- data/lib/active_support/deprecation/reporting.rb +61 -16
- data/lib/active_support/deprecation.rb +17 -9
- data/lib/active_support/descendants_tracker.rb +61 -9
- data/lib/active_support/digest.rb +20 -0
- data/lib/active_support/duration/iso8601_parser.rb +67 -66
- data/lib/active_support/duration/iso8601_serializer.rb +25 -17
- data/lib/active_support/duration.rb +349 -46
- data/lib/active_support/encrypted_configuration.rb +45 -0
- data/lib/active_support/encrypted_file.rb +117 -0
- data/lib/active_support/environment_inquirer.rb +20 -0
- data/lib/active_support/evented_file_update_checker.rb +88 -112
- data/lib/active_support/execution_wrapper.rb +25 -13
- data/lib/active_support/executor.rb +3 -1
- data/lib/active_support/file_update_checker.rb +56 -51
- data/lib/active_support/fork_tracker.rb +62 -0
- data/lib/active_support/gem_version.rb +4 -2
- data/lib/active_support/gzip.rb +7 -5
- data/lib/active_support/hash_with_indifferent_access.rb +153 -49
- data/lib/active_support/i18n.rb +9 -6
- data/lib/active_support/i18n_railtie.rb +30 -20
- data/lib/active_support/inflections.rb +13 -11
- data/lib/active_support/inflector/inflections.rb +28 -15
- data/lib/active_support/inflector/methods.rb +120 -109
- data/lib/active_support/inflector/transliterate.rb +60 -25
- data/lib/active_support/inflector.rb +7 -5
- data/lib/active_support/json/decoding.rb +30 -29
- data/lib/active_support/json/encoding.rb +22 -11
- data/lib/active_support/json.rb +4 -2
- data/lib/active_support/key_generator.rb +6 -36
- data/lib/active_support/lazy_load_hooks.rb +53 -20
- data/lib/active_support/locale/en.rb +33 -0
- data/lib/active_support/locale/en.yml +7 -3
- data/lib/active_support/log_subscriber/test_helper.rb +11 -9
- data/lib/active_support/log_subscriber.rb +51 -18
- data/lib/active_support/logger.rb +9 -22
- data/lib/active_support/logger_silence.rb +14 -21
- data/lib/active_support/logger_thread_safe_level.rb +55 -8
- data/lib/active_support/message_encryptor.rb +170 -53
- data/lib/active_support/message_verifier.rb +91 -20
- data/lib/active_support/messages/metadata.rb +80 -0
- data/lib/active_support/messages/rotation_configuration.rb +23 -0
- data/lib/active_support/messages/rotator.rb +57 -0
- data/lib/active_support/multibyte/chars.rb +24 -78
- data/lib/active_support/multibyte/unicode.rb +21 -352
- data/lib/active_support/multibyte.rb +4 -2
- data/lib/active_support/notifications/fanout.rb +121 -19
- data/lib/active_support/notifications/instrumenter.rb +78 -14
- data/lib/active_support/notifications.rb +80 -12
- data/lib/active_support/number_helper/number_converter.rb +17 -16
- data/lib/active_support/number_helper/number_to_currency_converter.rb +6 -9
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +5 -3
- data/lib/active_support/number_helper/number_to_human_converter.rb +13 -12
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +11 -13
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +5 -1
- data/lib/active_support/number_helper/number_to_phone_converter.rb +5 -4
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +18 -55
- data/lib/active_support/number_helper/rounding_helper.rb +50 -0
- data/lib/active_support/number_helper.rb +45 -16
- data/lib/active_support/option_merger.rb +25 -4
- data/lib/active_support/ordered_hash.rb +6 -4
- data/lib/active_support/ordered_options.rb +23 -9
- data/lib/active_support/parameter_filter.rb +133 -0
- data/lib/active_support/per_thread_registry.rb +7 -5
- data/lib/active_support/proxy_object.rb +2 -0
- data/lib/active_support/rails.rb +8 -9
- data/lib/active_support/railtie.rb +62 -11
- data/lib/active_support/reloader.rb +12 -11
- data/lib/active_support/rescuable.rb +20 -11
- data/lib/active_support/secure_compare_rotator.rb +51 -0
- data/lib/active_support/security_utils.rb +26 -15
- data/lib/active_support/string_inquirer.rb +12 -3
- data/lib/active_support/subscriber.rb +77 -23
- data/lib/active_support/tagged_logging.rb +52 -17
- data/lib/active_support/test_case.rb +106 -29
- data/lib/active_support/testing/assertions.rb +144 -8
- data/lib/active_support/testing/autorun.rb +5 -10
- 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 +4 -2
- data/lib/active_support/testing/file_fixtures.rb +4 -0
- data/lib/active_support/testing/isolation.rb +19 -24
- data/lib/active_support/testing/method_call_assertions.rb +31 -2
- data/lib/active_support/testing/parallelization/server.rb +78 -0
- data/lib/active_support/testing/parallelization/worker.rb +100 -0
- data/lib/active_support/testing/parallelization.rb +51 -0
- data/lib/active_support/testing/setup_and_teardown.rb +13 -8
- data/lib/active_support/testing/stream.rb +30 -29
- data/lib/active_support/testing/tagged_logging.rb +3 -1
- data/lib/active_support/testing/time_helpers.rb +125 -24
- data/lib/active_support/time.rb +14 -12
- data/lib/active_support/time_with_zone.rb +142 -55
- data/lib/active_support/values/time_zone.rb +160 -53
- data/lib/active_support/version.rb +3 -1
- data/lib/active_support/xml_mini/jdom.rb +115 -114
- data/lib/active_support/xml_mini/libxml.rb +15 -14
- data/lib/active_support/xml_mini/libxmlsax.rb +16 -18
- data/lib/active_support/xml_mini/nokogiri.rb +13 -13
- data/lib/active_support/xml_mini/nokogirisax.rb +15 -16
- data/lib/active_support/xml_mini/rexml.rb +18 -9
- data/lib/active_support/xml_mini.rb +44 -42
- data/lib/active_support.rb +19 -10
- metadata +79 -37
- data/lib/active_support/concurrency/latch.rb +0 -19
- data/lib/active_support/core_ext/array/prepend_and_append.rb +0 -7
- data/lib/active_support/core_ext/hash/compact.rb +0 -20
- data/lib/active_support/core_ext/hash/transform_values.rb +0 -29
- data/lib/active_support/core_ext/kernel/agnostics.rb +0 -11
- data/lib/active_support/core_ext/kernel/debugger.rb +0 -3
- data/lib/active_support/core_ext/module/method_transplanting.rb +0 -3
- data/lib/active_support/core_ext/module/qualified_const.rb +0 -70
- data/lib/active_support/core_ext/module/reachable.rb +0 -8
- data/lib/active_support/core_ext/numeric/inquiry.rb +0 -26
- data/lib/active_support/core_ext/range/include_range.rb +0 -23
- data/lib/active_support/core_ext/struct.rb +0 -3
- data/lib/active_support/core_ext/time/marshal.rb +0 -3
- data/lib/active_support/values/unicode_tables.dat +0 -0
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
|
-
# Most objects are cloneable, but not all. For example you can't dup
|
4
|
+
# Most objects are cloneable, but not all. For example you can't dup methods:
|
3
5
|
#
|
4
|
-
#
|
6
|
+
# method(:puts).dup # => TypeError: allocator undefined for Method
|
5
7
|
#
|
6
8
|
# Classes may signal their instances are not duplicable removing +dup+/+clone+
|
7
9
|
# or raising exceptions from them. So, to dup an arbitrary object you normally
|
@@ -19,79 +21,28 @@
|
|
19
21
|
class Object
|
20
22
|
# Can you safely dup this object?
|
21
23
|
#
|
22
|
-
# False for
|
24
|
+
# False for method objects;
|
23
25
|
# true otherwise.
|
24
26
|
def duplicable?
|
25
27
|
true
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
|
-
class
|
30
|
-
#
|
31
|
-
#
|
32
|
-
# nil.duplicable? # => false
|
33
|
-
# nil.dup # => TypeError: can't dup NilClass
|
34
|
-
def duplicable?
|
35
|
-
false
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
class FalseClass
|
40
|
-
# +false+ is not duplicable:
|
41
|
-
#
|
42
|
-
# false.duplicable? # => false
|
43
|
-
# false.dup # => TypeError: can't dup FalseClass
|
44
|
-
def duplicable?
|
45
|
-
false
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
class TrueClass
|
50
|
-
# +true+ is not duplicable:
|
51
|
-
#
|
52
|
-
# true.duplicable? # => false
|
53
|
-
# true.dup # => TypeError: can't dup TrueClass
|
54
|
-
def duplicable?
|
55
|
-
false
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
class Symbol
|
60
|
-
# Symbols are not duplicable:
|
61
|
-
#
|
62
|
-
# :my_symbol.duplicable? # => false
|
63
|
-
# :my_symbol.dup # => TypeError: can't dup Symbol
|
64
|
-
def duplicable?
|
65
|
-
false
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
class Numeric
|
70
|
-
# Numbers are not duplicable:
|
31
|
+
class Method
|
32
|
+
# Methods are not duplicable:
|
71
33
|
#
|
72
|
-
#
|
73
|
-
#
|
34
|
+
# method(:puts).duplicable? # => false
|
35
|
+
# method(:puts).dup # => TypeError: allocator undefined for Method
|
74
36
|
def duplicable?
|
75
37
|
false
|
76
38
|
end
|
77
39
|
end
|
78
40
|
|
79
|
-
|
80
|
-
|
81
|
-
# BigDecimals are duplicable:
|
41
|
+
class UnboundMethod
|
42
|
+
# Unbound methods are not duplicable:
|
82
43
|
#
|
83
|
-
#
|
84
|
-
#
|
85
|
-
def duplicable?
|
86
|
-
true
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
class Method
|
91
|
-
# Methods are not duplicable:
|
92
|
-
#
|
93
|
-
# method(:puts).duplicable? # => false
|
94
|
-
# method(:puts).dup # => TypeError: allocator undefined for Method
|
44
|
+
# method(:puts).unbind.duplicable? # => false
|
45
|
+
# method(:puts).unbind.dup # => TypeError: allocator undefined for UnboundMethod
|
95
46
|
def duplicable?
|
96
47
|
false
|
97
48
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Object
|
2
4
|
# Returns true if this object is included in the argument. Argument must be
|
3
5
|
# any object which responds to +#include?+. Usage:
|
@@ -22,6 +24,6 @@ class Object
|
|
22
24
|
#
|
23
25
|
# @return [Object]
|
24
26
|
def presence_in(another_object)
|
25
|
-
|
27
|
+
in?(another_object) ? self : nil
|
26
28
|
end
|
27
29
|
end
|
@@ -1,15 +1,20 @@
|
|
1
|
-
#
|
2
|
-
require 'json'
|
3
|
-
require 'bigdecimal'
|
4
|
-
require 'active_support/core_ext/big_decimal/conversions' # for #to_s
|
5
|
-
require 'active_support/core_ext/hash/except'
|
6
|
-
require 'active_support/core_ext/hash/slice'
|
7
|
-
require 'active_support/core_ext/object/instance_variables'
|
8
|
-
require 'time'
|
9
|
-
require 'active_support/core_ext/time/conversions'
|
10
|
-
require 'active_support/core_ext/date_time/conversions'
|
11
|
-
require 'active_support/core_ext/date/conversions'
|
1
|
+
# frozen_string_literal: true
|
12
2
|
|
3
|
+
# Hack to load json gem first so we can overwrite its to_json.
|
4
|
+
require "json"
|
5
|
+
require "bigdecimal"
|
6
|
+
require "uri/generic"
|
7
|
+
require "pathname"
|
8
|
+
require "active_support/core_ext/big_decimal/conversions" # for #to_s
|
9
|
+
require "active_support/core_ext/hash/except"
|
10
|
+
require "active_support/core_ext/hash/slice"
|
11
|
+
require "active_support/core_ext/object/instance_variables"
|
12
|
+
require "time"
|
13
|
+
require "active_support/core_ext/time/conversions"
|
14
|
+
require "active_support/core_ext/date_time/conversions"
|
15
|
+
require "active_support/core_ext/date/conversions"
|
16
|
+
|
17
|
+
#--
|
13
18
|
# The JSON gem adds a few modules to Ruby core classes containing :to_json definition, overwriting
|
14
19
|
# their default behavior. That said, we need to define the basic to_json method in all of them,
|
15
20
|
# otherwise they will always use to_json gem implementation, which is backwards incompatible in
|
@@ -40,7 +45,7 @@ module ActiveSupport
|
|
40
45
|
end
|
41
46
|
end
|
42
47
|
|
43
|
-
[Object, Array, FalseClass, Float, Hash, Integer, NilClass, String, TrueClass
|
48
|
+
[Enumerable, Object, Array, FalseClass, Float, Hash, Integer, NilClass, String, TrueClass].reverse_each do |klass|
|
44
49
|
klass.prepend(ActiveSupport::ToJsonWithActiveSupportEncoder)
|
45
50
|
end
|
46
51
|
|
@@ -131,6 +136,12 @@ module Enumerable
|
|
131
136
|
end
|
132
137
|
end
|
133
138
|
|
139
|
+
class IO
|
140
|
+
def as_json(options = nil) #:nodoc:
|
141
|
+
to_s
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
134
145
|
class Range
|
135
146
|
def as_json(options = nil) #:nodoc:
|
136
147
|
to_s
|
@@ -158,7 +169,11 @@ class Hash
|
|
158
169
|
self
|
159
170
|
end
|
160
171
|
|
161
|
-
|
172
|
+
result = {}
|
173
|
+
subset.each do |k, v|
|
174
|
+
result[k.to_s] = options ? v.as_json(options.dup) : v.as_json
|
175
|
+
end
|
176
|
+
result
|
162
177
|
end
|
163
178
|
end
|
164
179
|
|
@@ -187,14 +202,26 @@ class DateTime
|
|
187
202
|
if ActiveSupport::JSON::Encoding.use_standard_json_time_format
|
188
203
|
xmlschema(ActiveSupport::JSON::Encoding.time_precision)
|
189
204
|
else
|
190
|
-
strftime(
|
205
|
+
strftime("%Y/%m/%d %H:%M:%S %z")
|
191
206
|
end
|
192
207
|
end
|
193
208
|
end
|
194
209
|
|
210
|
+
class URI::Generic #:nodoc:
|
211
|
+
def as_json(options = nil)
|
212
|
+
to_s
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
class Pathname #:nodoc:
|
217
|
+
def as_json(options = nil)
|
218
|
+
to_s
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
195
222
|
class Process::Status #:nodoc:
|
196
223
|
def as_json(options = nil)
|
197
|
-
{ :
|
224
|
+
{ exitstatus: exitstatus, pid: pid }
|
198
225
|
end
|
199
226
|
end
|
200
227
|
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "cgi"
|
2
4
|
|
3
5
|
class Object
|
4
6
|
# Alias of <tt>to_s</tt>.
|
@@ -38,7 +40,7 @@ class Array
|
|
38
40
|
# Calls <tt>to_param</tt> on all its elements and joins the result with
|
39
41
|
# slashes. This is used by <tt>url_for</tt> in Action Pack.
|
40
42
|
def to_param
|
41
|
-
collect(&:to_param).join
|
43
|
+
collect(&:to_param).join "/"
|
42
44
|
end
|
43
45
|
|
44
46
|
# Converts an array into a string suitable for use as a URL query string,
|
@@ -51,7 +53,7 @@ class Array
|
|
51
53
|
if empty?
|
52
54
|
nil.to_query(prefix)
|
53
55
|
else
|
54
|
-
collect { |value| value.to_query(prefix) }.join
|
56
|
+
collect { |value| value.to_query(prefix) }.join "&"
|
55
57
|
end
|
56
58
|
end
|
57
59
|
end
|
@@ -73,11 +75,14 @@ class Hash
|
|
73
75
|
#
|
74
76
|
# This method is also aliased as +to_param+.
|
75
77
|
def to_query(namespace = nil)
|
76
|
-
collect do |key, value|
|
78
|
+
query = collect do |key, value|
|
77
79
|
unless (value.is_a?(Hash) || value.is_a?(Array)) && value.empty?
|
78
80
|
value.to_query(namespace ? "#{namespace}[#{key}]" : key)
|
79
81
|
end
|
80
|
-
end.compact
|
82
|
+
end.compact
|
83
|
+
|
84
|
+
query.sort! unless namespace.to_s.include?("[]")
|
85
|
+
query.join("&")
|
81
86
|
end
|
82
87
|
|
83
88
|
alias_method :to_param, :to_query
|
@@ -1,22 +1,34 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "delegate"
|
2
4
|
|
3
5
|
module ActiveSupport
|
4
6
|
module Tryable #:nodoc:
|
5
|
-
def try(*
|
6
|
-
|
7
|
+
def try(method_name = nil, *args, &b)
|
8
|
+
if method_name.nil? && block_given?
|
9
|
+
if b.arity == 0
|
10
|
+
instance_eval(&b)
|
11
|
+
else
|
12
|
+
yield self
|
13
|
+
end
|
14
|
+
elsif respond_to?(method_name)
|
15
|
+
public_send(method_name, *args, &b)
|
16
|
+
end
|
7
17
|
end
|
18
|
+
ruby2_keywords(:try) if respond_to?(:ruby2_keywords, true)
|
8
19
|
|
9
|
-
def try!(*
|
10
|
-
if
|
20
|
+
def try!(method_name = nil, *args, &b)
|
21
|
+
if method_name.nil? && block_given?
|
11
22
|
if b.arity == 0
|
12
23
|
instance_eval(&b)
|
13
24
|
else
|
14
25
|
yield self
|
15
26
|
end
|
16
27
|
else
|
17
|
-
public_send(*
|
28
|
+
public_send(method_name, *args, &b)
|
18
29
|
end
|
19
30
|
end
|
31
|
+
ruby2_keywords(:try!) if respond_to?(:ruby2_keywords, true)
|
20
32
|
end
|
21
33
|
end
|
22
34
|
|
@@ -133,14 +145,14 @@ class NilClass
|
|
133
145
|
#
|
134
146
|
# With +try+
|
135
147
|
# @person.try(:children).try(:first).try(:name)
|
136
|
-
def try(*
|
148
|
+
def try(_method_name = nil, *)
|
137
149
|
nil
|
138
150
|
end
|
139
151
|
|
140
152
|
# Calling +try!+ on +nil+ always returns +nil+.
|
141
153
|
#
|
142
154
|
# nil.try!(:name) # => nil
|
143
|
-
def try!(*
|
155
|
+
def try!(_method_name = nil, *)
|
144
156
|
nil
|
145
157
|
end
|
146
158
|
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/option_merger"
|
2
4
|
|
3
5
|
class Object
|
4
6
|
# An elegant way to factor duplication out of options passed to a series of
|
@@ -60,7 +62,18 @@ class Object
|
|
60
62
|
#
|
61
63
|
# validates :content, length: { minimum: 50 }, if: -> { content.present? }
|
62
64
|
#
|
63
|
-
# Hence the inherited default for
|
65
|
+
# Hence the inherited default for +if+ key is ignored.
|
66
|
+
#
|
67
|
+
# NOTE: You cannot call class methods implicitly inside of with_options.
|
68
|
+
# You can access these methods using the class name instead:
|
69
|
+
#
|
70
|
+
# class Phone < ActiveRecord::Base
|
71
|
+
# enum phone_number_type: { home: 0, office: 1, mobile: 2 }
|
72
|
+
#
|
73
|
+
# with_options presence: true do
|
74
|
+
# validates :phone_number_type, inclusion: { in: Phone.phone_number_types.keys }
|
75
|
+
# end
|
76
|
+
# end
|
64
77
|
#
|
65
78
|
def with_options(options, &block)
|
66
79
|
option_merger = ActiveSupport::OptionMerger.new(self, options)
|
@@ -1,14 +1,16 @@
|
|
1
|
-
|
2
|
-
require 'active_support/core_ext/object/blank'
|
3
|
-
require 'active_support/core_ext/object/duplicable'
|
4
|
-
require 'active_support/core_ext/object/deep_dup'
|
5
|
-
require 'active_support/core_ext/object/try'
|
6
|
-
require 'active_support/core_ext/object/inclusion'
|
1
|
+
# frozen_string_literal: true
|
7
2
|
|
8
|
-
require
|
9
|
-
require
|
3
|
+
require "active_support/core_ext/object/acts_like"
|
4
|
+
require "active_support/core_ext/object/blank"
|
5
|
+
require "active_support/core_ext/object/duplicable"
|
6
|
+
require "active_support/core_ext/object/deep_dup"
|
7
|
+
require "active_support/core_ext/object/try"
|
8
|
+
require "active_support/core_ext/object/inclusion"
|
10
9
|
|
11
|
-
require
|
12
|
-
require
|
13
|
-
|
14
|
-
require
|
10
|
+
require "active_support/core_ext/object/conversions"
|
11
|
+
require "active_support/core_ext/object/instance_variables"
|
12
|
+
|
13
|
+
require "active_support/core_ext/object/json"
|
14
|
+
require "active_support/core_ext/object/to_param"
|
15
|
+
require "active_support/core_ext/object/to_query"
|
16
|
+
require "active_support/core_ext/object/with_options"
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
module CompareWithRange
|
5
|
+
# Extends the default Range#=== to support range comparisons.
|
6
|
+
# (1..5) === (1..5) # => true
|
7
|
+
# (1..5) === (2..3) # => true
|
8
|
+
# (1..5) === (1...6) # => true
|
9
|
+
# (1..5) === (2..6) # => false
|
10
|
+
#
|
11
|
+
# The native Range#=== behavior is untouched.
|
12
|
+
# ('a'..'f') === ('c') # => true
|
13
|
+
# (5..9) === (11) # => false
|
14
|
+
#
|
15
|
+
# The given range must be fully bounded, with both start and end.
|
16
|
+
def ===(value)
|
17
|
+
if value.is_a?(::Range)
|
18
|
+
is_backwards_op = value.exclude_end? ? :>= : :>
|
19
|
+
return false if value.begin && value.end && value.begin.public_send(is_backwards_op, value.end)
|
20
|
+
# 1...10 includes 1..9 but it does not include 1..10.
|
21
|
+
# 1..10 includes 1...11 but it does not include 1...12.
|
22
|
+
operator = exclude_end? && !value.exclude_end? ? :< : :<=
|
23
|
+
value_max = !exclude_end? && value.exclude_end? ? value.max : value.last
|
24
|
+
super(value.first) && (self.end.nil? || value_max.public_send(operator, last))
|
25
|
+
else
|
26
|
+
super
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Extends the default Range#include? to support range comparisons.
|
31
|
+
# (1..5).include?(1..5) # => true
|
32
|
+
# (1..5).include?(2..3) # => true
|
33
|
+
# (1..5).include?(1...6) # => true
|
34
|
+
# (1..5).include?(2..6) # => false
|
35
|
+
#
|
36
|
+
# The native Range#include? behavior is untouched.
|
37
|
+
# ('a'..'f').include?('c') # => true
|
38
|
+
# (5..9).include?(11) # => false
|
39
|
+
#
|
40
|
+
# The given range must be fully bounded, with both start and end.
|
41
|
+
def include?(value)
|
42
|
+
if value.is_a?(::Range)
|
43
|
+
is_backwards_op = value.exclude_end? ? :>= : :>
|
44
|
+
return false if value.begin && value.end && value.begin.public_send(is_backwards_op, value.end)
|
45
|
+
# 1...10 includes 1..9 but it does not include 1..10.
|
46
|
+
# 1..10 includes 1...11 but it does not include 1...12.
|
47
|
+
operator = exclude_end? && !value.exclude_end? ? :< : :<=
|
48
|
+
value_max = !exclude_end? && value.exclude_end? ? value.max : value.last
|
49
|
+
super(value.first) && (self.end.nil? || value_max.public_send(operator, last))
|
50
|
+
else
|
51
|
+
super
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Extends the default Range#cover? to support range comparisons.
|
56
|
+
# (1..5).cover?(1..5) # => true
|
57
|
+
# (1..5).cover?(2..3) # => true
|
58
|
+
# (1..5).cover?(1...6) # => true
|
59
|
+
# (1..5).cover?(2..6) # => false
|
60
|
+
#
|
61
|
+
# The native Range#cover? behavior is untouched.
|
62
|
+
# ('a'..'f').cover?('c') # => true
|
63
|
+
# (5..9).cover?(11) # => false
|
64
|
+
#
|
65
|
+
# The given range must be fully bounded, with both start and end.
|
66
|
+
def cover?(value)
|
67
|
+
if value.is_a?(::Range)
|
68
|
+
is_backwards_op = value.exclude_end? ? :>= : :>
|
69
|
+
return false if value.begin && value.end && value.begin.public_send(is_backwards_op, value.end)
|
70
|
+
# 1...10 covers 1..9 but it does not cover 1..10.
|
71
|
+
# 1..10 covers 1...11 but it does not cover 1...12.
|
72
|
+
operator = exclude_end? && !value.exclude_end? ? :< : :<=
|
73
|
+
value_max = !exclude_end? && value.exclude_end? ? value.max : value.last
|
74
|
+
super(value.first) && (self.end.nil? || value_max.public_send(operator, last))
|
75
|
+
else
|
76
|
+
super
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
Range.prepend(ActiveSupport::CompareWithRange)
|
@@ -1,31 +1,41 @@
|
|
1
|
-
|
2
|
-
RANGE_FORMATS = {
|
3
|
-
:db => Proc.new { |start, stop| "BETWEEN '#{start.to_s(:db)}' AND '#{stop.to_s(:db)}'" }
|
4
|
-
}
|
1
|
+
# frozen_string_literal: true
|
5
2
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
3
|
+
module ActiveSupport
|
4
|
+
module RangeWithFormat
|
5
|
+
RANGE_FORMATS = {
|
6
|
+
db: -> (start, stop) do
|
7
|
+
case start
|
8
|
+
when String then "BETWEEN '#{start}' AND '#{stop}'"
|
9
|
+
else
|
10
|
+
"BETWEEN '#{start.to_s(:db)}' AND '#{stop.to_s(:db)}'"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
}
|
14
|
+
|
15
|
+
# Convert range to a formatted string. See RANGE_FORMATS for predefined formats.
|
16
|
+
#
|
17
|
+
# range = (1..100) # => 1..100
|
18
|
+
#
|
19
|
+
# range.to_s # => "1..100"
|
20
|
+
# range.to_s(:db) # => "BETWEEN '1' AND '100'"
|
21
|
+
#
|
22
|
+
# == Adding your own range formats to to_s
|
23
|
+
# You can add your own formats to the Range::RANGE_FORMATS hash.
|
24
|
+
# Use the format name as the hash key and a Proc instance.
|
25
|
+
#
|
26
|
+
# # config/initializers/range_formats.rb
|
27
|
+
# Range::RANGE_FORMATS[:short] = ->(start, stop) { "Between #{start.to_s(:db)} and #{stop.to_s(:db)}" }
|
28
|
+
def to_s(format = :default)
|
29
|
+
if formatter = RANGE_FORMATS[format]
|
30
|
+
formatter.call(first, last)
|
31
|
+
else
|
32
|
+
super()
|
33
|
+
end
|
24
34
|
end
|
25
|
-
end
|
26
35
|
|
27
|
-
|
28
|
-
|
36
|
+
alias_method :to_default_s, :to_s
|
37
|
+
alias_method :to_formatted_s, :to_s
|
38
|
+
end
|
29
39
|
end
|
30
40
|
|
31
41
|
Range.prepend(ActiveSupport::RangeWithFormat)
|
@@ -1,3 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/time_with_zone"
|
4
|
+
|
1
5
|
module ActiveSupport
|
2
6
|
module EachTimeWithZone #:nodoc:
|
3
7
|
def each(&block)
|
@@ -11,9 +15,8 @@ module ActiveSupport
|
|
11
15
|
end
|
12
16
|
|
13
17
|
private
|
14
|
-
|
15
18
|
def ensure_iteration_allowed
|
16
|
-
raise TypeError, "can't iterate from #{first.class}" if first.is_a?(
|
19
|
+
raise TypeError, "can't iterate from #{first.class}" if first.is_a?(TimeWithZone)
|
17
20
|
end
|
18
21
|
end
|
19
22
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/time_with_zone"
|
4
|
+
require "active_support/deprecation"
|
5
|
+
|
6
|
+
module ActiveSupport
|
7
|
+
module IncludeTimeWithZone #:nodoc:
|
8
|
+
# Extends the default Range#include? to support ActiveSupport::TimeWithZone.
|
9
|
+
#
|
10
|
+
# (1.hour.ago..1.hour.from_now).include?(Time.current) # => true
|
11
|
+
#
|
12
|
+
def include?(value)
|
13
|
+
if self.begin.is_a?(TimeWithZone) || self.end.is_a?(TimeWithZone)
|
14
|
+
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
15
|
+
Using `Range#include?` to check the inclusion of a value in
|
16
|
+
a date time range is deprecated.
|
17
|
+
It is recommended to use `Range#cover?` instead of `Range#include?` to
|
18
|
+
check the inclusion of a value in a date time range.
|
19
|
+
MSG
|
20
|
+
cover?(value)
|
21
|
+
else
|
22
|
+
super
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Range.prepend(ActiveSupport::IncludeTimeWithZone)
|
@@ -1,4 +1,7 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/range/conversions"
|
4
|
+
require "active_support/core_ext/range/compare_range"
|
5
|
+
require "active_support/core_ext/range/include_time_with_zone"
|
6
|
+
require "active_support/core_ext/range/overlaps"
|
7
|
+
require "active_support/core_ext/range/each"
|
@@ -1,4 +1,13 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Regexp
|
4
|
+
# Returns +true+ if the regexp has the multiline flag set.
|
5
|
+
#
|
6
|
+
# (/./).multiline? # => false
|
7
|
+
# (/./m).multiline? # => true
|
8
|
+
#
|
9
|
+
# Regexp.new(".").multiline? # => false
|
10
|
+
# Regexp.new(".", Regexp::MULTILINE).multiline? # => true
|
2
11
|
def multiline?
|
3
12
|
options & MULTILINE == MULTILINE
|
4
13
|
end
|
@@ -1,18 +1,21 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "securerandom"
|
2
4
|
|
3
5
|
module SecureRandom
|
4
|
-
BASE58_ALPHABET = (
|
6
|
+
BASE58_ALPHABET = ("0".."9").to_a + ("A".."Z").to_a + ("a".."z").to_a - ["0", "O", "I", "l"]
|
7
|
+
BASE36_ALPHABET = ("0".."9").to_a + ("a".."z").to_a
|
8
|
+
|
5
9
|
# SecureRandom.base58 generates a random base58 string.
|
6
10
|
#
|
7
|
-
# The argument _n_ specifies the length
|
11
|
+
# The argument _n_ specifies the length of the random string to be generated.
|
8
12
|
#
|
9
|
-
# If _n_ is not specified or is nil
|
13
|
+
# If _n_ is not specified or is +nil+, 16 is assumed. It may be larger in the future.
|
10
14
|
#
|
11
|
-
# The result may contain alphanumeric characters except 0, O, I and l
|
15
|
+
# The result may contain alphanumeric characters except 0, O, I and l.
|
12
16
|
#
|
13
17
|
# p SecureRandom.base58 # => "4kUgL2pdQMSCQtjE"
|
14
18
|
# p SecureRandom.base58(24) # => "77TMHrHJFvFDwodq8w7Ev2m7"
|
15
|
-
#
|
16
19
|
def self.base58(n = 16)
|
17
20
|
SecureRandom.random_bytes(n).unpack("C*").map do |byte|
|
18
21
|
idx = byte % 64
|
@@ -20,4 +23,23 @@ module SecureRandom
|
|
20
23
|
BASE58_ALPHABET[idx]
|
21
24
|
end.join
|
22
25
|
end
|
26
|
+
|
27
|
+
# SecureRandom.base36 generates a random base36 string in lowercase.
|
28
|
+
#
|
29
|
+
# The argument _n_ specifies the length of the random string to be generated.
|
30
|
+
#
|
31
|
+
# If _n_ is not specified or is +nil+, 16 is assumed. It may be larger in the future.
|
32
|
+
# This method can be used over +base58+ if a deterministic case key is necessary.
|
33
|
+
#
|
34
|
+
# The result will contain alphanumeric characters in lowercase.
|
35
|
+
#
|
36
|
+
# p SecureRandom.base36 # => "4kugl2pdqmscqtje"
|
37
|
+
# p SecureRandom.base36(24) # => "77tmhrhjfvfdwodq8w7ev2m7"
|
38
|
+
def self.base36(n = 16)
|
39
|
+
SecureRandom.random_bytes(n).unpack("C*").map do |byte|
|
40
|
+
idx = byte % 64
|
41
|
+
idx = SecureRandom.random_number(36) if idx >= 36
|
42
|
+
BASE36_ALPHABET[idx]
|
43
|
+
end.join
|
44
|
+
end
|
23
45
|
end
|