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,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/object/json"
|
4
|
+
require "active_support/core_ext/module/delegation"
|
3
5
|
|
4
6
|
module ActiveSupport
|
5
7
|
class << self
|
@@ -7,7 +9,7 @@ module ActiveSupport
|
|
7
9
|
:time_precision, :time_precision=,
|
8
10
|
:escape_html_entities_in_json, :escape_html_entities_in_json=,
|
9
11
|
:json_encoder, :json_encoder=,
|
10
|
-
:
|
12
|
+
to: :'ActiveSupport::JSON::Encoding'
|
11
13
|
end
|
12
14
|
|
13
15
|
module JSON
|
@@ -40,9 +42,9 @@ module ActiveSupport
|
|
40
42
|
ESCAPED_CHARS = {
|
41
43
|
"\u2028" => '\u2028',
|
42
44
|
"\u2029" => '\u2029',
|
43
|
-
|
44
|
-
|
45
|
-
|
45
|
+
">" => '\u003e',
|
46
|
+
"<" => '\u003c',
|
47
|
+
"&" => '\u0026',
|
46
48
|
}
|
47
49
|
|
48
50
|
ESCAPE_REGEX_WITH_HTML_ENTITIES = /[\u2028\u2029><&]/u
|
@@ -52,9 +54,13 @@ module ActiveSupport
|
|
52
54
|
class EscapedString < String #:nodoc:
|
53
55
|
def to_json(*)
|
54
56
|
if Encoding.escape_html_entities_in_json
|
55
|
-
|
57
|
+
s = super
|
58
|
+
s.gsub! ESCAPE_REGEX_WITH_HTML_ENTITIES, ESCAPED_CHARS
|
59
|
+
s
|
56
60
|
else
|
57
|
-
|
61
|
+
s = super
|
62
|
+
s.gsub! ESCAPE_REGEX_WITHOUT_HTML_ENTITIES, ESCAPED_CHARS
|
63
|
+
s
|
58
64
|
end
|
59
65
|
end
|
60
66
|
|
@@ -68,7 +74,8 @@ module ActiveSupport
|
|
68
74
|
:ESCAPE_REGEX_WITHOUT_HTML_ENTITIES, :EscapedString
|
69
75
|
|
70
76
|
# Convert an object into a "JSON-ready" representation composed of
|
71
|
-
# primitives like Hash, Array, String, Numeric,
|
77
|
+
# primitives like Hash, Array, String, Numeric,
|
78
|
+
# and +true+/+false+/+nil+.
|
72
79
|
# Recursively calls #as_json to the object to recursively build a
|
73
80
|
# fully JSON-ready object.
|
74
81
|
#
|
@@ -84,9 +91,13 @@ module ActiveSupport
|
|
84
91
|
when String
|
85
92
|
EscapedString.new(value)
|
86
93
|
when Numeric, NilClass, TrueClass, FalseClass
|
87
|
-
value
|
94
|
+
value.as_json
|
88
95
|
when Hash
|
89
|
-
|
96
|
+
result = {}
|
97
|
+
value.each do |k, v|
|
98
|
+
result[jsonify(k)] = jsonify(v)
|
99
|
+
end
|
100
|
+
result
|
90
101
|
when Array
|
91
102
|
value.map { |v| jsonify(v) }
|
92
103
|
else
|
data/lib/active_support/json.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "concurrent/map"
|
4
|
+
require "openssl"
|
3
5
|
|
4
6
|
module ActiveSupport
|
5
7
|
# KeyGenerator is a simple wrapper around OpenSSL's implementation of PBKDF2.
|
@@ -17,7 +19,7 @@ module ActiveSupport
|
|
17
19
|
# Returns a derived key suitable for use. The default key_size is chosen
|
18
20
|
# to be compatible with the default settings of ActiveSupport::MessageVerifier.
|
19
21
|
# i.e. OpenSSL::Digest::SHA1#block_length
|
20
|
-
def generate_key(salt, key_size=64)
|
22
|
+
def generate_key(salt, key_size = 64)
|
21
23
|
OpenSSL::PKCS5.pbkdf2_hmac_sha1(@secret, salt, @iterations, key_size)
|
22
24
|
end
|
23
25
|
end
|
@@ -33,39 +35,7 @@ module ActiveSupport
|
|
33
35
|
|
34
36
|
# Returns a derived key suitable for use.
|
35
37
|
def generate_key(*args)
|
36
|
-
@cache_keys[args.join] ||= @key_generator.generate_key(*args)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
class LegacyKeyGenerator # :nodoc:
|
41
|
-
SECRET_MIN_LENGTH = 30 # Characters
|
42
|
-
|
43
|
-
def initialize(secret)
|
44
|
-
ensure_secret_secure(secret)
|
45
|
-
@secret = secret
|
46
|
-
end
|
47
|
-
|
48
|
-
def generate_key(salt)
|
49
|
-
@secret
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
# To prevent users from using something insecure like "Password" we make sure that the
|
55
|
-
# secret they've provided is at least 30 characters in length.
|
56
|
-
def ensure_secret_secure(secret)
|
57
|
-
if secret.blank?
|
58
|
-
raise ArgumentError, "A secret is required to generate an integrity hash " \
|
59
|
-
"for cookie session data. Set a secret_key_base of at least " \
|
60
|
-
"#{SECRET_MIN_LENGTH} characters in config/secrets.yml."
|
61
|
-
end
|
62
|
-
|
63
|
-
if secret.length < SECRET_MIN_LENGTH
|
64
|
-
raise ArgumentError, "Secret should be something secure, " \
|
65
|
-
"like \"#{SecureRandom.hex(16)}\". The value you " \
|
66
|
-
"provided, \"#{secret}\", is shorter than the minimum length " \
|
67
|
-
"of #{SECRET_MIN_LENGTH} characters."
|
68
|
-
end
|
38
|
+
@cache_keys[args.join("|")] ||= @key_generator.generate_key(*args)
|
69
39
|
end
|
70
40
|
end
|
71
41
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module ActiveSupport
|
2
4
|
# lazy_load_hooks allows Rails to lazily load a lot of components and thus
|
3
5
|
# making the app boot faster. Because of this feature now there is no need to
|
@@ -15,34 +17,65 @@ module ActiveSupport
|
|
15
17
|
# end
|
16
18
|
# end
|
17
19
|
#
|
18
|
-
# When the entirety of +
|
20
|
+
# When the entirety of +ActiveRecord::Base+ has been
|
19
21
|
# evaluated then +run_load_hooks+ is invoked. The very last line of
|
20
|
-
# +
|
22
|
+
# +ActiveRecord::Base+ is:
|
21
23
|
#
|
22
24
|
# ActiveSupport.run_load_hooks(:active_record, ActiveRecord::Base)
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
module LazyLoadHooks
|
26
|
+
def self.extended(base) # :nodoc:
|
27
|
+
base.class_eval do
|
28
|
+
@load_hooks = Hash.new { |h, k| h[k] = [] }
|
29
|
+
@loaded = Hash.new { |h, k| h[k] = [] }
|
30
|
+
@run_once = Hash.new { |h, k| h[k] = [] }
|
31
|
+
end
|
29
32
|
end
|
30
33
|
|
31
|
-
|
32
|
-
|
34
|
+
# Declares a block that will be executed when a Rails component is fully
|
35
|
+
# loaded.
|
36
|
+
#
|
37
|
+
# Options:
|
38
|
+
#
|
39
|
+
# * <tt>:yield</tt> - Yields the object that run_load_hooks to +block+.
|
40
|
+
# * <tt>:run_once</tt> - Given +block+ will run only once.
|
41
|
+
def on_load(name, options = {}, &block)
|
42
|
+
@loaded[name].each do |base|
|
43
|
+
execute_hook(name, base, options, block)
|
44
|
+
end
|
33
45
|
|
34
|
-
|
35
|
-
if options[:yield]
|
36
|
-
block.call(base)
|
37
|
-
else
|
38
|
-
base.instance_eval(&block)
|
46
|
+
@load_hooks[name] << [block, options]
|
39
47
|
end
|
40
|
-
end
|
41
48
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
49
|
+
def run_load_hooks(name, base = Object)
|
50
|
+
@loaded[name] << base
|
51
|
+
@load_hooks[name].each do |hook, options|
|
52
|
+
execute_hook(name, base, options, hook)
|
53
|
+
end
|
46
54
|
end
|
55
|
+
|
56
|
+
private
|
57
|
+
def with_execution_control(name, block, once)
|
58
|
+
unless @run_once[name].include?(block)
|
59
|
+
@run_once[name] << block if once
|
60
|
+
|
61
|
+
yield
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def execute_hook(name, base, options, block)
|
66
|
+
with_execution_control(name, block, options[:run_once]) do
|
67
|
+
if options[:yield]
|
68
|
+
block.call(base)
|
69
|
+
else
|
70
|
+
if base.is_a?(Module)
|
71
|
+
base.class_eval(&block)
|
72
|
+
else
|
73
|
+
base.instance_eval(&block)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
47
78
|
end
|
79
|
+
|
80
|
+
extend LazyLoadHooks
|
48
81
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
{
|
4
|
+
en: {
|
5
|
+
number: {
|
6
|
+
nth: {
|
7
|
+
ordinals: lambda do |_key, options|
|
8
|
+
number = options[:number]
|
9
|
+
case number
|
10
|
+
when 1; "st"
|
11
|
+
when 2; "nd"
|
12
|
+
when 3; "rd"
|
13
|
+
when 4, 5, 6, 7, 8, 9, 10, 11, 12, 13; "th"
|
14
|
+
else
|
15
|
+
num_modulo = number.to_i.abs % 100
|
16
|
+
num_modulo %= 10 if num_modulo > 13
|
17
|
+
case num_modulo
|
18
|
+
when 1; "st"
|
19
|
+
when 2; "nd"
|
20
|
+
when 3; "rd"
|
21
|
+
else "th"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end,
|
25
|
+
|
26
|
+
ordinalized: lambda do |_key, options|
|
27
|
+
number = options[:number]
|
28
|
+
"#{number}#{ActiveSupport::Inflector.ordinal(number)}"
|
29
|
+
end
|
30
|
+
}
|
31
|
+
}
|
32
|
+
}
|
33
|
+
}
|
@@ -44,10 +44,12 @@ en:
|
|
44
44
|
delimiter: ","
|
45
45
|
# Number of decimals, behind the separator (the number 1 with a precision of 2 gives: 1.00)
|
46
46
|
precision: 3
|
47
|
+
# Determine how rounding is performed (see BigDecimal::mode)
|
48
|
+
round_mode: !ruby/sym default
|
47
49
|
# If set to true, precision will mean the number of significant digits instead
|
48
50
|
# of the number of decimal digits (1234 with precision 2 becomes 1200, 1.23543 becomes 1.2)
|
49
51
|
significant: false
|
50
|
-
# If set, the zeros after the decimal separator will always be stripped (
|
52
|
+
# If set, the zeros after the decimal separator will always be stripped (e.g.: 1.200 will be 1.2)
|
51
53
|
strip_insignificant_zeros: false
|
52
54
|
|
53
55
|
# Used in NumberHelper.number_to_currency()
|
@@ -56,10 +58,11 @@ en:
|
|
56
58
|
# Where is the currency sign? %u is the currency unit, %n the number (default: $5.00)
|
57
59
|
format: "%u%n"
|
58
60
|
unit: "$"
|
59
|
-
# These
|
61
|
+
# These six are to override number.format and are optional
|
60
62
|
separator: "."
|
61
63
|
delimiter: ","
|
62
64
|
precision: 2
|
65
|
+
# round_mode:
|
63
66
|
significant: false
|
64
67
|
strip_insignificant_zeros: false
|
65
68
|
|
@@ -87,10 +90,11 @@ en:
|
|
87
90
|
# Used in NumberHelper.number_to_human_size() and NumberHelper.number_to_human()
|
88
91
|
human:
|
89
92
|
format:
|
90
|
-
# These
|
93
|
+
# These six are to override number.format and are optional
|
91
94
|
# separator:
|
92
95
|
delimiter: ""
|
93
96
|
precision: 3
|
97
|
+
# round_mode:
|
94
98
|
significant: true
|
95
99
|
strip_insignificant_zeros: true
|
96
100
|
# Used in number_to_human_size()
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/log_subscriber"
|
4
|
+
require "active_support/logger"
|
5
|
+
require "active_support/notifications"
|
4
6
|
|
5
7
|
module ActiveSupport
|
6
8
|
class LogSubscriber
|
@@ -58,15 +60,15 @@ module ActiveSupport
|
|
58
60
|
def initialize(level = DEBUG)
|
59
61
|
@flush_count = 0
|
60
62
|
@level = level
|
61
|
-
@logged = Hash.new { |h,k| h[k] = [] }
|
63
|
+
@logged = Hash.new { |h, k| h[k] = [] }
|
62
64
|
end
|
63
65
|
|
64
66
|
def method_missing(level, message = nil)
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
67
|
+
if block_given?
|
68
|
+
@logged[level] << yield
|
69
|
+
else
|
70
|
+
@logged[level] << message
|
71
|
+
end
|
70
72
|
end
|
71
73
|
|
72
74
|
def logged(level)
|
@@ -1,10 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/module/attribute_accessors"
|
4
|
+
require "active_support/core_ext/class/attribute"
|
5
|
+
require "active_support/subscriber"
|
4
6
|
|
5
7
|
module ActiveSupport
|
6
|
-
# ActiveSupport::LogSubscriber is an object set to consume
|
7
|
-
# ActiveSupport::Notifications with the sole purpose of logging them.
|
8
|
+
# <tt>ActiveSupport::LogSubscriber</tt> is an object set to consume
|
9
|
+
# <tt>ActiveSupport::Notifications</tt> with the sole purpose of logging them.
|
8
10
|
# The log subscriber dispatches notifications to a registered object based
|
9
11
|
# on its given namespace.
|
10
12
|
#
|
@@ -14,7 +16,7 @@ module ActiveSupport
|
|
14
16
|
# module ActiveRecord
|
15
17
|
# class LogSubscriber < ActiveSupport::LogSubscriber
|
16
18
|
# def sql(event)
|
17
|
-
# "#{event.payload[:name]} (#{event.duration}) #{event.payload[:sql]}"
|
19
|
+
# info "#{event.payload[:name]} (#{event.duration}) #{event.payload[:sql]}"
|
18
20
|
# end
|
19
21
|
# end
|
20
22
|
# end
|
@@ -27,13 +29,39 @@ module ActiveSupport
|
|
27
29
|
# subscriber, the line above should be called after your
|
28
30
|
# <tt>ActiveRecord::LogSubscriber</tt> definition.
|
29
31
|
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
32
|
+
# A logger also needs to be set with <tt>ActiveRecord::LogSubscriber.logger=</tt>.
|
33
|
+
# This is assigned automatically in a Rails environment.
|
34
|
+
#
|
35
|
+
# After configured, whenever a <tt>"sql.active_record"</tt> notification is published,
|
36
|
+
# it will properly dispatch the event
|
37
|
+
# (<tt>ActiveSupport::Notifications::Event</tt>) to the sql method.
|
38
|
+
#
|
39
|
+
# Being an <tt>ActiveSupport::Notifications</tt> consumer,
|
40
|
+
# <tt>ActiveSupport::LogSubscriber</tt> exposes a simple interface to check if
|
41
|
+
# instrumented code raises an exception. It is common to log a different
|
42
|
+
# message in case of an error, and this can be achieved by extending
|
43
|
+
# the previous example:
|
44
|
+
#
|
45
|
+
# module ActiveRecord
|
46
|
+
# class LogSubscriber < ActiveSupport::LogSubscriber
|
47
|
+
# def sql(event)
|
48
|
+
# exception = event.payload[:exception]
|
49
|
+
#
|
50
|
+
# if exception
|
51
|
+
# exception_object = event.payload[:exception_object]
|
52
|
+
#
|
53
|
+
# error "[ERROR] #{event.payload[:name]}: #{exception.join(', ')} " \
|
54
|
+
# "(#{exception_object.backtrace.first})"
|
55
|
+
# else
|
56
|
+
# # standard logger code
|
57
|
+
# end
|
58
|
+
# end
|
59
|
+
# end
|
60
|
+
# end
|
33
61
|
#
|
34
62
|
# Log subscriber also has some helpers to deal with logging and automatically
|
35
|
-
# flushes all logs when the request finishes
|
36
|
-
# notification) in a Rails environment.
|
63
|
+
# flushes all logs when the request finishes
|
64
|
+
# (via <tt>action_dispatch.callback</tt> notification) in a Rails environment.
|
37
65
|
class LogSubscriber < Subscriber
|
38
66
|
# Embed in a String to clear all previous ANSI sequences.
|
39
67
|
CLEAR = "\e[0m"
|
@@ -49,8 +77,7 @@ module ActiveSupport
|
|
49
77
|
CYAN = "\e[36m"
|
50
78
|
WHITE = "\e[37m"
|
51
79
|
|
52
|
-
mattr_accessor :colorize_logging
|
53
|
-
self.colorize_logging = true
|
80
|
+
mattr_accessor :colorize_logging, default: true
|
54
81
|
|
55
82
|
class << self
|
56
83
|
def logger
|
@@ -69,6 +96,11 @@ module ActiveSupport
|
|
69
96
|
def flush_all!
|
70
97
|
logger.flush if logger.respond_to?(:flush)
|
71
98
|
end
|
99
|
+
|
100
|
+
private
|
101
|
+
def fetch_public_methods(subscriber, inherit_all)
|
102
|
+
subscriber.public_methods(inherit_all) - LogSubscriber.public_instance_methods(true)
|
103
|
+
end
|
72
104
|
end
|
73
105
|
|
74
106
|
def logger
|
@@ -81,12 +113,13 @@ module ActiveSupport
|
|
81
113
|
|
82
114
|
def finish(name, id, payload)
|
83
115
|
super if logger
|
84
|
-
rescue
|
85
|
-
logger
|
116
|
+
rescue => e
|
117
|
+
if logger
|
118
|
+
logger.error "Could not log #{name.inspect} event. #{e.class}: #{e.message} #{e.backtrace}"
|
119
|
+
end
|
86
120
|
end
|
87
121
|
|
88
|
-
|
89
|
-
|
122
|
+
private
|
90
123
|
%w(info debug warn error fatal unknown).each do |level|
|
91
124
|
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
92
125
|
def #{level}(progname = nil, &block)
|
@@ -99,7 +132,7 @@ module ActiveSupport
|
|
99
132
|
# option is set to +true+, it also adds bold to the string. This is based
|
100
133
|
# on the Highline implementation and will automatically append CLEAR to the
|
101
134
|
# end of the returned String.
|
102
|
-
def color(text, color, bold=false)
|
135
|
+
def color(text, color, bold = false) # :doc:
|
103
136
|
return text unless colorize_logging
|
104
137
|
color = self.class.const_get(color.upcase) if color.is_a?(Symbol)
|
105
138
|
bold = bold ? BOLD : ""
|
@@ -1,10 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/logger_silence"
|
4
|
+
require "active_support/logger_thread_safe_level"
|
5
|
+
require "logger"
|
4
6
|
|
5
7
|
module ActiveSupport
|
6
8
|
class Logger < ::Logger
|
7
|
-
include ActiveSupport::LoggerThreadSafeLevel
|
8
9
|
include LoggerSilence
|
9
10
|
|
10
11
|
# Returns true if the logger destination matches one of the sources
|
@@ -13,7 +14,7 @@ module ActiveSupport
|
|
13
14
|
# ActiveSupport::Logger.logger_outputs_to?(logger, STDOUT)
|
14
15
|
# # => true
|
15
16
|
def self.logger_outputs_to?(logger, *sources)
|
16
|
-
logdev = logger.instance_variable_get(
|
17
|
+
logdev = logger.instance_variable_get(:@logdev)
|
17
18
|
logger_source = logdev.dev if logdev.respond_to?(:dev)
|
18
19
|
sources.any? { |source| source == logger_source }
|
19
20
|
end
|
@@ -59,14 +60,14 @@ module ActiveSupport
|
|
59
60
|
define_method(:silence) do |level = Logger::ERROR, &block|
|
60
61
|
if logger.respond_to?(:silence)
|
61
62
|
logger.silence(level) do
|
62
|
-
if
|
63
|
+
if defined?(super)
|
63
64
|
super(level, &block)
|
64
65
|
else
|
65
66
|
block.call(self)
|
66
67
|
end
|
67
68
|
end
|
68
69
|
else
|
69
|
-
if
|
70
|
+
if defined?(super)
|
70
71
|
super(level, &block)
|
71
72
|
else
|
72
73
|
block.call(self)
|
@@ -76,23 +77,9 @@ module ActiveSupport
|
|
76
77
|
end
|
77
78
|
end
|
78
79
|
|
79
|
-
def initialize(*args)
|
80
|
+
def initialize(*args, **kwargs)
|
80
81
|
super
|
81
82
|
@formatter = SimpleFormatter.new
|
82
|
-
after_initialize if respond_to? :after_initialize
|
83
|
-
end
|
84
|
-
|
85
|
-
def add(severity, message = nil, progname = nil, &block)
|
86
|
-
return true if @logdev.nil? || (severity || UNKNOWN) < level
|
87
|
-
super
|
88
|
-
end
|
89
|
-
|
90
|
-
Logger::Severity.constants.each do |severity|
|
91
|
-
class_eval(<<-EOT, __FILE__, __LINE__ + 1)
|
92
|
-
def #{severity.downcase}? # def debug?
|
93
|
-
Logger::#{severity} >= level # DEBUG >= level
|
94
|
-
end # end
|
95
|
-
EOT
|
96
83
|
end
|
97
84
|
|
98
85
|
# Simple formatter which only displays the message.
|
@@ -1,28 +1,21 @@
|
|
1
|
-
|
2
|
-
require 'active_support/core_ext/module/attribute_accessors'
|
3
|
-
require 'concurrent'
|
1
|
+
# frozen_string_literal: true
|
4
2
|
|
5
|
-
|
6
|
-
|
3
|
+
require "active_support/concern"
|
4
|
+
require "active_support/core_ext/module/attribute_accessors"
|
5
|
+
require "active_support/logger_thread_safe_level"
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
7
|
+
module ActiveSupport
|
8
|
+
module LoggerSilence
|
9
|
+
extend ActiveSupport::Concern
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
old_local_level = local_level
|
18
|
-
self.local_level = temporary_level
|
11
|
+
included do
|
12
|
+
cattr_accessor :silencer, default: true
|
13
|
+
include ActiveSupport::LoggerThreadSafeLevel
|
14
|
+
end
|
19
15
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
24
|
-
else
|
25
|
-
yield self
|
16
|
+
# Silences the logger for the duration of the block.
|
17
|
+
def silence(severity = Logger::ERROR)
|
18
|
+
silencer ? log_at(severity) { yield self } : yield(self)
|
26
19
|
end
|
27
20
|
end
|
28
21
|
end
|
@@ -1,31 +1,78 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
require "active_support/core_ext/module/attribute_accessors"
|
5
|
+
require "concurrent"
|
6
|
+
require "fiber"
|
2
7
|
|
3
8
|
module ActiveSupport
|
4
9
|
module LoggerThreadSafeLevel # :nodoc:
|
5
10
|
extend ActiveSupport::Concern
|
6
11
|
|
7
|
-
|
8
|
-
|
12
|
+
included do
|
13
|
+
cattr_accessor :local_levels, default: Concurrent::Map.new(initial_capacity: 2), instance_accessor: false
|
14
|
+
end
|
15
|
+
|
16
|
+
Logger::Severity.constants.each do |severity|
|
17
|
+
class_eval(<<-EOT, __FILE__, __LINE__ + 1)
|
18
|
+
def #{severity.downcase}? # def debug?
|
19
|
+
Logger::#{severity} >= level # DEBUG >= level
|
20
|
+
end # end
|
21
|
+
EOT
|
9
22
|
end
|
10
23
|
|
11
24
|
def local_log_id
|
12
|
-
|
25
|
+
Fiber.current.__id__
|
13
26
|
end
|
14
27
|
|
15
28
|
def local_level
|
16
|
-
|
29
|
+
self.class.local_levels[local_log_id]
|
17
30
|
end
|
18
31
|
|
19
32
|
def local_level=(level)
|
20
|
-
|
21
|
-
|
33
|
+
case level
|
34
|
+
when Integer
|
35
|
+
self.class.local_levels[local_log_id] = level
|
36
|
+
when Symbol
|
37
|
+
self.class.local_levels[local_log_id] = Logger::Severity.const_get(level.to_s.upcase)
|
38
|
+
when nil
|
39
|
+
self.class.local_levels.delete(local_log_id)
|
22
40
|
else
|
23
|
-
|
41
|
+
raise ArgumentError, "Invalid log level: #{level.inspect}"
|
24
42
|
end
|
25
43
|
end
|
26
44
|
|
27
45
|
def level
|
28
46
|
local_level || super
|
29
47
|
end
|
48
|
+
|
49
|
+
# Change the thread-local level for the duration of the given block.
|
50
|
+
def log_at(level)
|
51
|
+
old_local_level, self.local_level = local_level, level
|
52
|
+
yield
|
53
|
+
ensure
|
54
|
+
self.local_level = old_local_level
|
55
|
+
end
|
56
|
+
|
57
|
+
# Redefined to check severity against #level, and thus the thread-local level, rather than +@level+.
|
58
|
+
# FIXME: Remove when the minimum Ruby version supports overriding Logger#level.
|
59
|
+
def add(severity, message = nil, progname = nil, &block) #:nodoc:
|
60
|
+
severity ||= UNKNOWN
|
61
|
+
progname ||= @progname
|
62
|
+
|
63
|
+
return true if @logdev.nil? || severity < level
|
64
|
+
|
65
|
+
if message.nil?
|
66
|
+
if block_given?
|
67
|
+
message = yield
|
68
|
+
else
|
69
|
+
message = progname
|
70
|
+
progname = @progname
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
@logdev.write \
|
75
|
+
format_message(format_severity(severity), Time.now, progname, message)
|
76
|
+
end
|
30
77
|
end
|
31
78
|
end
|