activesupport 4.2.11.1 → 5.2.4
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 +399 -440
- 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 +97 -88
- 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 +461 -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 +17 -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 +34 -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 +307 -35
- 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 +128 -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 +6 -4
- 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 +54 -24
- 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 "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,7 +13,7 @@ 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
19
|
if data.eof?
|
@@ -20,7 +22,6 @@ module ActiveSupport
|
|
20
22
|
LibXML::XML::Parser.io(data).parse.to_hash
|
21
23
|
end
|
22
24
|
end
|
23
|
-
|
24
25
|
end
|
25
26
|
end
|
26
27
|
|
@@ -33,20 +34,20 @@ module LibXML #:nodoc:
|
|
33
34
|
end
|
34
35
|
|
35
36
|
module Node #:nodoc:
|
36
|
-
CONTENT_ROOT =
|
37
|
+
CONTENT_ROOT = "__content__".freeze
|
37
38
|
|
38
39
|
# Convert XML document to hash.
|
39
40
|
#
|
40
41
|
# hash::
|
41
42
|
# Hash to merge the converted element into.
|
42
|
-
def to_hash(hash={})
|
43
|
+
def to_hash(hash = {})
|
43
44
|
node_hash = {}
|
44
45
|
|
45
46
|
# Insert node hash into parent hash correctly.
|
46
47
|
case hash[name]
|
47
|
-
|
48
|
-
|
49
|
-
|
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
|
50
51
|
end
|
51
52
|
|
52
53
|
# Handle child elements
|
@@ -54,7 +55,7 @@ module LibXML #:nodoc:
|
|
54
55
|
if c.element?
|
55
56
|
c.to_hash(node_hash)
|
56
57
|
elsif c.text? || c.cdata?
|
57
|
-
node_hash[CONTENT_ROOT] ||=
|
58
|
+
node_hash[CONTENT_ROOT] ||= "".dup
|
58
59
|
node_hash[CONTENT_ROOT] << c.content
|
59
60
|
end
|
60
61
|
end
|
@@ -73,5 +74,7 @@ module LibXML #:nodoc:
|
|
73
74
|
end
|
74
75
|
end
|
75
76
|
|
76
|
-
|
77
|
-
|
77
|
+
# :enddoc:
|
78
|
+
|
79
|
+
LibXML::XML::Document.include(LibXML::Conversions::Document)
|
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__".freeze
|
17
|
+
HASH_SIZE_KEY = "__hash_size__".freeze
|
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 => "".dup }
|
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 => "".dup }.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,7 +64,7 @@ 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 data.eof?
|
@@ -71,7 +72,7 @@ module ActiveSupport
|
|
71
72
|
else
|
72
73
|
LibXML::XML::Error.set_handler(&LibXML::XML::Error::QUIET_HANDLER)
|
73
74
|
parser = LibXML::XML::SaxParser.io(data)
|
74
|
-
document =
|
75
|
+
document = document_class.new
|
75
76
|
|
76
77
|
parser.callbacks = document
|
77
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,7 +18,7 @@ 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
24
|
if data.eof?
|
@@ -36,20 +38,20 @@ module ActiveSupport
|
|
36
38
|
end
|
37
39
|
|
38
40
|
module Node #:nodoc:
|
39
|
-
CONTENT_ROOT =
|
41
|
+
CONTENT_ROOT = "__content__".freeze
|
40
42
|
|
41
43
|
# Convert XML document to hash.
|
42
44
|
#
|
43
45
|
# hash::
|
44
46
|
# Hash to merge the converted element into.
|
45
|
-
def to_hash(hash={})
|
47
|
+
def to_hash(hash = {})
|
46
48
|
node_hash = {}
|
47
49
|
|
48
50
|
# Insert node hash into parent hash correctly.
|
49
51
|
case hash[name]
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
53
55
|
end
|
54
56
|
|
55
57
|
# Handle child elements
|
@@ -57,7 +59,7 @@ module ActiveSupport
|
|
57
59
|
if c.element?
|
58
60
|
c.to_hash(node_hash)
|
59
61
|
elsif c.text? || c.cdata?
|
60
|
-
node_hash[CONTENT_ROOT] ||=
|
62
|
+
node_hash[CONTENT_ROOT] ||= "".dup
|
61
63
|
node_hash[CONTENT_ROOT] << c.content
|
62
64
|
end
|
63
65
|
end
|
@@ -75,7 +77,7 @@ module ActiveSupport
|
|
75
77
|
end
|
76
78
|
end
|
77
79
|
|
78
|
-
Nokogiri::XML::Document.
|
79
|
-
Nokogiri::XML::Node.
|
80
|
+
Nokogiri::XML::Document.include(Conversions::Document)
|
81
|
+
Nokogiri::XML::Node.include(Conversions::Node)
|
80
82
|
end
|
81
83
|
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__".freeze
|
20
|
+
HASH_SIZE_KEY = "__hash_size__".freeze
|
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 => "".dup }.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,13 +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 data.eof?
|
76
77
|
{}
|
77
78
|
else
|
78
|
-
document =
|
79
|
+
document = document_class.new
|
79
80
|
parser = Nokogiri::XML::SAX::Parser.new(document)
|
80
81
|
parser.parse(data)
|
81
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__".freeze
|
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
|
-
silence_warnings { require
|
28
|
+
silence_warnings { require "rexml/document" } unless defined?(REXML::Document)
|
27
29
|
doc = REXML::Document.new(data)
|
28
30
|
|
29
31
|
if doc.root
|
@@ -55,7 +57,7 @@ module ActiveSupport
|
|
55
57
|
hash = get_attributes(element)
|
56
58
|
|
57
59
|
if element.has_elements?
|
58
|
-
element.each_element {|child| merge_element!(hash, child, depth - 1) }
|
60
|
+
element.each_element { |child| merge_element!(hash, child, depth - 1) }
|
59
61
|
merge_texts!(hash, element) unless empty_content?(element)
|
60
62
|
hash
|
61
63
|
else
|
@@ -74,7 +76,7 @@ module ActiveSupport
|
|
74
76
|
hash
|
75
77
|
else
|
76
78
|
# must use value to prevent double-escaping
|
77
|
-
texts =
|
79
|
+
texts = "".dup
|
78
80
|
element.texts.each { |t| texts << t.value }
|
79
81
|
merge!(hash, CONTENT_KEY, texts)
|
80
82
|
end
|
@@ -113,7 +115,7 @@ module ActiveSupport
|
|
113
115
|
# XML element to extract attributes from.
|
114
116
|
def get_attributes(element)
|
115
117
|
attributes = {}
|
116
|
-
element.attributes.each { |n,v| attributes[n] = v }
|
118
|
+
element.attributes.each { |n, v| attributes[n] = v }
|
117
119
|
attributes
|
118
120
|
end
|
119
121
|
|
@@ -1,9 +1,11 @@
|
|
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 "active_support/core_ext/module/delegation"
|
7
|
+
require "active_support/core_ext/string/inflections"
|
8
|
+
require "active_support/core_ext/date_time/calculations"
|
7
9
|
|
8
10
|
module ActiveSupport
|
9
11
|
# = XmlMini
|
@@ -20,11 +22,11 @@ module ActiveSupport
|
|
20
22
|
attr_writer :original_filename, :content_type
|
21
23
|
|
22
24
|
def original_filename
|
23
|
-
@original_filename ||
|
25
|
+
@original_filename || "untitled"
|
24
26
|
end
|
25
27
|
|
26
28
|
def content_type
|
27
|
-
@content_type ||
|
29
|
+
@content_type || "application/octet-stream"
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
@@ -73,7 +75,7 @@ module ActiveSupport
|
|
73
75
|
begin
|
74
76
|
BigDecimal(number)
|
75
77
|
rescue ArgumentError
|
76
|
-
BigDecimal(
|
78
|
+
BigDecimal(number.to_f.to_s)
|
77
79
|
end
|
78
80
|
else
|
79
81
|
BigDecimal(number)
|
@@ -81,7 +83,7 @@ module ActiveSupport
|
|
81
83
|
end,
|
82
84
|
"boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.to_s.strip) },
|
83
85
|
"string" => Proc.new { |string| string.to_s },
|
84
|
-
"yaml" => Proc.new { |yaml| YAML
|
86
|
+
"yaml" => Proc.new { |yaml| YAML.load(yaml) rescue yaml },
|
85
87
|
"base64Binary" => Proc.new { |bin| ::Base64.decode64(bin) },
|
86
88
|
"binary" => Proc.new { |bin, entity| _parse_binary(bin, entity) },
|
87
89
|
"file" => Proc.new { |file, entity| _parse_file(file, entity) }
|
@@ -96,7 +98,7 @@ module ActiveSupport
|
|
96
98
|
attr_accessor :depth
|
97
99
|
self.depth = 100
|
98
100
|
|
99
|
-
delegate :parse, :
|
101
|
+
delegate :parse, to: :backend
|
100
102
|
|
101
103
|
def backend
|
102
104
|
current_thread_backend || @backend
|
@@ -118,7 +120,7 @@ module ActiveSupport
|
|
118
120
|
|
119
121
|
def to_tag(key, value, options)
|
120
122
|
type_name = options.delete(:type)
|
121
|
-
merged_options = options.merge(:
|
123
|
+
merged_options = options.merge(root: key, skip_instruct: true)
|
122
124
|
|
123
125
|
if value.is_a?(::Method) || value.is_a?(::Proc)
|
124
126
|
if value.arity == 1
|
@@ -136,7 +138,7 @@ module ActiveSupport
|
|
136
138
|
|
137
139
|
key = rename_key(key.to_s, options)
|
138
140
|
|
139
|
-
attributes = options[:skip_types] || type_name.nil? ? {
|
141
|
+
attributes = options[:skip_types] || type_name.nil? ? {} : { type: type_name }
|
140
142
|
attributes[:nil] = true if value.nil?
|
141
143
|
|
142
144
|
encoding = options[:encoding] || DEFAULT_ENCODINGS[type_name]
|
@@ -159,33 +161,31 @@ module ActiveSupport
|
|
159
161
|
key
|
160
162
|
end
|
161
163
|
|
162
|
-
|
163
|
-
|
164
|
-
def _dasherize(key)
|
165
|
-
# $2 must be a non-greedy regex for this to work
|
166
|
-
left, middle, right = /\A(_*)(.*?)(_*)\Z/.match(key.strip)[1,3]
|
167
|
-
"#{left}#{middle.tr('_ ', '--')}#{right}"
|
168
|
-
end
|
164
|
+
private
|
169
165
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
::Base64.decode64(bin)
|
175
|
-
else
|
176
|
-
bin
|
166
|
+
def _dasherize(key)
|
167
|
+
# $2 must be a non-greedy regex for this to work
|
168
|
+
left, middle, right = /\A(_*)(.*?)(_*)\Z/.match(key.strip)[1, 3]
|
169
|
+
"#{left}#{middle.tr('_ ', '--')}#{right}"
|
177
170
|
end
|
178
|
-
end
|
179
171
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
172
|
+
# TODO: Add support for other encodings
|
173
|
+
def _parse_binary(bin, entity)
|
174
|
+
case entity["encoding"]
|
175
|
+
when "base64"
|
176
|
+
::Base64.decode64(bin)
|
177
|
+
else
|
178
|
+
bin
|
179
|
+
end
|
180
|
+
end
|
187
181
|
|
188
|
-
|
182
|
+
def _parse_file(file, entity)
|
183
|
+
f = StringIO.new(::Base64.decode64(file))
|
184
|
+
f.extend(FileLike)
|
185
|
+
f.original_filename = entity["name"]
|
186
|
+
f.content_type = entity["content_type"]
|
187
|
+
f
|
188
|
+
end
|
189
189
|
|
190
190
|
def current_thread_backend
|
191
191
|
Thread.current[:xml_mini_backend]
|
@@ -205,5 +205,5 @@ module ActiveSupport
|
|
205
205
|
end
|
206
206
|
end
|
207
207
|
|
208
|
-
XmlMini.backend =
|
208
|
+
XmlMini.backend = "REXML"
|
209
209
|
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-2018 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,11 +34,16 @@ module ActiveSupport
|
|
32
34
|
extend ActiveSupport::Autoload
|
33
35
|
|
34
36
|
autoload :Concern
|
37
|
+
autoload :CurrentAttributes
|
35
38
|
autoload :Dependencies
|
36
39
|
autoload :DescendantsTracker
|
40
|
+
autoload :ExecutionWrapper
|
41
|
+
autoload :Executor
|
37
42
|
autoload :FileUpdateChecker
|
43
|
+
autoload :EventedFileUpdateChecker
|
38
44
|
autoload :LogSubscriber
|
39
45
|
autoload :Notifications
|
46
|
+
autoload :Reloader
|
40
47
|
|
41
48
|
eager_autoload do
|
42
49
|
autoload :BacktraceCleaner
|
@@ -46,6 +53,7 @@ module ActiveSupport
|
|
46
53
|
autoload :Callbacks
|
47
54
|
autoload :Configurable
|
48
55
|
autoload :Deprecation
|
56
|
+
autoload :Digest
|
49
57
|
autoload :Gzip
|
50
58
|
autoload :Inflector
|
51
59
|
autoload :JSON
|
@@ -60,6 +68,7 @@ module ActiveSupport
|
|
60
68
|
autoload :StringInquirer
|
61
69
|
autoload :TaggedLogging
|
62
70
|
autoload :XmlMini
|
71
|
+
autoload :ArrayInquirer
|
63
72
|
end
|
64
73
|
|
65
74
|
autoload :Rescuable
|
@@ -72,15 +81,7 @@ module ActiveSupport
|
|
72
81
|
NumberHelper.eager_load!
|
73
82
|
end
|
74
83
|
|
75
|
-
|
76
|
-
|
77
|
-
def self.test_order=(new_order) # :nodoc:
|
78
|
-
@@test_order = new_order
|
79
|
-
end
|
80
|
-
|
81
|
-
def self.test_order # :nodoc:
|
82
|
-
@@test_order
|
83
|
-
end
|
84
|
+
cattr_accessor :test_order # :nodoc:
|
84
85
|
|
85
86
|
def self.to_time_preserves_timezone
|
86
87
|
DateAndTime::Compatibility.preserve_timezone
|