activesupport 4.2.11.1 → 6.0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of activesupport might be problematic. Click here for more details.

Files changed (263) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +399 -411
  3. data/MIT-LICENSE +2 -2
  4. data/README.rdoc +7 -7
  5. data/lib/active_support/actionable_error.rb +48 -0
  6. data/lib/active_support/all.rb +5 -3
  7. data/lib/active_support/array_inquirer.rb +48 -0
  8. data/lib/active_support/backtrace_cleaner.rb +34 -6
  9. data/lib/active_support/benchmarkable.rb +6 -4
  10. data/lib/active_support/builder.rb +3 -1
  11. data/lib/active_support/cache/file_store.rb +58 -53
  12. data/lib/active_support/cache/mem_cache_store.rb +95 -91
  13. data/lib/active_support/cache/memory_store.rb +39 -36
  14. data/lib/active_support/cache/null_store.rb +11 -7
  15. data/lib/active_support/cache/redis_cache_store.rb +493 -0
  16. data/lib/active_support/cache/strategy/local_cache.rb +75 -42
  17. data/lib/active_support/cache/strategy/local_cache_middleware.rb +10 -9
  18. data/lib/active_support/cache.rb +331 -217
  19. data/lib/active_support/callbacks.rb +650 -592
  20. data/lib/active_support/concern.rb +35 -6
  21. data/lib/active_support/concurrency/load_interlock_aware_monitor.rb +35 -0
  22. data/lib/active_support/concurrency/share_lock.rb +226 -0
  23. data/lib/active_support/configurable.rb +13 -14
  24. data/lib/active_support/core_ext/array/access.rb +41 -1
  25. data/lib/active_support/core_ext/array/conversions.rb +24 -20
  26. data/lib/active_support/core_ext/array/extract.rb +21 -0
  27. data/lib/active_support/core_ext/array/extract_options.rb +2 -0
  28. data/lib/active_support/core_ext/array/grouping.rb +11 -18
  29. data/lib/active_support/core_ext/array/inquiry.rb +19 -0
  30. data/lib/active_support/core_ext/array/prepend_and_append.rb +4 -6
  31. data/lib/active_support/core_ext/array/wrap.rb +7 -4
  32. data/lib/active_support/core_ext/array.rb +9 -6
  33. data/lib/active_support/core_ext/benchmark.rb +3 -1
  34. data/lib/active_support/core_ext/big_decimal/conversions.rb +10 -12
  35. data/lib/active_support/core_ext/big_decimal.rb +3 -1
  36. data/lib/active_support/core_ext/class/attribute.rb +45 -31
  37. data/lib/active_support/core_ext/class/attribute_accessors.rb +3 -1
  38. data/lib/active_support/core_ext/class/subclasses.rb +20 -6
  39. data/lib/active_support/core_ext/class.rb +4 -3
  40. data/lib/active_support/core_ext/date/acts_like.rb +3 -1
  41. data/lib/active_support/core_ext/date/blank.rb +14 -0
  42. data/lib/active_support/core_ext/date/calculations.rb +17 -14
  43. data/lib/active_support/core_ext/date/conversions.rb +25 -23
  44. data/lib/active_support/core_ext/date/zones.rb +4 -2
  45. data/lib/active_support/core_ext/date.rb +6 -4
  46. data/lib/active_support/core_ext/date_and_time/calculations.rb +154 -65
  47. data/lib/active_support/core_ext/date_and_time/compatibility.rb +4 -3
  48. data/lib/active_support/core_ext/date_and_time/zones.rb +12 -13
  49. data/lib/active_support/core_ext/date_time/acts_like.rb +4 -2
  50. data/lib/active_support/core_ext/date_time/blank.rb +14 -0
  51. data/lib/active_support/core_ext/date_time/calculations.rb +37 -19
  52. data/lib/active_support/core_ext/date_time/compatibility.rb +8 -6
  53. data/lib/active_support/core_ext/date_time/conversions.rb +16 -13
  54. data/lib/active_support/core_ext/date_time.rb +7 -5
  55. data/lib/active_support/core_ext/digest/uuid.rb +7 -5
  56. data/lib/active_support/core_ext/digest.rb +3 -0
  57. data/lib/active_support/core_ext/enumerable.rb +114 -22
  58. data/lib/active_support/core_ext/file/atomic.rb +38 -31
  59. data/lib/active_support/core_ext/file.rb +3 -1
  60. data/lib/active_support/core_ext/hash/compact.rb +4 -23
  61. data/lib/active_support/core_ext/hash/conversions.rb +62 -41
  62. data/lib/active_support/core_ext/hash/deep_merge.rb +9 -13
  63. data/lib/active_support/core_ext/hash/deep_transform_values.rb +46 -0
  64. data/lib/active_support/core_ext/hash/except.rb +12 -9
  65. data/lib/active_support/core_ext/hash/indifferent_access.rb +4 -3
  66. data/lib/active_support/core_ext/hash/keys.rb +19 -42
  67. data/lib/active_support/core_ext/hash/reverse_merge.rb +5 -2
  68. data/lib/active_support/core_ext/hash/slice.rb +5 -27
  69. data/lib/active_support/core_ext/hash/transform_values.rb +4 -22
  70. data/lib/active_support/core_ext/hash.rb +10 -9
  71. data/lib/active_support/core_ext/integer/inflections.rb +3 -1
  72. data/lib/active_support/core_ext/integer/multiple.rb +3 -1
  73. data/lib/active_support/core_ext/integer/time.rb +11 -18
  74. data/lib/active_support/core_ext/integer.rb +5 -3
  75. data/lib/active_support/core_ext/kernel/concern.rb +5 -1
  76. data/lib/active_support/core_ext/kernel/reporting.rb +4 -84
  77. data/lib/active_support/core_ext/kernel/singleton_class.rb +2 -0
  78. data/lib/active_support/core_ext/kernel.rb +5 -5
  79. data/lib/active_support/core_ext/load_error.rb +3 -22
  80. data/lib/active_support/core_ext/marshal.rb +8 -8
  81. data/lib/active_support/core_ext/module/aliasing.rb +6 -44
  82. data/lib/active_support/core_ext/module/anonymous.rb +12 -1
  83. data/lib/active_support/core_ext/module/attr_internal.rb +8 -9
  84. data/lib/active_support/core_ext/module/attribute_accessors.rb +46 -46
  85. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +144 -0
  86. data/lib/active_support/core_ext/module/concerning.rb +11 -12
  87. data/lib/active_support/core_ext/module/delegation.rb +133 -30
  88. data/lib/active_support/core_ext/module/deprecation.rb +4 -2
  89. data/lib/active_support/core_ext/module/introspection.rb +44 -19
  90. data/lib/active_support/core_ext/module/reachable.rb +5 -7
  91. data/lib/active_support/core_ext/module/redefine_method.rb +40 -0
  92. data/lib/active_support/core_ext/module/remove_method.rb +8 -3
  93. data/lib/active_support/core_ext/module.rb +13 -11
  94. data/lib/active_support/core_ext/name_error.rb +22 -2
  95. data/lib/active_support/core_ext/numeric/bytes.rb +22 -0
  96. data/lib/active_support/core_ext/numeric/conversions.rb +129 -136
  97. data/lib/active_support/core_ext/numeric/inquiry.rb +5 -0
  98. data/lib/active_support/core_ext/numeric/time.rb +35 -23
  99. data/lib/active_support/core_ext/numeric.rb +5 -3
  100. data/lib/active_support/core_ext/object/acts_like.rb +12 -1
  101. data/lib/active_support/core_ext/object/blank.rb +27 -3
  102. data/lib/active_support/core_ext/object/conversions.rb +6 -4
  103. data/lib/active_support/core_ext/object/deep_dup.rb +13 -4
  104. data/lib/active_support/core_ext/object/duplicable.rb +13 -93
  105. data/lib/active_support/core_ext/object/inclusion.rb +5 -3
  106. data/lib/active_support/core_ext/object/instance_variables.rb +3 -1
  107. data/lib/active_support/core_ext/object/json.rb +51 -20
  108. data/lib/active_support/core_ext/object/to_param.rb +3 -1
  109. data/lib/active_support/core_ext/object/to_query.rb +10 -5
  110. data/lib/active_support/core_ext/object/try.rb +81 -23
  111. data/lib/active_support/core_ext/object/with_options.rb +16 -3
  112. data/lib/active_support/core_ext/object.rb +14 -13
  113. data/lib/active_support/core_ext/range/compare_range.rb +76 -0
  114. data/lib/active_support/core_ext/range/conversions.rb +37 -15
  115. data/lib/active_support/core_ext/range/each.rb +18 -17
  116. data/lib/active_support/core_ext/range/include_range.rb +7 -21
  117. data/lib/active_support/core_ext/range/include_time_with_zone.rb +23 -0
  118. data/lib/active_support/core_ext/range/overlaps.rb +2 -0
  119. data/lib/active_support/core_ext/range.rb +7 -4
  120. data/lib/active_support/core_ext/regexp.rb +2 -0
  121. data/lib/active_support/core_ext/securerandom.rb +45 -0
  122. data/lib/active_support/core_ext/string/access.rb +16 -6
  123. data/lib/active_support/core_ext/string/behavior.rb +3 -1
  124. data/lib/active_support/core_ext/string/conversions.rb +7 -4
  125. data/lib/active_support/core_ext/string/exclude.rb +2 -0
  126. data/lib/active_support/core_ext/string/filters.rb +48 -6
  127. data/lib/active_support/core_ext/string/indent.rb +6 -4
  128. data/lib/active_support/core_ext/string/inflections.rb +66 -24
  129. data/lib/active_support/core_ext/string/inquiry.rb +3 -1
  130. data/lib/active_support/core_ext/string/multibyte.rb +16 -7
  131. data/lib/active_support/core_ext/string/output_safety.rb +93 -40
  132. data/lib/active_support/core_ext/string/starts_ends_with.rb +2 -0
  133. data/lib/active_support/core_ext/string/strip.rb +6 -5
  134. data/lib/active_support/core_ext/string/zones.rb +4 -2
  135. data/lib/active_support/core_ext/string.rb +15 -13
  136. data/lib/active_support/core_ext/time/acts_like.rb +3 -1
  137. data/lib/active_support/core_ext/time/calculations.rb +115 -52
  138. data/lib/active_support/core_ext/time/compatibility.rb +4 -2
  139. data/lib/active_support/core_ext/time/conversions.rb +20 -13
  140. data/lib/active_support/core_ext/time/zones.rb +41 -7
  141. data/lib/active_support/core_ext/time.rb +7 -6
  142. data/lib/active_support/core_ext/uri.rb +6 -7
  143. data/lib/active_support/core_ext.rb +3 -1
  144. data/lib/active_support/current_attributes.rb +203 -0
  145. data/lib/active_support/dependencies/autoload.rb +2 -0
  146. data/lib/active_support/dependencies/interlock.rb +57 -0
  147. data/lib/active_support/dependencies/zeitwerk_integration.rb +117 -0
  148. data/lib/active_support/dependencies.rb +208 -166
  149. data/lib/active_support/deprecation/behaviors.rb +44 -11
  150. data/lib/active_support/deprecation/constant_accessor.rb +52 -0
  151. data/lib/active_support/deprecation/instance_delegator.rb +17 -2
  152. data/lib/active_support/deprecation/method_wrappers.rb +61 -21
  153. data/lib/active_support/deprecation/proxy_wrappers.rb +81 -30
  154. data/lib/active_support/deprecation/reporting.rb +32 -12
  155. data/lib/active_support/deprecation.rb +12 -9
  156. data/lib/active_support/descendants_tracker.rb +57 -9
  157. data/lib/active_support/digest.rb +20 -0
  158. data/lib/active_support/duration/iso8601_parser.rb +123 -0
  159. data/lib/active_support/duration/iso8601_serializer.rb +53 -0
  160. data/lib/active_support/duration.rb +315 -40
  161. data/lib/active_support/encrypted_configuration.rb +45 -0
  162. data/lib/active_support/encrypted_file.rb +100 -0
  163. data/lib/active_support/evented_file_update_checker.rb +234 -0
  164. data/lib/active_support/execution_wrapper.rb +129 -0
  165. data/lib/active_support/executor.rb +8 -0
  166. data/lib/active_support/file_update_checker.rb +62 -37
  167. data/lib/active_support/gem_version.rb +6 -4
  168. data/lib/active_support/gzip.rb +7 -5
  169. data/lib/active_support/hash_with_indifferent_access.rb +129 -30
  170. data/lib/active_support/i18n.rb +9 -6
  171. data/lib/active_support/i18n_railtie.rb +50 -14
  172. data/lib/active_support/inflections.rb +13 -11
  173. data/lib/active_support/inflector/inflections.rb +58 -13
  174. data/lib/active_support/inflector/methods.rb +159 -145
  175. data/lib/active_support/inflector/transliterate.rb +84 -34
  176. data/lib/active_support/inflector.rb +7 -5
  177. data/lib/active_support/json/decoding.rb +32 -30
  178. data/lib/active_support/json/encoding.rb +17 -60
  179. data/lib/active_support/json.rb +4 -2
  180. data/lib/active_support/key_generator.rb +11 -43
  181. data/lib/active_support/lazy_load_hooks.rb +53 -20
  182. data/lib/active_support/locale/en.rb +33 -0
  183. data/lib/active_support/locale/en.yml +2 -0
  184. data/lib/active_support/log_subscriber/test_helper.rb +14 -12
  185. data/lib/active_support/log_subscriber.rb +44 -19
  186. data/lib/active_support/logger.rb +9 -23
  187. data/lib/active_support/logger_silence.rb +32 -14
  188. data/lib/active_support/logger_thread_safe_level.rb +32 -8
  189. data/lib/active_support/message_encryptor.rb +166 -53
  190. data/lib/active_support/message_verifier.rb +149 -16
  191. data/lib/active_support/messages/metadata.rb +72 -0
  192. data/lib/active_support/messages/rotation_configuration.rb +22 -0
  193. data/lib/active_support/messages/rotator.rb +56 -0
  194. data/lib/active_support/multibyte/chars.rb +56 -63
  195. data/lib/active_support/multibyte/unicode.rb +56 -290
  196. data/lib/active_support/multibyte.rb +4 -2
  197. data/lib/active_support/notifications/fanout.rb +109 -22
  198. data/lib/active_support/notifications/instrumenter.rb +107 -16
  199. data/lib/active_support/notifications.rb +51 -10
  200. data/lib/active_support/number_helper/number_converter.rb +16 -15
  201. data/lib/active_support/number_helper/number_to_currency_converter.rb +14 -15
  202. data/lib/active_support/number_helper/number_to_delimited_converter.rb +11 -4
  203. data/lib/active_support/number_helper/number_to_human_converter.rb +13 -10
  204. data/lib/active_support/number_helper/number_to_human_size_converter.rb +11 -9
  205. data/lib/active_support/number_helper/number_to_percentage_converter.rb +5 -1
  206. data/lib/active_support/number_helper/number_to_phone_converter.rb +15 -5
  207. data/lib/active_support/number_helper/number_to_rounded_converter.rb +25 -57
  208. data/lib/active_support/number_helper/rounding_helper.rb +66 -0
  209. data/lib/active_support/number_helper.rb +105 -68
  210. data/lib/active_support/option_merger.rb +24 -4
  211. data/lib/active_support/ordered_hash.rb +7 -5
  212. data/lib/active_support/ordered_options.rb +27 -5
  213. data/lib/active_support/parameter_filter.rb +128 -0
  214. data/lib/active_support/per_thread_registry.rb +9 -4
  215. data/lib/active_support/proxy_object.rb +2 -0
  216. data/lib/active_support/rails.rb +10 -8
  217. data/lib/active_support/railtie.rb +43 -9
  218. data/lib/active_support/reloader.rb +130 -0
  219. data/lib/active_support/rescuable.rb +108 -53
  220. data/lib/active_support/security_utils.rb +15 -11
  221. data/lib/active_support/string_inquirer.rb +11 -4
  222. data/lib/active_support/subscriber.rb +74 -30
  223. data/lib/active_support/tagged_logging.rb +25 -13
  224. data/lib/active_support/test_case.rb +107 -44
  225. data/lib/active_support/testing/assertions.rb +151 -20
  226. data/lib/active_support/testing/autorun.rb +4 -2
  227. data/lib/active_support/testing/constant_lookup.rb +2 -1
  228. data/lib/active_support/testing/declarative.rb +3 -1
  229. data/lib/active_support/testing/deprecation.rb +13 -10
  230. data/lib/active_support/testing/file_fixtures.rb +38 -0
  231. data/lib/active_support/testing/isolation.rb +35 -26
  232. data/lib/active_support/testing/method_call_assertions.rb +70 -0
  233. data/lib/active_support/testing/parallelization.rb +134 -0
  234. data/lib/active_support/testing/setup_and_teardown.rb +13 -8
  235. data/lib/active_support/testing/stream.rb +43 -0
  236. data/lib/active_support/testing/tagged_logging.rb +3 -1
  237. data/lib/active_support/testing/time_helpers.rb +84 -20
  238. data/lib/active_support/time.rb +14 -12
  239. data/lib/active_support/time_with_zone.rb +179 -39
  240. data/lib/active_support/values/time_zone.rb +203 -63
  241. data/lib/active_support/version.rb +3 -1
  242. data/lib/active_support/xml_mini/jdom.rb +116 -115
  243. data/lib/active_support/xml_mini/libxml.rb +16 -13
  244. data/lib/active_support/xml_mini/libxmlsax.rb +15 -14
  245. data/lib/active_support/xml_mini/nokogiri.rb +14 -12
  246. data/lib/active_support/xml_mini/nokogirisax.rb +14 -13
  247. data/lib/active_support/xml_mini/rexml.rb +11 -9
  248. data/lib/active_support/xml_mini.rb +38 -46
  249. data/lib/active_support.rb +13 -11
  250. metadata +84 -26
  251. data/lib/active_support/concurrency/latch.rb +0 -27
  252. data/lib/active_support/core_ext/big_decimal/yaml_conversions.rb +0 -16
  253. data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -45
  254. data/lib/active_support/core_ext/date_time/zones.rb +0 -6
  255. data/lib/active_support/core_ext/kernel/agnostics.rb +0 -11
  256. data/lib/active_support/core_ext/kernel/debugger.rb +0 -10
  257. data/lib/active_support/core_ext/module/method_transplanting.rb +0 -13
  258. data/lib/active_support/core_ext/module/qualified_const.rb +0 -52
  259. data/lib/active_support/core_ext/object/itself.rb +0 -15
  260. data/lib/active_support/core_ext/struct.rb +0 -6
  261. data/lib/active_support/core_ext/thread.rb +0 -86
  262. data/lib/active_support/core_ext/time/marshal.rb +0 -30
  263. data/lib/active_support/values/unicode_tables.dat +0 -0
@@ -1,9 +1,11 @@
1
- raise "JRuby is required to use the JDOM backend for XmlMini" unless RUBY_PLATFORM =~ /java/
1
+ # frozen_string_literal: true
2
2
 
3
- require 'jruby'
3
+ raise "JRuby is required to use the JDOM backend for XmlMini" unless RUBY_PLATFORM.include?("java")
4
+
5
+ require "jruby"
4
6
  include Java
5
7
 
6
- require 'active_support/core_ext/object/blank'
8
+ require "active_support/core_ext/object/blank"
7
9
 
8
10
  java_import javax.xml.parsers.DocumentBuilder unless defined? DocumentBuilder
9
11
  java_import javax.xml.parsers.DocumentBuilderFactory unless defined? DocumentBuilderFactory
@@ -16,7 +18,7 @@ module ActiveSupport
16
18
  module XmlMini_JDOM #:nodoc:
17
19
  extend self
18
20
 
19
- CONTENT_KEY = '__content__'.freeze
21
+ CONTENT_KEY = "__content__"
20
22
 
21
23
  NODE_TYPE_NAMES = %w{ATTRIBUTE_NODE CDATA_SECTION_NODE COMMENT_NODE DOCUMENT_FRAGMENT_NODE
22
24
  DOCUMENT_NODE DOCUMENT_TYPE_NODE ELEMENT_NODE ENTITY_NODE ENTITY_REFERENCE_NODE NOTATION_NODE
@@ -38,7 +40,7 @@ module ActiveSupport
38
40
  else
39
41
  @dbf = DocumentBuilderFactory.new_instance
40
42
  # secure processing of java xml
41
- # http://www.ibm.com/developerworks/xml/library/x-tipcfsx/index.html
43
+ # https://archive.is/9xcQQ
42
44
  @dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)
43
45
  @dbf.setFeature("http://xml.org/sax/features/external-general-entities", false)
44
46
  @dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false)
@@ -46,136 +48,135 @@ module ActiveSupport
46
48
  xml_string_reader = StringReader.new(data)
47
49
  xml_input_source = InputSource.new(xml_string_reader)
48
50
  doc = @dbf.new_document_builder.parse(xml_input_source)
49
- merge_element!({CONTENT_KEY => ''}, doc.document_element, XmlMini.depth)
51
+ merge_element!({ CONTENT_KEY => "" }, doc.document_element, XmlMini.depth)
50
52
  end
51
53
  end
52
54
 
53
55
  private
56
+ # Convert an XML element and merge into the hash
57
+ #
58
+ # hash::
59
+ # Hash to merge the converted element into.
60
+ # element::
61
+ # XML element to merge into hash
62
+ def merge_element!(hash, element, depth)
63
+ raise "Document too deep!" if depth == 0
64
+ delete_empty(hash)
65
+ merge!(hash, element.tag_name, collapse(element, depth))
66
+ end
54
67
 
55
- # Convert an XML element and merge into the hash
56
- #
57
- # hash::
58
- # Hash to merge the converted element into.
59
- # element::
60
- # XML element to merge into hash
61
- def merge_element!(hash, element, depth)
62
- raise 'Document too deep!' if depth == 0
63
- delete_empty(hash)
64
- merge!(hash, element.tag_name, collapse(element, depth))
65
- end
66
-
67
- def delete_empty(hash)
68
- hash.delete(CONTENT_KEY) if hash[CONTENT_KEY] == ''
69
- end
70
-
71
- # Actually converts an XML document element into a data structure.
72
- #
73
- # element::
74
- # The document element to be collapsed.
75
- def collapse(element, depth)
76
- hash = get_attributes(element)
68
+ def delete_empty(hash)
69
+ hash.delete(CONTENT_KEY) if hash[CONTENT_KEY] == ""
70
+ end
77
71
 
78
- child_nodes = element.child_nodes
79
- if child_nodes.length > 0
80
- (0...child_nodes.length).each do |i|
81
- child = child_nodes.item(i)
82
- merge_element!(hash, child, depth - 1) unless child.node_type == Node.TEXT_NODE
72
+ # Actually converts an XML document element into a data structure.
73
+ #
74
+ # element::
75
+ # The document element to be collapsed.
76
+ def collapse(element, depth)
77
+ hash = get_attributes(element)
78
+
79
+ child_nodes = element.child_nodes
80
+ if child_nodes.length > 0
81
+ (0...child_nodes.length).each do |i|
82
+ child = child_nodes.item(i)
83
+ merge_element!(hash, child, depth - 1) unless child.node_type == Node.TEXT_NODE
84
+ end
85
+ merge_texts!(hash, element) unless empty_content?(element)
86
+ hash
87
+ else
88
+ merge_texts!(hash, element)
83
89
  end
84
- merge_texts!(hash, element) unless empty_content?(element)
85
- hash
86
- else
87
- merge_texts!(hash, element)
88
90
  end
89
- end
90
91
 
91
- # Merge all the texts of an element into the hash
92
- #
93
- # hash::
94
- # Hash to add the converted element to.
95
- # element::
96
- # XML element whose texts are to me merged into the hash
97
- def merge_texts!(hash, element)
98
- delete_empty(hash)
99
- text_children = texts(element)
100
- if text_children.join.empty?
101
- hash
102
- else
103
- # must use value to prevent double-escaping
104
- merge!(hash, CONTENT_KEY, text_children.join)
92
+ # Merge all the texts of an element into the hash
93
+ #
94
+ # hash::
95
+ # Hash to add the converted element to.
96
+ # element::
97
+ # XML element whose texts are to me merged into the hash
98
+ def merge_texts!(hash, element)
99
+ delete_empty(hash)
100
+ text_children = texts(element)
101
+ if text_children.join.empty?
102
+ hash
103
+ else
104
+ # must use value to prevent double-escaping
105
+ merge!(hash, CONTENT_KEY, text_children.join)
106
+ end
105
107
  end
106
- end
107
108
 
108
- # Adds a new key/value pair to an existing Hash. If the key to be added
109
- # already exists and the existing value associated with key is not
110
- # an Array, it will be wrapped in an Array. Then the new value is
111
- # appended to that Array.
112
- #
113
- # hash::
114
- # Hash to add key/value pair to.
115
- # key::
116
- # Key to be added.
117
- # value::
118
- # Value to be associated with key.
119
- def merge!(hash, key, value)
120
- if hash.has_key?(key)
121
- if hash[key].instance_of?(Array)
122
- hash[key] << value
109
+ # Adds a new key/value pair to an existing Hash. If the key to be added
110
+ # already exists and the existing value associated with key is not
111
+ # an Array, it will be wrapped in an Array. Then the new value is
112
+ # appended to that Array.
113
+ #
114
+ # hash::
115
+ # Hash to add key/value pair to.
116
+ # key::
117
+ # Key to be added.
118
+ # value::
119
+ # Value to be associated with key.
120
+ def merge!(hash, key, value)
121
+ if hash.has_key?(key)
122
+ if hash[key].instance_of?(Array)
123
+ hash[key] << value
124
+ else
125
+ hash[key] = [hash[key], value]
126
+ end
127
+ elsif value.instance_of?(Array)
128
+ hash[key] = [value]
123
129
  else
124
- hash[key] = [hash[key], value]
130
+ hash[key] = value
125
131
  end
126
- elsif value.instance_of?(Array)
127
- hash[key] = [value]
128
- else
129
- hash[key] = value
132
+ hash
130
133
  end
131
- hash
132
- end
133
134
 
134
- # Converts the attributes array of an XML element into a hash.
135
- # Returns an empty Hash if node has no attributes.
136
- #
137
- # element::
138
- # XML element to extract attributes from.
139
- def get_attributes(element)
140
- attribute_hash = {}
141
- attributes = element.attributes
142
- (0...attributes.length).each do |i|
143
- attribute_hash[CONTENT_KEY] ||= ''
144
- attribute_hash[attributes.item(i).name] = attributes.item(i).value
145
- end
146
- attribute_hash
147
- end
135
+ # Converts the attributes array of an XML element into a hash.
136
+ # Returns an empty Hash if node has no attributes.
137
+ #
138
+ # element::
139
+ # XML element to extract attributes from.
140
+ def get_attributes(element)
141
+ attribute_hash = {}
142
+ attributes = element.attributes
143
+ (0...attributes.length).each do |i|
144
+ attribute_hash[CONTENT_KEY] ||= ""
145
+ attribute_hash[attributes.item(i).name] = attributes.item(i).value
146
+ end
147
+ attribute_hash
148
+ end
148
149
 
149
- # Determines if a document element has text content
150
- #
151
- # element::
152
- # XML element to be checked.
153
- def texts(element)
154
- texts = []
155
- child_nodes = element.child_nodes
156
- (0...child_nodes.length).each do |i|
157
- item = child_nodes.item(i)
158
- if item.node_type == Node.TEXT_NODE
159
- texts << item.get_data
150
+ # Determines if a document element has text content
151
+ #
152
+ # element::
153
+ # XML element to be checked.
154
+ def texts(element)
155
+ texts = []
156
+ child_nodes = element.child_nodes
157
+ (0...child_nodes.length).each do |i|
158
+ item = child_nodes.item(i)
159
+ if item.node_type == Node.TEXT_NODE
160
+ texts << item.get_data
161
+ end
160
162
  end
163
+ texts
161
164
  end
162
- texts
163
- end
164
165
 
165
- # Determines if a document element has text content
166
- #
167
- # element::
168
- # XML element to be checked.
169
- def empty_content?(element)
170
- text = ''
171
- child_nodes = element.child_nodes
172
- (0...child_nodes.length).each do |i|
173
- item = child_nodes.item(i)
174
- if item.node_type == Node.TEXT_NODE
175
- text << item.get_data.strip
166
+ # Determines if a document element has text content
167
+ #
168
+ # element::
169
+ # XML element to be checked.
170
+ def empty_content?(element)
171
+ text = +""
172
+ child_nodes = element.child_nodes
173
+ (0...child_nodes.length).each do |i|
174
+ item = child_nodes.item(i)
175
+ if item.node_type == Node.TEXT_NODE
176
+ text << item.get_data.strip
177
+ end
176
178
  end
179
+ text.strip.length == 0
177
180
  end
178
- text.strip.length == 0
179
- end
180
181
  end
181
182
  end
@@ -1,6 +1,8 @@
1
- require 'libxml'
2
- require 'active_support/core_ext/object/blank'
3
- require 'stringio'
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 = '__content__'.freeze
37
+ CONTENT_ROOT = "__content__"
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
- when Array then hash[name] << node_hash
48
- when Hash then hash[name] = [hash[name], node_hash]
49
- when nil then hash[name] = node_hash
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] ||= +""
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
- LibXML::XML::Document.send(:include, LibXML::Conversions::Document)
77
- LibXML::XML::Node.send(:include, LibXML::Conversions::Node)
77
+ # :enddoc:
78
+
79
+ LibXML::XML::Document.include(LibXML::Conversions::Document)
80
+ LibXML::XML::Node.include(LibXML::Conversions::Node)
@@ -1,6 +1,8 @@
1
- require 'libxml'
2
- require 'active_support/core_ext/object/blank'
3
- require 'stringio'
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 = '__content__'.freeze
16
- HASH_SIZE_KEY = '__hash_size__'.freeze
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 => '' }.merge!(attrs)
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
- when Array then current_hash[name] << new_hash
40
- when Hash then current_hash[name] = [current_hash[name], new_hash]
41
- when nil then current_hash[name] = new_hash
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 = self.document_class.new
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 'nokogiri'
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 'active_support/core_ext/object/blank'
8
- require 'stringio'
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 = '__content__'.freeze
41
+ CONTENT_ROOT = "__content__"
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
- when Array then hash[name] << node_hash
51
- when Hash then hash[name] = [hash[name], node_hash]
52
- when nil then hash[name] = node_hash
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] ||= +""
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.send(:include, Conversions::Document)
79
- Nokogiri::XML::Node.send(:include, Conversions::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 'nokogiri'
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 'active_support/core_ext/object/blank'
8
- require 'stringio'
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
- CONTENT_KEY = '__content__'.freeze
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 => '' }.merge!(Hash[attrs])
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
- when Array then current_hash[name] << new_hash
46
- when Hash then current_hash[name] = [current_hash[name], new_hash]
47
- when nil then current_hash[name] = new_hash
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 = self.document_class.new
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
- require 'active_support/core_ext/kernel/reporting'
2
- require 'active_support/core_ext/object/blank'
3
- require 'stringio'
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 = '__content__'.freeze
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
- silence_warnings { require 'rexml/document' } unless defined?(REXML::Document)
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 = +""
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