activesupport 4.2.11.1 → 5.2.8.1
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 +441 -399
- data/MIT-LICENSE +2 -2
- data/README.rdoc +4 -5
- data/lib/active_support/all.rb +5 -3
- data/lib/active_support/array_inquirer.rb +48 -0
- data/lib/active_support/backtrace_cleaner.rb +7 -5
- data/lib/active_support/benchmarkable.rb +6 -4
- data/lib/active_support/builder.rb +3 -1
- data/lib/active_support/cache/file_store.rb +41 -35
- data/lib/active_support/cache/mem_cache_store.rb +91 -91
- data/lib/active_support/cache/memory_store.rb +27 -30
- data/lib/active_support/cache/null_store.rb +7 -8
- data/lib/active_support/cache/redis_cache_store.rb +466 -0
- data/lib/active_support/cache/strategy/local_cache.rb +67 -34
- data/lib/active_support/cache/strategy/local_cache_middleware.rb +10 -9
- data/lib/active_support/cache.rb +287 -196
- data/lib/active_support/callbacks.rb +640 -590
- data/lib/active_support/concern.rb +11 -5
- data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +35 -0
- data/lib/active_support/concurrency/share_lock.rb +227 -0
- data/lib/active_support/configurable.rb +8 -5
- data/lib/active_support/core_ext/array/access.rb +29 -1
- data/lib/active_support/core_ext/array/conversions.rb +22 -18
- data/lib/active_support/core_ext/array/extract_options.rb +2 -0
- data/lib/active_support/core_ext/array/grouping.rb +11 -18
- data/lib/active_support/core_ext/array/inquiry.rb +19 -0
- data/lib/active_support/core_ext/array/prepend_and_append.rb +5 -3
- data/lib/active_support/core_ext/array/wrap.rb +7 -4
- data/lib/active_support/core_ext/array.rb +9 -6
- data/lib/active_support/core_ext/benchmark.rb +3 -1
- data/lib/active_support/core_ext/big_decimal/conversions.rb +10 -12
- data/lib/active_support/core_ext/big_decimal.rb +3 -1
- data/lib/active_support/core_ext/class/attribute.rb +41 -22
- data/lib/active_support/core_ext/class/attribute_accessors.rb +3 -1
- data/lib/active_support/core_ext/class/subclasses.rb +20 -6
- data/lib/active_support/core_ext/class.rb +4 -3
- data/lib/active_support/core_ext/date/acts_like.rb +3 -1
- data/lib/active_support/core_ext/date/blank.rb +14 -0
- data/lib/active_support/core_ext/date/calculations.rb +11 -9
- data/lib/active_support/core_ext/date/conversions.rb +25 -23
- data/lib/active_support/core_ext/date/zones.rb +4 -2
- data/lib/active_support/core_ext/date.rb +6 -4
- data/lib/active_support/core_ext/date_and_time/calculations.rb +170 -58
- data/lib/active_support/core_ext/date_and_time/compatibility.rb +4 -3
- data/lib/active_support/core_ext/date_and_time/zones.rb +12 -12
- data/lib/active_support/core_ext/date_time/acts_like.rb +4 -2
- data/lib/active_support/core_ext/date_time/blank.rb +14 -0
- data/lib/active_support/core_ext/date_time/calculations.rb +36 -18
- data/lib/active_support/core_ext/date_time/compatibility.rb +8 -6
- data/lib/active_support/core_ext/date_time/conversions.rb +16 -12
- data/lib/active_support/core_ext/date_time.rb +7 -5
- data/lib/active_support/core_ext/digest/uuid.rb +7 -5
- data/lib/active_support/core_ext/digest.rb +3 -0
- data/lib/active_support/core_ext/enumerable.rb +101 -33
- data/lib/active_support/core_ext/file/atomic.rb +38 -31
- data/lib/active_support/core_ext/file.rb +3 -1
- data/lib/active_support/core_ext/hash/compact.rb +14 -9
- data/lib/active_support/core_ext/hash/conversions.rb +62 -41
- data/lib/active_support/core_ext/hash/deep_merge.rb +9 -13
- data/lib/active_support/core_ext/hash/except.rb +11 -8
- data/lib/active_support/core_ext/hash/indifferent_access.rb +4 -3
- data/lib/active_support/core_ext/hash/keys.rb +33 -27
- data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
- data/lib/active_support/core_ext/hash/slice.rb +8 -8
- data/lib/active_support/core_ext/hash/transform_values.rb +14 -5
- data/lib/active_support/core_ext/hash.rb +11 -9
- data/lib/active_support/core_ext/integer/inflections.rb +3 -1
- data/lib/active_support/core_ext/integer/multiple.rb +2 -0
- data/lib/active_support/core_ext/integer/time.rb +11 -18
- data/lib/active_support/core_ext/integer.rb +5 -3
- data/lib/active_support/core_ext/kernel/agnostics.rb +2 -0
- data/lib/active_support/core_ext/kernel/concern.rb +5 -1
- data/lib/active_support/core_ext/kernel/reporting.rb +4 -84
- data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
- data/lib/active_support/core_ext/kernel.rb +6 -5
- data/lib/active_support/core_ext/load_error.rb +3 -22
- data/lib/active_support/core_ext/marshal.rb +8 -8
- data/lib/active_support/core_ext/module/aliasing.rb +6 -44
- data/lib/active_support/core_ext/module/anonymous.rb +12 -1
- data/lib/active_support/core_ext/module/attr_internal.rb +8 -9
- data/lib/active_support/core_ext/module/attribute_accessors.rb +43 -40
- data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +150 -0
- data/lib/active_support/core_ext/module/concerning.rb +11 -12
- data/lib/active_support/core_ext/module/delegation.rb +99 -29
- data/lib/active_support/core_ext/module/deprecation.rb +4 -2
- data/lib/active_support/core_ext/module/introspection.rb +9 -9
- data/lib/active_support/core_ext/module/reachable.rb +5 -2
- data/lib/active_support/core_ext/module/redefine_method.rb +49 -0
- data/lib/active_support/core_ext/module/remove_method.rb +8 -3
- data/lib/active_support/core_ext/module.rb +14 -11
- data/lib/active_support/core_ext/name_error.rb +22 -2
- data/lib/active_support/core_ext/numeric/bytes.rb +22 -0
- data/lib/active_support/core_ext/numeric/conversions.rb +78 -81
- data/lib/active_support/core_ext/numeric/inquiry.rb +28 -0
- data/lib/active_support/core_ext/numeric/time.rb +35 -23
- data/lib/active_support/core_ext/numeric.rb +6 -3
- data/lib/active_support/core_ext/object/acts_like.rb +12 -1
- data/lib/active_support/core_ext/object/blank.rb +27 -2
- data/lib/active_support/core_ext/object/conversions.rb +6 -4
- data/lib/active_support/core_ext/object/deep_dup.rb +13 -4
- data/lib/active_support/core_ext/object/duplicable.rb +41 -14
- data/lib/active_support/core_ext/object/inclusion.rb +5 -3
- data/lib/active_support/core_ext/object/instance_variables.rb +3 -1
- data/lib/active_support/core_ext/object/json.rb +49 -19
- data/lib/active_support/core_ext/object/to_param.rb +3 -1
- data/lib/active_support/core_ext/object/to_query.rb +10 -5
- data/lib/active_support/core_ext/object/try.rb +69 -21
- data/lib/active_support/core_ext/object/with_options.rb +16 -3
- data/lib/active_support/core_ext/object.rb +14 -13
- data/lib/active_support/core_ext/range/compare_range.rb +61 -0
- data/lib/active_support/core_ext/range/conversions.rb +27 -7
- data/lib/active_support/core_ext/range/each.rb +19 -17
- data/lib/active_support/core_ext/range/include_range.rb +2 -22
- data/lib/active_support/core_ext/range/include_time_with_zone.rb +23 -0
- data/lib/active_support/core_ext/range/overlaps.rb +2 -0
- data/lib/active_support/core_ext/range.rb +7 -4
- data/lib/active_support/core_ext/regexp.rb +6 -0
- data/lib/active_support/core_ext/securerandom.rb +25 -0
- data/lib/active_support/core_ext/string/access.rb +8 -6
- data/lib/active_support/core_ext/string/behavior.rb +3 -1
- data/lib/active_support/core_ext/string/conversions.rb +7 -4
- data/lib/active_support/core_ext/string/exclude.rb +2 -0
- data/lib/active_support/core_ext/string/filters.rb +6 -5
- data/lib/active_support/core_ext/string/indent.rb +6 -4
- data/lib/active_support/core_ext/string/inflections.rb +61 -24
- data/lib/active_support/core_ext/string/inquiry.rb +3 -1
- data/lib/active_support/core_ext/string/multibyte.rb +15 -7
- data/lib/active_support/core_ext/string/output_safety.rb +62 -38
- data/lib/active_support/core_ext/string/starts_ends_with.rb +2 -0
- data/lib/active_support/core_ext/string/strip.rb +4 -5
- data/lib/active_support/core_ext/string/zones.rb +4 -2
- data/lib/active_support/core_ext/string.rb +15 -13
- data/lib/active_support/core_ext/time/acts_like.rb +3 -1
- data/lib/active_support/core_ext/time/calculations.rb +85 -51
- data/lib/active_support/core_ext/time/compatibility.rb +4 -2
- data/lib/active_support/core_ext/time/conversions.rb +20 -13
- data/lib/active_support/core_ext/time/zones.rb +41 -7
- data/lib/active_support/core_ext/time.rb +7 -6
- data/lib/active_support/core_ext/uri.rb +6 -8
- data/lib/active_support/core_ext.rb +3 -1
- data/lib/active_support/current_attributes.rb +195 -0
- data/lib/active_support/dependencies/autoload.rb +2 -0
- data/lib/active_support/dependencies/interlock.rb +57 -0
- data/lib/active_support/dependencies.rb +152 -161
- data/lib/active_support/deprecation/behaviors.rb +44 -11
- data/lib/active_support/deprecation/constant_accessor.rb +52 -0
- data/lib/active_support/deprecation/instance_delegator.rb +17 -2
- data/lib/active_support/deprecation/method_wrappers.rb +66 -20
- data/lib/active_support/deprecation/proxy_wrappers.rb +56 -28
- data/lib/active_support/deprecation/reporting.rb +32 -12
- data/lib/active_support/deprecation.rb +12 -9
- data/lib/active_support/descendants_tracker.rb +2 -0
- data/lib/active_support/digest.rb +20 -0
- data/lib/active_support/duration/iso8601_parser.rb +125 -0
- data/lib/active_support/duration/iso8601_serializer.rb +55 -0
- data/lib/active_support/duration.rb +314 -38
- data/lib/active_support/encrypted_configuration.rb +49 -0
- data/lib/active_support/encrypted_file.rb +99 -0
- data/lib/active_support/evented_file_update_checker.rb +205 -0
- data/lib/active_support/execution_wrapper.rb +131 -0
- data/lib/active_support/executor.rb +8 -0
- data/lib/active_support/file_update_checker.rb +63 -37
- data/lib/active_support/gem_version.rb +5 -3
- data/lib/active_support/gzip.rb +7 -5
- data/lib/active_support/hash_with_indifferent_access.rb +123 -28
- data/lib/active_support/i18n.rb +8 -6
- data/lib/active_support/i18n_railtie.rb +37 -13
- data/lib/active_support/inflections.rb +13 -11
- data/lib/active_support/inflector/inflections.rb +61 -12
- data/lib/active_support/inflector/methods.rb +163 -136
- data/lib/active_support/inflector/transliterate.rb +48 -27
- data/lib/active_support/inflector.rb +7 -5
- data/lib/active_support/json/decoding.rb +16 -13
- data/lib/active_support/json/encoding.rb +11 -58
- data/lib/active_support/json.rb +4 -2
- data/lib/active_support/key_generator.rb +25 -25
- data/lib/active_support/lazy_load_hooks.rb +50 -20
- data/lib/active_support/locale/en.yml +2 -0
- data/lib/active_support/log_subscriber/test_helper.rb +14 -12
- data/lib/active_support/log_subscriber.rb +13 -10
- data/lib/active_support/logger.rb +8 -7
- data/lib/active_support/logger_silence.rb +6 -4
- data/lib/active_support/logger_thread_safe_level.rb +7 -5
- data/lib/active_support/message_encryptor.rb +168 -53
- data/lib/active_support/message_verifier.rb +150 -17
- data/lib/active_support/messages/metadata.rb +71 -0
- data/lib/active_support/messages/rotation_configuration.rb +22 -0
- data/lib/active_support/messages/rotator.rb +56 -0
- data/lib/active_support/multibyte/chars.rb +36 -23
- data/lib/active_support/multibyte/unicode.rb +100 -96
- data/lib/active_support/multibyte.rb +4 -2
- data/lib/active_support/notifications/fanout.rb +11 -9
- data/lib/active_support/notifications/instrumenter.rb +27 -7
- data/lib/active_support/notifications.rb +11 -7
- data/lib/active_support/number_helper/number_converter.rb +13 -11
- data/lib/active_support/number_helper/number_to_currency_converter.rb +9 -9
- data/lib/active_support/number_helper/number_to_delimited_converter.rb +9 -3
- data/lib/active_support/number_helper/number_to_human_converter.rb +11 -9
- data/lib/active_support/number_helper/number_to_human_size_converter.rb +9 -8
- data/lib/active_support/number_helper/number_to_percentage_converter.rb +3 -1
- data/lib/active_support/number_helper/number_to_phone_converter.rb +13 -4
- data/lib/active_support/number_helper/number_to_rounded_converter.rb +23 -56
- data/lib/active_support/number_helper/rounding_helper.rb +66 -0
- data/lib/active_support/number_helper.rb +94 -68
- data/lib/active_support/option_merger.rb +3 -1
- data/lib/active_support/ordered_hash.rb +6 -4
- data/lib/active_support/ordered_options.rb +23 -5
- data/lib/active_support/per_thread_registry.rb +9 -4
- data/lib/active_support/proxy_object.rb +2 -0
- data/lib/active_support/rails.rb +16 -8
- data/lib/active_support/railtie.rb +43 -9
- data/lib/active_support/reloader.rb +131 -0
- data/lib/active_support/rescuable.rb +108 -53
- data/lib/active_support/security_utils.rb +15 -11
- data/lib/active_support/string_inquirer.rb +11 -3
- data/lib/active_support/subscriber.rb +21 -16
- data/lib/active_support/tagged_logging.rb +14 -11
- data/lib/active_support/test_case.rb +19 -47
- data/lib/active_support/testing/assertions.rb +137 -20
- data/lib/active_support/testing/autorun.rb +4 -2
- data/lib/active_support/testing/constant_lookup.rb +2 -1
- data/lib/active_support/testing/declarative.rb +3 -1
- data/lib/active_support/testing/deprecation.rb +14 -10
- data/lib/active_support/testing/file_fixtures.rb +36 -0
- data/lib/active_support/testing/isolation.rb +34 -25
- data/lib/active_support/testing/method_call_assertions.rb +43 -0
- data/lib/active_support/testing/setup_and_teardown.rb +13 -8
- data/lib/active_support/testing/stream.rb +44 -0
- data/lib/active_support/testing/tagged_logging.rb +3 -1
- data/lib/active_support/testing/time_helpers.rb +81 -15
- data/lib/active_support/time.rb +14 -12
- data/lib/active_support/time_with_zone.rb +169 -39
- data/lib/active_support/values/time_zone.rb +196 -61
- data/lib/active_support/values/unicode_tables.dat +0 -0
- data/lib/active_support/version.rb +3 -1
- data/lib/active_support/xml_mini/jdom.rb +116 -114
- data/lib/active_support/xml_mini/libxml.rb +16 -13
- data/lib/active_support/xml_mini/libxmlsax.rb +15 -14
- data/lib/active_support/xml_mini/nokogiri.rb +14 -12
- data/lib/active_support/xml_mini/nokogirisax.rb +14 -13
- data/lib/active_support/xml_mini/rexml.rb +11 -9
- data/lib/active_support/xml_mini.rb +37 -37
- data/lib/active_support.rb +12 -11
- metadata +57 -27
- data/lib/active_support/concurrency/latch.rb +0 -27
- data/lib/active_support/core_ext/big_decimal/yaml_conversions.rb +0 -16
- data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -45
- data/lib/active_support/core_ext/date_time/zones.rb +0 -6
- data/lib/active_support/core_ext/kernel/debugger.rb +0 -10
- data/lib/active_support/core_ext/module/method_transplanting.rb +0 -13
- data/lib/active_support/core_ext/module/qualified_const.rb +0 -52
- data/lib/active_support/core_ext/object/itself.rb +0 -15
- data/lib/active_support/core_ext/struct.rb +0 -6
- data/lib/active_support/core_ext/thread.rb +0 -86
- data/lib/active_support/core_ext/time/marshal.rb +0 -30
@@ -1,6 +1,8 @@
|
|
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/module/delegation"
|
5
|
+
require "json"
|
4
6
|
|
5
7
|
module ActiveSupport
|
6
8
|
# Look for and parse json strings that look like ISO 8601 times.
|
@@ -8,21 +10,16 @@ module ActiveSupport
|
|
8
10
|
|
9
11
|
module JSON
|
10
12
|
# matches YAML-formatted dates
|
11
|
-
DATE_REGEX =
|
12
|
-
|
13
|
+
DATE_REGEX = /^\d{4}-\d{2}-\d{2}$/
|
14
|
+
DATETIME_REGEX = /^(?:\d{4}-\d{2}-\d{2}|\d{4}-\d{1,2}-\d{1,2}[T \t]+\d{1,2}:\d{2}:\d{2}(\.[0-9]*)?(([ \t]*)Z|[-+]\d{2}?(:\d{2})?)?)$/
|
15
|
+
|
13
16
|
class << self
|
14
17
|
# Parses a JSON string (JavaScript Object Notation) into a hash.
|
15
18
|
# See http://www.json.org for more info.
|
16
19
|
#
|
17
20
|
# ActiveSupport::JSON.decode("{\"team\":\"rails\",\"players\":\"36\"}")
|
18
21
|
# => {"team" => "rails", "players" => "36"}
|
19
|
-
def decode(json
|
20
|
-
if options.present?
|
21
|
-
raise ArgumentError, "In Rails 4.1, ActiveSupport::JSON.decode no longer " \
|
22
|
-
"accepts an options hash for MultiJSON. MultiJSON reached its end of life " \
|
23
|
-
"and has been removed."
|
24
|
-
end
|
25
|
-
|
22
|
+
def decode(json)
|
26
23
|
data = ::JSON.parse(json, quirks_mode: true)
|
27
24
|
|
28
25
|
if ActiveSupport.parse_json_times
|
@@ -54,7 +51,13 @@ module ActiveSupport
|
|
54
51
|
nil
|
55
52
|
when DATE_REGEX
|
56
53
|
begin
|
57
|
-
|
54
|
+
Date.parse(data)
|
55
|
+
rescue ArgumentError
|
56
|
+
data
|
57
|
+
end
|
58
|
+
when DATETIME_REGEX
|
59
|
+
begin
|
60
|
+
Time.zone.parse(data)
|
58
61
|
rescue ArgumentError
|
59
62
|
data
|
60
63
|
end
|
@@ -1,15 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/object/json"
|
4
|
+
require "active_support/core_ext/module/delegation"
|
4
5
|
|
5
6
|
module ActiveSupport
|
6
7
|
class << self
|
7
8
|
delegate :use_standard_json_time_format, :use_standard_json_time_format=,
|
8
9
|
:time_precision, :time_precision=,
|
9
10
|
:escape_html_entities_in_json, :escape_html_entities_in_json=,
|
10
|
-
:encode_big_decimal_as_string, :encode_big_decimal_as_string=,
|
11
11
|
:json_encoder, :json_encoder=,
|
12
|
-
:
|
12
|
+
to: :'ActiveSupport::JSON::Encoding'
|
13
13
|
end
|
14
14
|
|
15
15
|
module JSON
|
@@ -42,9 +42,9 @@ module ActiveSupport
|
|
42
42
|
ESCAPED_CHARS = {
|
43
43
|
"\u2028" => '\u2028',
|
44
44
|
"\u2029" => '\u2029',
|
45
|
-
|
46
|
-
|
47
|
-
|
45
|
+
">" => '\u003e',
|
46
|
+
"<" => '\u003c',
|
47
|
+
"&" => '\u0026',
|
48
48
|
}
|
49
49
|
|
50
50
|
ESCAPE_REGEX_WITH_HTML_ENTITIES = /[\u2028\u2029><&]/u
|
@@ -70,7 +70,8 @@ module ActiveSupport
|
|
70
70
|
:ESCAPE_REGEX_WITHOUT_HTML_ENTITIES, :EscapedString
|
71
71
|
|
72
72
|
# Convert an object into a "JSON-ready" representation composed of
|
73
|
-
# primitives like Hash, Array, String, Numeric,
|
73
|
+
# primitives like Hash, Array, String, Numeric,
|
74
|
+
# and +true+/+false+/+nil+.
|
74
75
|
# Recursively calls #as_json to the object to recursively build a
|
75
76
|
# fully JSON-ready object.
|
76
77
|
#
|
@@ -86,7 +87,7 @@ module ActiveSupport
|
|
86
87
|
when String
|
87
88
|
EscapedString.new(value)
|
88
89
|
when Numeric, NilClass, TrueClass, FalseClass
|
89
|
-
value
|
90
|
+
value.as_json
|
90
91
|
when Hash
|
91
92
|
Hash[value.map { |k, v| [jsonify(k), jsonify(v)] }]
|
92
93
|
when Array
|
@@ -118,54 +119,6 @@ module ActiveSupport
|
|
118
119
|
# Sets the encoder used by Rails to encode Ruby objects into JSON strings
|
119
120
|
# in +Object#to_json+ and +ActiveSupport::JSON.encode+.
|
120
121
|
attr_accessor :json_encoder
|
121
|
-
|
122
|
-
def encode_big_decimal_as_string=(as_string)
|
123
|
-
message = \
|
124
|
-
"The JSON encoder in Rails 4.1 no longer supports encoding BigDecimals as JSON numbers. Instead, " \
|
125
|
-
"the new encoder will always encode them as strings.\n\n" \
|
126
|
-
"You are seeing this error because you have 'active_support.encode_big_decimal_as_string' in " \
|
127
|
-
"your configuration file. If you have been setting this to true, you can safely remove it from " \
|
128
|
-
"your configuration. Otherwise, you should add the 'activesupport-json_encoder' gem to your " \
|
129
|
-
"Gemfile in order to restore this functionality."
|
130
|
-
|
131
|
-
raise NotImplementedError, message
|
132
|
-
end
|
133
|
-
|
134
|
-
def encode_big_decimal_as_string
|
135
|
-
message = \
|
136
|
-
"The JSON encoder in Rails 4.1 no longer supports encoding BigDecimals as JSON numbers. Instead, " \
|
137
|
-
"the new encoder will always encode them as strings.\n\n" \
|
138
|
-
"You are seeing this error because you are trying to check the value of the related configuration, " \
|
139
|
-
"`active_support.encode_big_decimal_as_string`. If your application depends on this option, you should " \
|
140
|
-
"add the 'activesupport-json_encoder' gem to your Gemfile. For now, this option will always be true. " \
|
141
|
-
"In the future, it will be removed from Rails, so you should stop checking its value."
|
142
|
-
|
143
|
-
ActiveSupport::Deprecation.warn message
|
144
|
-
|
145
|
-
true
|
146
|
-
end
|
147
|
-
|
148
|
-
# Deprecate CircularReferenceError
|
149
|
-
def const_missing(name)
|
150
|
-
if name == :CircularReferenceError
|
151
|
-
message = "The JSON encoder in Rails 4.1 no longer offers protection from circular references. " \
|
152
|
-
"You are seeing this warning because you are rescuing from (or otherwise referencing) " \
|
153
|
-
"ActiveSupport::Encoding::CircularReferenceError. In the future, this error will be " \
|
154
|
-
"removed from Rails. You should remove these rescue blocks from your code and ensure " \
|
155
|
-
"that your data structures are free of circular references so they can be properly " \
|
156
|
-
"serialized into JSON.\n\n" \
|
157
|
-
"For example, the following Hash contains a circular reference to itself:\n" \
|
158
|
-
" h = {}\n" \
|
159
|
-
" h['circular'] = h\n" \
|
160
|
-
"In this case, calling h.to_json would not work properly."
|
161
|
-
|
162
|
-
ActiveSupport::Deprecation.warn message
|
163
|
-
|
164
|
-
SystemStackError
|
165
|
-
else
|
166
|
-
super
|
167
|
-
end
|
168
|
-
end
|
169
122
|
end
|
170
123
|
|
171
124
|
self.use_standard_json_time_format = true
|
data/lib/active_support/json.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "concurrent/map"
|
4
|
+
require "openssl"
|
3
5
|
|
4
6
|
module ActiveSupport
|
5
|
-
# KeyGenerator is a simple wrapper around OpenSSL's implementation of PBKDF2
|
7
|
+
# KeyGenerator is a simple wrapper around OpenSSL's implementation of PBKDF2.
|
6
8
|
# It can be used to derive a number of keys for various purposes from a given secret.
|
7
9
|
# This lets Rails applications have a single secure secret, but avoid reusing that
|
8
10
|
# key in multiple incompatible contexts.
|
@@ -17,25 +19,23 @@ 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
|
24
26
|
|
25
27
|
# CachingKeyGenerator is a wrapper around KeyGenerator which allows users to avoid
|
26
28
|
# re-executing the key generation process when it's called using the same salt and
|
27
|
-
# key_size
|
29
|
+
# key_size.
|
28
30
|
class CachingKeyGenerator
|
29
31
|
def initialize(key_generator)
|
30
32
|
@key_generator = key_generator
|
31
|
-
@cache_keys =
|
33
|
+
@cache_keys = Concurrent::Map.new
|
32
34
|
end
|
33
35
|
|
34
|
-
# Returns a derived key suitable for use.
|
35
|
-
|
36
|
-
|
37
|
-
def generate_key(salt, key_size=64)
|
38
|
-
@cache_keys["#{salt}#{key_size}"] ||= @key_generator.generate_key(salt, key_size)
|
36
|
+
# Returns a derived key suitable for use.
|
37
|
+
def generate_key(*args)
|
38
|
+
@cache_keys[args.join] ||= @key_generator.generate_key(*args)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -53,21 +53,21 @@ module ActiveSupport
|
|
53
53
|
|
54
54
|
private
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
56
|
+
# To prevent users from using something insecure like "Password" we make sure that the
|
57
|
+
# secret they've provided is at least 30 characters in length.
|
58
|
+
def ensure_secret_secure(secret)
|
59
|
+
if secret.blank?
|
60
|
+
raise ArgumentError, "A secret is required to generate an integrity hash " \
|
61
|
+
"for cookie session data. Set a secret_key_base of at least " \
|
62
|
+
"#{SECRET_MIN_LENGTH} characters in via `bin/rails credentials:edit`."
|
63
|
+
end
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
65
|
+
if secret.length < SECRET_MIN_LENGTH
|
66
|
+
raise ArgumentError, "Secret should be something secure, " \
|
67
|
+
"like \"#{SecureRandom.hex(16)}\". The value you " \
|
68
|
+
"provided, \"#{secret}\", is shorter than the minimum length " \
|
69
|
+
"of #{SECRET_MIN_LENGTH} characters."
|
70
|
+
end
|
70
71
|
end
|
71
|
-
end
|
72
72
|
end
|
73
73
|
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,62 @@ 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
|
+
|
58
|
+
def with_execution_control(name, block, once)
|
59
|
+
unless @run_once[name].include?(block)
|
60
|
+
@run_once[name] << block if once
|
61
|
+
|
62
|
+
yield
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def execute_hook(name, base, options, block)
|
67
|
+
with_execution_control(name, block, options[:run_once]) do
|
68
|
+
if options[:yield]
|
69
|
+
block.call(base)
|
70
|
+
else
|
71
|
+
base.instance_eval(&block)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
47
75
|
end
|
76
|
+
|
77
|
+
extend LazyLoadHooks
|
48
78
|
end
|
@@ -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
|
@@ -10,7 +12,7 @@ module ActiveSupport
|
|
10
12
|
# class SyncLogSubscriberTest < ActiveSupport::TestCase
|
11
13
|
# include ActiveSupport::LogSubscriber::TestHelper
|
12
14
|
#
|
13
|
-
#
|
15
|
+
# setup do
|
14
16
|
# ActiveRecord::LogSubscriber.attach_to(:active_record)
|
15
17
|
# end
|
16
18
|
#
|
@@ -33,7 +35,7 @@ module ActiveSupport
|
|
33
35
|
# you can collect them doing @logger.logged(level), where level is the level
|
34
36
|
# used in logging, like info, debug, warn and so on.
|
35
37
|
module TestHelper
|
36
|
-
def setup
|
38
|
+
def setup # :nodoc:
|
37
39
|
@logger = MockLogger.new
|
38
40
|
@notifier = ActiveSupport::Notifications::Fanout.new
|
39
41
|
|
@@ -44,7 +46,7 @@ module ActiveSupport
|
|
44
46
|
ActiveSupport::Notifications.notifier = @notifier
|
45
47
|
end
|
46
48
|
|
47
|
-
def teardown
|
49
|
+
def teardown # :nodoc:
|
48
50
|
set_logger(nil)
|
49
51
|
ActiveSupport::Notifications.notifier = @old_notifier
|
50
52
|
end
|
@@ -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,6 +1,8 @@
|
|
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
8
|
# ActiveSupport::LogSubscriber is an object set to consume
|
@@ -49,8 +51,7 @@ module ActiveSupport
|
|
49
51
|
CYAN = "\e[36m"
|
50
52
|
WHITE = "\e[37m"
|
51
53
|
|
52
|
-
mattr_accessor :colorize_logging
|
53
|
-
self.colorize_logging = true
|
54
|
+
mattr_accessor :colorize_logging, default: true
|
54
55
|
|
55
56
|
class << self
|
56
57
|
def logger
|
@@ -81,11 +82,13 @@ module ActiveSupport
|
|
81
82
|
|
82
83
|
def finish(name, id, payload)
|
83
84
|
super if logger
|
84
|
-
rescue
|
85
|
-
logger
|
85
|
+
rescue => e
|
86
|
+
if logger
|
87
|
+
logger.error "Could not log #{name.inspect} event. #{e.class}: #{e.message} #{e.backtrace}"
|
88
|
+
end
|
86
89
|
end
|
87
90
|
|
88
|
-
|
91
|
+
private
|
89
92
|
|
90
93
|
%w(info debug warn error fatal unknown).each do |level|
|
91
94
|
class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
@@ -95,11 +98,11 @@ module ActiveSupport
|
|
95
98
|
METHOD
|
96
99
|
end
|
97
100
|
|
98
|
-
# Set color by using a
|
101
|
+
# Set color by using a symbol or one of the defined constants. If a third
|
99
102
|
# option is set to +true+, it also adds bold to the string. This is based
|
100
103
|
# on the Highline implementation and will automatically append CLEAR to the
|
101
104
|
# end of the returned String.
|
102
|
-
def color(text, color, bold=false)
|
105
|
+
def color(text, color, bold = false) # :doc:
|
103
106
|
return text unless colorize_logging
|
104
107
|
color = self.class.const_get(color.upcase) if color.is_a?(Symbol)
|
105
108
|
bold = bold ? BOLD : ""
|
@@ -1,7 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/logger_silence"
|
4
|
+
require "active_support/logger_thread_safe_level"
|
5
|
+
require "logger"
|
5
6
|
|
6
7
|
module ActiveSupport
|
7
8
|
class Logger < ::Logger
|
@@ -58,16 +59,16 @@ module ActiveSupport
|
|
58
59
|
end
|
59
60
|
|
60
61
|
define_method(:silence) do |level = Logger::ERROR, &block|
|
61
|
-
if logger.respond_to?(:silence)
|
62
|
+
if logger.respond_to?(:silence)
|
62
63
|
logger.silence(level) do
|
63
|
-
if
|
64
|
+
if defined?(super)
|
64
65
|
super(level, &block)
|
65
66
|
else
|
66
67
|
block.call(self)
|
67
68
|
end
|
68
69
|
end
|
69
70
|
else
|
70
|
-
if
|
71
|
+
if defined?(super)
|
71
72
|
super(level, &block)
|
72
73
|
else
|
73
74
|
block.call(self)
|
@@ -1,12 +1,14 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
require "active_support/core_ext/module/attribute_accessors"
|
5
|
+
require "concurrent"
|
3
6
|
|
4
7
|
module LoggerSilence
|
5
8
|
extend ActiveSupport::Concern
|
6
9
|
|
7
10
|
included do
|
8
|
-
cattr_accessor :silencer
|
9
|
-
self.silencer = true
|
11
|
+
cattr_accessor :silencer, default: true
|
10
12
|
end
|
11
13
|
|
12
14
|
# Silences the logger for the duration of the block.
|
@@ -1,16 +1,18 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
require "fiber"
|
3
5
|
|
4
6
|
module ActiveSupport
|
5
|
-
module LoggerThreadSafeLevel
|
7
|
+
module LoggerThreadSafeLevel # :nodoc:
|
6
8
|
extend ActiveSupport::Concern
|
7
9
|
|
8
10
|
def after_initialize
|
9
|
-
@local_levels =
|
11
|
+
@local_levels = Concurrent::Map.new(initial_capacity: 2)
|
10
12
|
end
|
11
13
|
|
12
14
|
def local_log_id
|
13
|
-
|
15
|
+
Fiber.current.__id__
|
14
16
|
end
|
15
17
|
|
16
18
|
def local_level
|