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,6 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "libxml"
|
4
|
+
require "active_support/core_ext/object/blank"
|
5
|
+
require "stringio"
|
4
6
|
|
5
7
|
module ActiveSupport
|
6
8
|
module XmlMini_LibXML #:nodoc:
|
@@ -11,18 +13,15 @@ module ActiveSupport
|
|
11
13
|
# XML Document string or IO to parse
|
12
14
|
def parse(data)
|
13
15
|
if !data.respond_to?(:read)
|
14
|
-
data = StringIO.new(data ||
|
16
|
+
data = StringIO.new(data || "")
|
15
17
|
end
|
16
18
|
|
17
|
-
|
18
|
-
if char.nil?
|
19
|
+
if data.eof?
|
19
20
|
{}
|
20
21
|
else
|
21
|
-
data.ungetc(char)
|
22
22
|
LibXML::XML::Parser.io(data).parse.to_hash
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
26
25
|
end
|
27
26
|
end
|
28
27
|
|
@@ -35,20 +34,20 @@ module LibXML #:nodoc:
|
|
35
34
|
end
|
36
35
|
|
37
36
|
module Node #:nodoc:
|
38
|
-
CONTENT_ROOT =
|
37
|
+
CONTENT_ROOT = "__content__"
|
39
38
|
|
40
39
|
# Convert XML document to hash.
|
41
40
|
#
|
42
41
|
# hash::
|
43
42
|
# Hash to merge the converted element into.
|
44
|
-
def to_hash(hash={})
|
43
|
+
def to_hash(hash = {})
|
45
44
|
node_hash = {}
|
46
45
|
|
47
46
|
# Insert node hash into parent hash correctly.
|
48
47
|
case hash[name]
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
when Array then hash[name] << node_hash
|
49
|
+
when Hash then hash[name] = [hash[name], node_hash]
|
50
|
+
when nil then hash[name] = node_hash
|
52
51
|
end
|
53
52
|
|
54
53
|
# Handle child elements
|
@@ -56,7 +55,7 @@ module LibXML #:nodoc:
|
|
56
55
|
if c.element?
|
57
56
|
c.to_hash(node_hash)
|
58
57
|
elsif c.text? || c.cdata?
|
59
|
-
node_hash[CONTENT_ROOT] ||=
|
58
|
+
node_hash[CONTENT_ROOT] ||= +""
|
60
59
|
node_hash[CONTENT_ROOT] << c.content
|
61
60
|
end
|
62
61
|
end
|
@@ -75,5 +74,7 @@ module LibXML #:nodoc:
|
|
75
74
|
end
|
76
75
|
end
|
77
76
|
|
77
|
+
# :enddoc:
|
78
|
+
|
78
79
|
LibXML::XML::Document.include(LibXML::Conversions::Document)
|
79
80
|
LibXML::XML::Node.include(LibXML::Conversions::Node)
|
@@ -1,6 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "libxml"
|
4
|
+
require "active_support/core_ext/object/blank"
|
5
|
+
require "stringio"
|
4
6
|
|
5
7
|
module ActiveSupport
|
6
8
|
module XmlMini_LibXMLSAX #:nodoc:
|
@@ -9,11 +11,10 @@ module ActiveSupport
|
|
9
11
|
# Class that will build the hash while the XML document
|
10
12
|
# is being parsed using SAX events.
|
11
13
|
class HashBuilder
|
12
|
-
|
13
14
|
include LibXML::XML::SaxParser::Callbacks
|
14
15
|
|
15
|
-
CONTENT_KEY =
|
16
|
-
HASH_SIZE_KEY =
|
16
|
+
CONTENT_KEY = "__content__"
|
17
|
+
HASH_SIZE_KEY = "__hash_size__"
|
17
18
|
|
18
19
|
attr_reader :hash
|
19
20
|
|
@@ -22,7 +23,7 @@ module ActiveSupport
|
|
22
23
|
end
|
23
24
|
|
24
25
|
def on_start_document
|
25
|
-
@hash = { CONTENT_KEY =>
|
26
|
+
@hash = { CONTENT_KEY => +"" }
|
26
27
|
@hash_stack = [@hash]
|
27
28
|
end
|
28
29
|
|
@@ -32,20 +33,20 @@ module ActiveSupport
|
|
32
33
|
end
|
33
34
|
|
34
35
|
def on_start_element(name, attrs = {})
|
35
|
-
new_hash = { CONTENT_KEY =>
|
36
|
+
new_hash = { CONTENT_KEY => +"" }.merge!(attrs)
|
36
37
|
new_hash[HASH_SIZE_KEY] = new_hash.size + 1
|
37
38
|
|
38
39
|
case current_hash[name]
|
39
|
-
|
40
|
-
|
41
|
-
|
40
|
+
when Array then current_hash[name] << new_hash
|
41
|
+
when Hash then current_hash[name] = [current_hash[name], new_hash]
|
42
|
+
when nil then current_hash[name] = new_hash
|
42
43
|
end
|
43
44
|
|
44
45
|
@hash_stack.push(new_hash)
|
45
46
|
end
|
46
47
|
|
47
48
|
def on_end_element(name)
|
48
|
-
if current_hash.length > current_hash.delete(HASH_SIZE_KEY) && current_hash[CONTENT_KEY].blank? || current_hash[CONTENT_KEY] ==
|
49
|
+
if current_hash.length > current_hash.delete(HASH_SIZE_KEY) && current_hash[CONTENT_KEY].blank? || current_hash[CONTENT_KEY] == ""
|
49
50
|
current_hash.delete(CONTENT_KEY)
|
50
51
|
end
|
51
52
|
@hash_stack.pop
|
@@ -63,18 +64,15 @@ module ActiveSupport
|
|
63
64
|
|
64
65
|
def parse(data)
|
65
66
|
if !data.respond_to?(:read)
|
66
|
-
data = StringIO.new(data ||
|
67
|
+
data = StringIO.new(data || "")
|
67
68
|
end
|
68
69
|
|
69
|
-
|
70
|
-
if char.nil?
|
70
|
+
if data.eof?
|
71
71
|
{}
|
72
72
|
else
|
73
|
-
data.ungetc(char)
|
74
|
-
|
75
73
|
LibXML::XML::Error.set_handler(&LibXML::XML::Error::QUIET_HANDLER)
|
76
74
|
parser = LibXML::XML::SaxParser.io(data)
|
77
|
-
document =
|
75
|
+
document = document_class.new
|
78
76
|
|
79
77
|
parser.callbacks = document
|
80
78
|
parser.parse
|
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
begin
|
2
|
-
require
|
4
|
+
require "nokogiri"
|
3
5
|
rescue LoadError => e
|
4
6
|
$stderr.puts "You don't have nokogiri installed in your application. Please add it to your Gemfile and run bundle install"
|
5
7
|
raise e
|
6
8
|
end
|
7
|
-
require
|
8
|
-
require
|
9
|
+
require "active_support/core_ext/object/blank"
|
10
|
+
require "stringio"
|
9
11
|
|
10
12
|
module ActiveSupport
|
11
13
|
module XmlMini_Nokogiri #:nodoc:
|
@@ -16,14 +18,12 @@ module ActiveSupport
|
|
16
18
|
# XML Document string or IO to parse
|
17
19
|
def parse(data)
|
18
20
|
if !data.respond_to?(:read)
|
19
|
-
data = StringIO.new(data ||
|
21
|
+
data = StringIO.new(data || "")
|
20
22
|
end
|
21
23
|
|
22
|
-
|
23
|
-
if char.nil?
|
24
|
+
if data.eof?
|
24
25
|
{}
|
25
26
|
else
|
26
|
-
data.ungetc(char)
|
27
27
|
doc = Nokogiri::XML(data)
|
28
28
|
raise doc.errors.first if doc.errors.length > 0
|
29
29
|
doc.to_hash
|
@@ -38,20 +38,20 @@ module ActiveSupport
|
|
38
38
|
end
|
39
39
|
|
40
40
|
module Node #:nodoc:
|
41
|
-
CONTENT_ROOT =
|
41
|
+
CONTENT_ROOT = "__content__"
|
42
42
|
|
43
43
|
# Convert XML document to hash.
|
44
44
|
#
|
45
45
|
# hash::
|
46
46
|
# Hash to merge the converted element into.
|
47
|
-
def to_hash(hash={})
|
47
|
+
def to_hash(hash = {})
|
48
48
|
node_hash = {}
|
49
49
|
|
50
50
|
# Insert node hash into parent hash correctly.
|
51
51
|
case hash[name]
|
52
|
-
|
53
|
-
|
54
|
-
|
52
|
+
when Array then hash[name] << node_hash
|
53
|
+
when Hash then hash[name] = [hash[name], node_hash]
|
54
|
+
when nil then hash[name] = node_hash
|
55
55
|
end
|
56
56
|
|
57
57
|
# Handle child elements
|
@@ -59,7 +59,7 @@ module ActiveSupport
|
|
59
59
|
if c.element?
|
60
60
|
c.to_hash(node_hash)
|
61
61
|
elsif c.text? || c.cdata?
|
62
|
-
node_hash[CONTENT_ROOT] ||=
|
62
|
+
node_hash[CONTENT_ROOT] ||= +""
|
63
63
|
node_hash[CONTENT_ROOT] << c.content
|
64
64
|
end
|
65
65
|
end
|
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
begin
|
2
|
-
require
|
4
|
+
require "nokogiri"
|
3
5
|
rescue LoadError => e
|
4
6
|
$stderr.puts "You don't have nokogiri installed in your application. Please add it to your Gemfile and run bundle install"
|
5
7
|
raise e
|
6
8
|
end
|
7
|
-
require
|
8
|
-
require
|
9
|
+
require "active_support/core_ext/object/blank"
|
10
|
+
require "stringio"
|
9
11
|
|
10
12
|
module ActiveSupport
|
11
13
|
module XmlMini_NokogiriSAX #:nodoc:
|
@@ -14,9 +16,8 @@ module ActiveSupport
|
|
14
16
|
# Class that will build the hash while the XML document
|
15
17
|
# is being parsed using SAX events.
|
16
18
|
class HashBuilder < Nokogiri::XML::SAX::Document
|
17
|
-
|
18
|
-
|
19
|
-
HASH_SIZE_KEY = '__hash_size__'.freeze
|
19
|
+
CONTENT_KEY = "__content__"
|
20
|
+
HASH_SIZE_KEY = "__hash_size__"
|
20
21
|
|
21
22
|
attr_reader :hash
|
22
23
|
|
@@ -38,20 +39,20 @@ module ActiveSupport
|
|
38
39
|
end
|
39
40
|
|
40
41
|
def start_element(name, attrs = [])
|
41
|
-
new_hash = { CONTENT_KEY =>
|
42
|
+
new_hash = { CONTENT_KEY => +"" }.merge!(Hash[attrs])
|
42
43
|
new_hash[HASH_SIZE_KEY] = new_hash.size + 1
|
43
44
|
|
44
45
|
case current_hash[name]
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
when Array then current_hash[name] << new_hash
|
47
|
+
when Hash then current_hash[name] = [current_hash[name], new_hash]
|
48
|
+
when nil then current_hash[name] = new_hash
|
48
49
|
end
|
49
50
|
|
50
51
|
@hash_stack.push(new_hash)
|
51
52
|
end
|
52
53
|
|
53
54
|
def end_element(name)
|
54
|
-
if current_hash.length > current_hash.delete(HASH_SIZE_KEY) && current_hash[CONTENT_KEY].blank? || current_hash[CONTENT_KEY] ==
|
55
|
+
if current_hash.length > current_hash.delete(HASH_SIZE_KEY) && current_hash[CONTENT_KEY].blank? || current_hash[CONTENT_KEY] == ""
|
55
56
|
current_hash.delete(CONTENT_KEY)
|
56
57
|
end
|
57
58
|
@hash_stack.pop
|
@@ -69,15 +70,13 @@ module ActiveSupport
|
|
69
70
|
|
70
71
|
def parse(data)
|
71
72
|
if !data.respond_to?(:read)
|
72
|
-
data = StringIO.new(data ||
|
73
|
+
data = StringIO.new(data || "")
|
73
74
|
end
|
74
75
|
|
75
|
-
|
76
|
-
if char.nil?
|
76
|
+
if data.eof?
|
77
77
|
{}
|
78
78
|
else
|
79
|
-
|
80
|
-
document = self.document_class.new
|
79
|
+
document = document_class.new
|
81
80
|
parser = Nokogiri::XML::SAX::Parser.new(document)
|
82
81
|
parser.parse(data)
|
83
82
|
document.hash
|
@@ -1,12 +1,14 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/kernel/reporting"
|
4
|
+
require "active_support/core_ext/object/blank"
|
5
|
+
require "stringio"
|
4
6
|
|
5
7
|
module ActiveSupport
|
6
8
|
module XmlMini_REXML #:nodoc:
|
7
9
|
extend self
|
8
10
|
|
9
|
-
CONTENT_KEY =
|
11
|
+
CONTENT_KEY = "__content__"
|
10
12
|
|
11
13
|
# Parse an XML Document string or IO into a simple hash.
|
12
14
|
#
|
@@ -17,13 +19,13 @@ module ActiveSupport
|
|
17
19
|
# XML Document string or IO to parse
|
18
20
|
def parse(data)
|
19
21
|
if !data.respond_to?(:read)
|
20
|
-
data = StringIO.new(data ||
|
22
|
+
data = StringIO.new(data || "")
|
21
23
|
end
|
22
24
|
|
23
25
|
if data.eof?
|
24
26
|
{}
|
25
27
|
else
|
26
|
-
|
28
|
+
require_rexml unless defined?(REXML::Document)
|
27
29
|
doc = REXML::Document.new(data)
|
28
30
|
|
29
31
|
if doc.root
|
@@ -36,6 +38,13 @@ module ActiveSupport
|
|
36
38
|
end
|
37
39
|
|
38
40
|
private
|
41
|
+
def require_rexml
|
42
|
+
silence_warnings { require "rexml/document" }
|
43
|
+
rescue LoadError => e
|
44
|
+
$stderr.puts "You don't have rexml installed in your application. Please add it to your Gemfile and run bundle install"
|
45
|
+
raise e
|
46
|
+
end
|
47
|
+
|
39
48
|
# Convert an XML element and merge into the hash
|
40
49
|
#
|
41
50
|
# hash::
|
@@ -55,7 +64,7 @@ module ActiveSupport
|
|
55
64
|
hash = get_attributes(element)
|
56
65
|
|
57
66
|
if element.has_elements?
|
58
|
-
element.each_element {|child| merge_element!(hash, child, depth - 1) }
|
67
|
+
element.each_element { |child| merge_element!(hash, child, depth - 1) }
|
59
68
|
merge_texts!(hash, element) unless empty_content?(element)
|
60
69
|
hash
|
61
70
|
else
|
@@ -74,7 +83,7 @@ module ActiveSupport
|
|
74
83
|
hash
|
75
84
|
else
|
76
85
|
# must use value to prevent double-escaping
|
77
|
-
texts =
|
86
|
+
texts = +""
|
78
87
|
element.texts.each { |t| texts << t.value }
|
79
88
|
merge!(hash, CONTENT_KEY, texts)
|
80
89
|
end
|
@@ -113,7 +122,7 @@ module ActiveSupport
|
|
113
122
|
# XML element to extract attributes from.
|
114
123
|
def get_attributes(element)
|
115
124
|
attributes = {}
|
116
|
-
element.attributes.each { |n,v| attributes[n] = v }
|
125
|
+
element.attributes.each { |n, v| attributes[n] = v }
|
117
126
|
attributes
|
118
127
|
end
|
119
128
|
|
@@ -1,9 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "time"
|
4
|
+
require "base64"
|
5
|
+
require "bigdecimal"
|
6
|
+
require "bigdecimal/util"
|
7
|
+
require "active_support/core_ext/module/delegation"
|
8
|
+
require "active_support/core_ext/string/inflections"
|
9
|
+
require "active_support/core_ext/date_time/calculations"
|
7
10
|
|
8
11
|
module ActiveSupport
|
9
12
|
# = XmlMini
|
@@ -20,11 +23,11 @@ module ActiveSupport
|
|
20
23
|
attr_writer :original_filename, :content_type
|
21
24
|
|
22
25
|
def original_filename
|
23
|
-
@original_filename ||
|
26
|
+
@original_filename || "untitled"
|
24
27
|
end
|
25
28
|
|
26
29
|
def content_type
|
27
|
-
@content_type ||
|
30
|
+
@content_type || "application/octet-stream"
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
@@ -46,10 +49,6 @@ module ActiveSupport
|
|
46
49
|
"Array" => "array",
|
47
50
|
"Hash" => "hash"
|
48
51
|
}
|
49
|
-
|
50
|
-
# No need to map these on Ruby 2.4+
|
51
|
-
TYPE_NAMES["Fixnum"] = "integer" unless Fixnum == Integer
|
52
|
-
TYPE_NAMES["Bignum"] = "integer" unless Bignum == Integer
|
53
52
|
end
|
54
53
|
|
55
54
|
FORMATTING = {
|
@@ -68,10 +67,16 @@ module ActiveSupport
|
|
68
67
|
"datetime" => Proc.new { |time| Time.xmlschema(time).utc rescue ::DateTime.parse(time).utc },
|
69
68
|
"integer" => Proc.new { |integer| integer.to_i },
|
70
69
|
"float" => Proc.new { |float| float.to_f },
|
71
|
-
"decimal" => Proc.new
|
70
|
+
"decimal" => Proc.new do |number|
|
71
|
+
if String === number
|
72
|
+
number.to_d
|
73
|
+
else
|
74
|
+
BigDecimal(number)
|
75
|
+
end
|
76
|
+
end,
|
72
77
|
"boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.to_s.strip) },
|
73
78
|
"string" => Proc.new { |string| string.to_s },
|
74
|
-
"yaml" => Proc.new { |yaml| YAML
|
79
|
+
"yaml" => Proc.new { |yaml| YAML.load(yaml) rescue yaml },
|
75
80
|
"base64Binary" => Proc.new { |bin| ::Base64.decode64(bin) },
|
76
81
|
"binary" => Proc.new { |bin, entity| _parse_binary(bin, entity) },
|
77
82
|
"file" => Proc.new { |file, entity| _parse_file(file, entity) }
|
@@ -86,7 +91,7 @@ module ActiveSupport
|
|
86
91
|
attr_accessor :depth
|
87
92
|
self.depth = 100
|
88
93
|
|
89
|
-
delegate :parse, :
|
94
|
+
delegate :parse, to: :backend
|
90
95
|
|
91
96
|
def backend
|
92
97
|
current_thread_backend || @backend
|
@@ -108,7 +113,7 @@ module ActiveSupport
|
|
108
113
|
|
109
114
|
def to_tag(key, value, options)
|
110
115
|
type_name = options.delete(:type)
|
111
|
-
merged_options = options.merge(:
|
116
|
+
merged_options = options.merge(root: key, skip_instruct: true)
|
112
117
|
|
113
118
|
if value.is_a?(::Method) || value.is_a?(::Proc)
|
114
119
|
if value.arity == 1
|
@@ -126,7 +131,7 @@ module ActiveSupport
|
|
126
131
|
|
127
132
|
key = rename_key(key.to_s, options)
|
128
133
|
|
129
|
-
attributes = options[:skip_types] || type_name.nil? ? {
|
134
|
+
attributes = options[:skip_types] || type_name.nil? ? {} : { type: type_name }
|
130
135
|
attributes[:nil] = true if value.nil?
|
131
136
|
|
132
137
|
encoding = options[:encoding] || DEFAULT_ENCODINGS[type_name]
|
@@ -149,33 +154,30 @@ module ActiveSupport
|
|
149
154
|
key
|
150
155
|
end
|
151
156
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
"#{left}#{middle.tr('_ ', '--')}#{right}"
|
158
|
-
end
|
159
|
-
|
160
|
-
# TODO: Add support for other encodings
|
161
|
-
def _parse_binary(bin, entity) #:nodoc:
|
162
|
-
case entity['encoding']
|
163
|
-
when 'base64'
|
164
|
-
::Base64.decode64(bin)
|
165
|
-
else
|
166
|
-
bin
|
157
|
+
private
|
158
|
+
def _dasherize(key)
|
159
|
+
# $2 must be a non-greedy regex for this to work
|
160
|
+
left, middle, right = /\A(_*)(.*?)(_*)\Z/.match(key.strip)[1, 3]
|
161
|
+
"#{left}#{middle.tr('_ ', '--')}#{right}"
|
167
162
|
end
|
168
|
-
end
|
169
163
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
164
|
+
# TODO: Add support for other encodings
|
165
|
+
def _parse_binary(bin, entity)
|
166
|
+
case entity["encoding"]
|
167
|
+
when "base64"
|
168
|
+
::Base64.decode64(bin)
|
169
|
+
else
|
170
|
+
bin
|
171
|
+
end
|
172
|
+
end
|
177
173
|
|
178
|
-
|
174
|
+
def _parse_file(file, entity)
|
175
|
+
f = StringIO.new(::Base64.decode64(file))
|
176
|
+
f.extend(FileLike)
|
177
|
+
f.original_filename = entity["name"]
|
178
|
+
f.content_type = entity["content_type"]
|
179
|
+
f
|
180
|
+
end
|
179
181
|
|
180
182
|
def current_thread_backend
|
181
183
|
Thread.current[:xml_mini_backend]
|
@@ -195,5 +197,5 @@ module ActiveSupport
|
|
195
197
|
end
|
196
198
|
end
|
197
199
|
|
198
|
-
XmlMini.backend =
|
200
|
+
XmlMini.backend = "REXML"
|
199
201
|
end
|
data/lib/active_support.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#--
|
2
|
-
# Copyright (c) 2005-
|
4
|
+
# Copyright (c) 2005-2020 David Heinemeier Hansson
|
3
5
|
#
|
4
6
|
# Permission is hereby granted, free of charge, to any person obtaining
|
5
7
|
# a copy of this software and associated documentation files (the
|
@@ -21,7 +23,7 @@
|
|
21
23
|
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
24
|
#++
|
23
25
|
|
24
|
-
require
|
26
|
+
require "securerandom"
|
25
27
|
require "active_support/dependencies/autoload"
|
26
28
|
require "active_support/version"
|
27
29
|
require "active_support/logger"
|
@@ -32,15 +34,20 @@ module ActiveSupport
|
|
32
34
|
extend ActiveSupport::Autoload
|
33
35
|
|
34
36
|
autoload :Concern
|
37
|
+
autoload :ActionableError
|
38
|
+
autoload :ConfigurationFile
|
39
|
+
autoload :CurrentAttributes
|
35
40
|
autoload :Dependencies
|
36
41
|
autoload :DescendantsTracker
|
37
42
|
autoload :ExecutionWrapper
|
38
43
|
autoload :Executor
|
39
44
|
autoload :FileUpdateChecker
|
40
45
|
autoload :EventedFileUpdateChecker
|
46
|
+
autoload :ForkTracker
|
41
47
|
autoload :LogSubscriber
|
42
48
|
autoload :Notifications
|
43
49
|
autoload :Reloader
|
50
|
+
autoload :SecureCompareRotator
|
44
51
|
|
45
52
|
eager_autoload do
|
46
53
|
autoload :BacktraceCleaner
|
@@ -50,6 +57,7 @@ module ActiveSupport
|
|
50
57
|
autoload :Callbacks
|
51
58
|
autoload :Configurable
|
52
59
|
autoload :Deprecation
|
60
|
+
autoload :Digest
|
53
61
|
autoload :Gzip
|
54
62
|
autoload :Inflector
|
55
63
|
autoload :JSON
|
@@ -62,6 +70,7 @@ module ActiveSupport
|
|
62
70
|
autoload :OrderedHash
|
63
71
|
autoload :OrderedOptions
|
64
72
|
autoload :StringInquirer
|
73
|
+
autoload :EnvironmentInquirer
|
65
74
|
autoload :TaggedLogging
|
66
75
|
autoload :XmlMini
|
67
76
|
autoload :ArrayInquirer
|
@@ -79,14 +88,6 @@ module ActiveSupport
|
|
79
88
|
|
80
89
|
cattr_accessor :test_order # :nodoc:
|
81
90
|
|
82
|
-
def self.halt_callback_chains_on_return_false
|
83
|
-
Callbacks.halt_and_display_warning_on_return_false
|
84
|
-
end
|
85
|
-
|
86
|
-
def self.halt_callback_chains_on_return_false=(value)
|
87
|
-
Callbacks.halt_and_display_warning_on_return_false = value
|
88
|
-
end
|
89
|
-
|
90
91
|
def self.to_time_preserves_timezone
|
91
92
|
DateAndTime::Compatibility.preserve_timezone
|
92
93
|
end
|
@@ -94,6 +95,14 @@ module ActiveSupport
|
|
94
95
|
def self.to_time_preserves_timezone=(value)
|
95
96
|
DateAndTime::Compatibility.preserve_timezone = value
|
96
97
|
end
|
98
|
+
|
99
|
+
def self.utc_to_local_returns_utc_offset_times
|
100
|
+
DateAndTime::Compatibility.utc_to_local_returns_utc_offset_times
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.utc_to_local_returns_utc_offset_times=(value)
|
104
|
+
DateAndTime::Compatibility.utc_to_local_returns_utc_offset_times = value
|
105
|
+
end
|
97
106
|
end
|
98
107
|
|
99
108
|
autoload :I18n, "active_support/i18n"
|