activesupport 5.0.7.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


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

Files changed (236) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +1013 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +39 -0
  5. data/lib/active_support.rb +99 -0
  6. data/lib/active_support/all.rb +3 -0
  7. data/lib/active_support/array_inquirer.rb +44 -0
  8. data/lib/active_support/backtrace_cleaner.rb +103 -0
  9. data/lib/active_support/benchmarkable.rb +49 -0
  10. data/lib/active_support/builder.rb +6 -0
  11. data/lib/active_support/cache.rb +701 -0
  12. data/lib/active_support/cache/file_store.rb +204 -0
  13. data/lib/active_support/cache/mem_cache_store.rb +207 -0
  14. data/lib/active_support/cache/memory_store.rb +167 -0
  15. data/lib/active_support/cache/null_store.rb +41 -0
  16. data/lib/active_support/cache/strategy/local_cache.rb +172 -0
  17. data/lib/active_support/cache/strategy/local_cache_middleware.rb +44 -0
  18. data/lib/active_support/callbacks.rb +791 -0
  19. data/lib/active_support/concern.rb +142 -0
  20. data/lib/active_support/concurrency/latch.rb +26 -0
  21. data/lib/active_support/concurrency/share_lock.rb +226 -0
  22. data/lib/active_support/configurable.rb +148 -0
  23. data/lib/active_support/core_ext.rb +4 -0
  24. data/lib/active_support/core_ext/array.rb +7 -0
  25. data/lib/active_support/core_ext/array/access.rb +90 -0
  26. data/lib/active_support/core_ext/array/conversions.rb +211 -0
  27. data/lib/active_support/core_ext/array/extract_options.rb +29 -0
  28. data/lib/active_support/core_ext/array/grouping.rb +107 -0
  29. data/lib/active_support/core_ext/array/inquiry.rb +17 -0
  30. data/lib/active_support/core_ext/array/prepend_and_append.rb +7 -0
  31. data/lib/active_support/core_ext/array/wrap.rb +46 -0
  32. data/lib/active_support/core_ext/benchmark.rb +14 -0
  33. data/lib/active_support/core_ext/big_decimal.rb +1 -0
  34. data/lib/active_support/core_ext/big_decimal/conversions.rb +14 -0
  35. data/lib/active_support/core_ext/class.rb +2 -0
  36. data/lib/active_support/core_ext/class/attribute.rb +128 -0
  37. data/lib/active_support/core_ext/class/attribute_accessors.rb +4 -0
  38. data/lib/active_support/core_ext/class/subclasses.rb +41 -0
  39. data/lib/active_support/core_ext/date.rb +5 -0
  40. data/lib/active_support/core_ext/date/acts_like.rb +8 -0
  41. data/lib/active_support/core_ext/date/blank.rb +12 -0
  42. data/lib/active_support/core_ext/date/calculations.rb +143 -0
  43. data/lib/active_support/core_ext/date/conversions.rb +95 -0
  44. data/lib/active_support/core_ext/date/zones.rb +6 -0
  45. data/lib/active_support/core_ext/date_and_time/calculations.rb +335 -0
  46. data/lib/active_support/core_ext/date_and_time/compatibility.rb +14 -0
  47. data/lib/active_support/core_ext/date_and_time/zones.rb +40 -0
  48. data/lib/active_support/core_ext/date_time.rb +5 -0
  49. data/lib/active_support/core_ext/date_time/acts_like.rb +14 -0
  50. data/lib/active_support/core_ext/date_time/blank.rb +12 -0
  51. data/lib/active_support/core_ext/date_time/calculations.rb +199 -0
  52. data/lib/active_support/core_ext/date_time/compatibility.rb +16 -0
  53. data/lib/active_support/core_ext/date_time/conversions.rb +105 -0
  54. data/lib/active_support/core_ext/digest/uuid.rb +51 -0
  55. data/lib/active_support/core_ext/enumerable.rb +146 -0
  56. data/lib/active_support/core_ext/file.rb +1 -0
  57. data/lib/active_support/core_ext/file/atomic.rb +68 -0
  58. data/lib/active_support/core_ext/hash.rb +9 -0
  59. data/lib/active_support/core_ext/hash/compact.rb +24 -0
  60. data/lib/active_support/core_ext/hash/conversions.rb +262 -0
  61. data/lib/active_support/core_ext/hash/deep_merge.rb +38 -0
  62. data/lib/active_support/core_ext/hash/except.rb +22 -0
  63. data/lib/active_support/core_ext/hash/indifferent_access.rb +23 -0
  64. data/lib/active_support/core_ext/hash/keys.rb +170 -0
  65. data/lib/active_support/core_ext/hash/reverse_merge.rb +22 -0
  66. data/lib/active_support/core_ext/hash/slice.rb +48 -0
  67. data/lib/active_support/core_ext/hash/transform_values.rb +29 -0
  68. data/lib/active_support/core_ext/integer.rb +3 -0
  69. data/lib/active_support/core_ext/integer/inflections.rb +29 -0
  70. data/lib/active_support/core_ext/integer/multiple.rb +10 -0
  71. data/lib/active_support/core_ext/integer/time.rb +29 -0
  72. data/lib/active_support/core_ext/kernel.rb +4 -0
  73. data/lib/active_support/core_ext/kernel/agnostics.rb +11 -0
  74. data/lib/active_support/core_ext/kernel/concern.rb +12 -0
  75. data/lib/active_support/core_ext/kernel/debugger.rb +3 -0
  76. data/lib/active_support/core_ext/kernel/reporting.rb +43 -0
  77. data/lib/active_support/core_ext/kernel/singleton_class.rb +6 -0
  78. data/lib/active_support/core_ext/load_error.rb +31 -0
  79. data/lib/active_support/core_ext/marshal.rb +22 -0
  80. data/lib/active_support/core_ext/module.rb +12 -0
  81. data/lib/active_support/core_ext/module/aliasing.rb +74 -0
  82. data/lib/active_support/core_ext/module/anonymous.rb +28 -0
  83. data/lib/active_support/core_ext/module/attr_internal.rb +36 -0
  84. data/lib/active_support/core_ext/module/attribute_accessors.rb +212 -0
  85. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +141 -0
  86. data/lib/active_support/core_ext/module/concerning.rb +135 -0
  87. data/lib/active_support/core_ext/module/delegation.rb +216 -0
  88. data/lib/active_support/core_ext/module/deprecation.rb +23 -0
  89. data/lib/active_support/core_ext/module/introspection.rb +68 -0
  90. data/lib/active_support/core_ext/module/method_transplanting.rb +3 -0
  91. data/lib/active_support/core_ext/module/qualified_const.rb +70 -0
  92. data/lib/active_support/core_ext/module/reachable.rb +8 -0
  93. data/lib/active_support/core_ext/module/remove_method.rb +35 -0
  94. data/lib/active_support/core_ext/name_error.rb +31 -0
  95. data/lib/active_support/core_ext/numeric.rb +4 -0
  96. data/lib/active_support/core_ext/numeric/bytes.rb +64 -0
  97. data/lib/active_support/core_ext/numeric/conversions.rb +144 -0
  98. data/lib/active_support/core_ext/numeric/inquiry.rb +26 -0
  99. data/lib/active_support/core_ext/numeric/time.rb +74 -0
  100. data/lib/active_support/core_ext/object.rb +14 -0
  101. data/lib/active_support/core_ext/object/acts_like.rb +10 -0
  102. data/lib/active_support/core_ext/object/blank.rb +143 -0
  103. data/lib/active_support/core_ext/object/conversions.rb +4 -0
  104. data/lib/active_support/core_ext/object/deep_dup.rb +53 -0
  105. data/lib/active_support/core_ext/object/duplicable.rb +124 -0
  106. data/lib/active_support/core_ext/object/inclusion.rb +27 -0
  107. data/lib/active_support/core_ext/object/instance_variables.rb +28 -0
  108. data/lib/active_support/core_ext/object/json.rb +205 -0
  109. data/lib/active_support/core_ext/object/to_param.rb +1 -0
  110. data/lib/active_support/core_ext/object/to_query.rb +84 -0
  111. data/lib/active_support/core_ext/object/try.rb +146 -0
  112. data/lib/active_support/core_ext/object/with_options.rb +69 -0
  113. data/lib/active_support/core_ext/range.rb +4 -0
  114. data/lib/active_support/core_ext/range/conversions.rb +31 -0
  115. data/lib/active_support/core_ext/range/each.rb +21 -0
  116. data/lib/active_support/core_ext/range/include_range.rb +23 -0
  117. data/lib/active_support/core_ext/range/overlaps.rb +8 -0
  118. data/lib/active_support/core_ext/regexp.rb +5 -0
  119. data/lib/active_support/core_ext/securerandom.rb +23 -0
  120. data/lib/active_support/core_ext/string.rb +13 -0
  121. data/lib/active_support/core_ext/string/access.rb +104 -0
  122. data/lib/active_support/core_ext/string/behavior.rb +6 -0
  123. data/lib/active_support/core_ext/string/conversions.rb +57 -0
  124. data/lib/active_support/core_ext/string/exclude.rb +11 -0
  125. data/lib/active_support/core_ext/string/filters.rb +102 -0
  126. data/lib/active_support/core_ext/string/indent.rb +43 -0
  127. data/lib/active_support/core_ext/string/inflections.rb +244 -0
  128. data/lib/active_support/core_ext/string/inquiry.rb +13 -0
  129. data/lib/active_support/core_ext/string/multibyte.rb +53 -0
  130. data/lib/active_support/core_ext/string/output_safety.rb +260 -0
  131. data/lib/active_support/core_ext/string/starts_ends_with.rb +4 -0
  132. data/lib/active_support/core_ext/string/strip.rb +23 -0
  133. data/lib/active_support/core_ext/string/zones.rb +14 -0
  134. data/lib/active_support/core_ext/struct.rb +3 -0
  135. data/lib/active_support/core_ext/time.rb +5 -0
  136. data/lib/active_support/core_ext/time/acts_like.rb +8 -0
  137. data/lib/active_support/core_ext/time/calculations.rb +290 -0
  138. data/lib/active_support/core_ext/time/compatibility.rb +14 -0
  139. data/lib/active_support/core_ext/time/conversions.rb +67 -0
  140. data/lib/active_support/core_ext/time/marshal.rb +3 -0
  141. data/lib/active_support/core_ext/time/zones.rb +111 -0
  142. data/lib/active_support/core_ext/uri.rb +24 -0
  143. data/lib/active_support/dependencies.rb +755 -0
  144. data/lib/active_support/dependencies/autoload.rb +77 -0
  145. data/lib/active_support/dependencies/interlock.rb +55 -0
  146. data/lib/active_support/deprecation.rb +43 -0
  147. data/lib/active_support/deprecation/behaviors.rb +90 -0
  148. data/lib/active_support/deprecation/instance_delegator.rb +37 -0
  149. data/lib/active_support/deprecation/method_wrappers.rb +70 -0
  150. data/lib/active_support/deprecation/proxy_wrappers.rb +149 -0
  151. data/lib/active_support/deprecation/reporting.rb +112 -0
  152. data/lib/active_support/descendants_tracker.rb +60 -0
  153. data/lib/active_support/duration.rb +235 -0
  154. data/lib/active_support/duration/iso8601_parser.rb +122 -0
  155. data/lib/active_support/duration/iso8601_serializer.rb +51 -0
  156. data/lib/active_support/evented_file_update_checker.rb +199 -0
  157. data/lib/active_support/execution_wrapper.rb +126 -0
  158. data/lib/active_support/executor.rb +6 -0
  159. data/lib/active_support/file_update_checker.rb +157 -0
  160. data/lib/active_support/gem_version.rb +15 -0
  161. data/lib/active_support/gzip.rb +36 -0
  162. data/lib/active_support/hash_with_indifferent_access.rb +329 -0
  163. data/lib/active_support/i18n.rb +13 -0
  164. data/lib/active_support/i18n_railtie.rb +115 -0
  165. data/lib/active_support/inflections.rb +70 -0
  166. data/lib/active_support/inflector.rb +7 -0
  167. data/lib/active_support/inflector/inflections.rb +242 -0
  168. data/lib/active_support/inflector/methods.rb +390 -0
  169. data/lib/active_support/inflector/transliterate.rb +112 -0
  170. data/lib/active_support/json.rb +2 -0
  171. data/lib/active_support/json/decoding.rb +74 -0
  172. data/lib/active_support/json/encoding.rb +127 -0
  173. data/lib/active_support/key_generator.rb +71 -0
  174. data/lib/active_support/lazy_load_hooks.rb +76 -0
  175. data/lib/active_support/locale/en.yml +135 -0
  176. data/lib/active_support/log_subscriber.rb +109 -0
  177. data/lib/active_support/log_subscriber/test_helper.rb +104 -0
  178. data/lib/active_support/logger.rb +106 -0
  179. data/lib/active_support/logger_silence.rb +28 -0
  180. data/lib/active_support/logger_thread_safe_level.rb +31 -0
  181. data/lib/active_support/message_encryptor.rb +114 -0
  182. data/lib/active_support/message_verifier.rb +134 -0
  183. data/lib/active_support/multibyte.rb +21 -0
  184. data/lib/active_support/multibyte/chars.rb +231 -0
  185. data/lib/active_support/multibyte/unicode.rb +413 -0
  186. data/lib/active_support/notifications.rb +212 -0
  187. data/lib/active_support/notifications/fanout.rb +157 -0
  188. data/lib/active_support/notifications/instrumenter.rb +91 -0
  189. data/lib/active_support/number_helper.rb +368 -0
  190. data/lib/active_support/number_helper/number_converter.rb +182 -0
  191. data/lib/active_support/number_helper/number_to_currency_converter.rb +44 -0
  192. data/lib/active_support/number_helper/number_to_delimited_converter.rb +28 -0
  193. data/lib/active_support/number_helper/number_to_human_converter.rb +68 -0
  194. data/lib/active_support/number_helper/number_to_human_size_converter.rb +62 -0
  195. data/lib/active_support/number_helper/number_to_percentage_converter.rb +12 -0
  196. data/lib/active_support/number_helper/number_to_phone_converter.rb +58 -0
  197. data/lib/active_support/number_helper/number_to_rounded_converter.rb +92 -0
  198. data/lib/active_support/option_merger.rb +25 -0
  199. data/lib/active_support/ordered_hash.rb +48 -0
  200. data/lib/active_support/ordered_options.rb +81 -0
  201. data/lib/active_support/per_thread_registry.rb +58 -0
  202. data/lib/active_support/proxy_object.rb +13 -0
  203. data/lib/active_support/rails.rb +27 -0
  204. data/lib/active_support/railtie.rb +51 -0
  205. data/lib/active_support/reloader.rb +129 -0
  206. data/lib/active_support/rescuable.rb +173 -0
  207. data/lib/active_support/security_utils.rb +27 -0
  208. data/lib/active_support/string_inquirer.rb +26 -0
  209. data/lib/active_support/subscriber.rb +120 -0
  210. data/lib/active_support/tagged_logging.rb +77 -0
  211. data/lib/active_support/test_case.rb +88 -0
  212. data/lib/active_support/testing/assertions.rb +99 -0
  213. data/lib/active_support/testing/autorun.rb +5 -0
  214. data/lib/active_support/testing/constant_lookup.rb +50 -0
  215. data/lib/active_support/testing/declarative.rb +26 -0
  216. data/lib/active_support/testing/deprecation.rb +36 -0
  217. data/lib/active_support/testing/file_fixtures.rb +34 -0
  218. data/lib/active_support/testing/isolation.rb +115 -0
  219. data/lib/active_support/testing/method_call_assertions.rb +41 -0
  220. data/lib/active_support/testing/setup_and_teardown.rb +50 -0
  221. data/lib/active_support/testing/stream.rb +42 -0
  222. data/lib/active_support/testing/tagged_logging.rb +25 -0
  223. data/lib/active_support/testing/time_helpers.rb +136 -0
  224. data/lib/active_support/time.rb +18 -0
  225. data/lib/active_support/time_with_zone.rb +511 -0
  226. data/lib/active_support/values/time_zone.rb +484 -0
  227. data/lib/active_support/values/unicode_tables.dat +0 -0
  228. data/lib/active_support/version.rb +8 -0
  229. data/lib/active_support/xml_mini.rb +209 -0
  230. data/lib/active_support/xml_mini/jdom.rb +181 -0
  231. data/lib/active_support/xml_mini/libxml.rb +77 -0
  232. data/lib/active_support/xml_mini/libxmlsax.rb +82 -0
  233. data/lib/active_support/xml_mini/nokogiri.rb +81 -0
  234. data/lib/active_support/xml_mini/nokogirisax.rb +85 -0
  235. data/lib/active_support/xml_mini/rexml.rb +128 -0
  236. metadata +350 -0
@@ -0,0 +1,82 @@
1
+ require 'libxml'
2
+ require 'active_support/core_ext/object/blank'
3
+ require 'stringio'
4
+
5
+ module ActiveSupport
6
+ module XmlMini_LibXMLSAX #:nodoc:
7
+ extend self
8
+
9
+ # Class that will build the hash while the XML document
10
+ # is being parsed using SAX events.
11
+ class HashBuilder
12
+
13
+ include LibXML::XML::SaxParser::Callbacks
14
+
15
+ CONTENT_KEY = '__content__'.freeze
16
+ HASH_SIZE_KEY = '__hash_size__'.freeze
17
+
18
+ attr_reader :hash
19
+
20
+ def current_hash
21
+ @hash_stack.last
22
+ end
23
+
24
+ def on_start_document
25
+ @hash = { CONTENT_KEY => '' }
26
+ @hash_stack = [@hash]
27
+ end
28
+
29
+ def on_end_document
30
+ @hash = @hash_stack.pop
31
+ @hash.delete(CONTENT_KEY)
32
+ end
33
+
34
+ def on_start_element(name, attrs = {})
35
+ new_hash = { CONTENT_KEY => '' }.merge!(attrs)
36
+ new_hash[HASH_SIZE_KEY] = new_hash.size + 1
37
+
38
+ 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
42
+ end
43
+
44
+ @hash_stack.push(new_hash)
45
+ end
46
+
47
+ 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
+ current_hash.delete(CONTENT_KEY)
50
+ end
51
+ @hash_stack.pop
52
+ end
53
+
54
+ def on_characters(string)
55
+ current_hash[CONTENT_KEY] << string
56
+ end
57
+
58
+ alias_method :on_cdata_block, :on_characters
59
+ end
60
+
61
+ attr_accessor :document_class
62
+ self.document_class = HashBuilder
63
+
64
+ def parse(data)
65
+ if !data.respond_to?(:read)
66
+ data = StringIO.new(data || '')
67
+ end
68
+
69
+ if data.eof?
70
+ {}
71
+ else
72
+ LibXML::XML::Error.set_handler(&LibXML::XML::Error::QUIET_HANDLER)
73
+ parser = LibXML::XML::SaxParser.io(data)
74
+ document = self.document_class.new
75
+
76
+ parser.callbacks = document
77
+ parser.parse
78
+ document.hash
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,81 @@
1
+ begin
2
+ require 'nokogiri'
3
+ rescue LoadError => e
4
+ $stderr.puts "You don't have nokogiri installed in your application. Please add it to your Gemfile and run bundle install"
5
+ raise e
6
+ end
7
+ require 'active_support/core_ext/object/blank'
8
+ require 'stringio'
9
+
10
+ module ActiveSupport
11
+ module XmlMini_Nokogiri #:nodoc:
12
+ extend self
13
+
14
+ # Parse an XML Document string or IO into a simple hash using libxml / nokogiri.
15
+ # data::
16
+ # XML Document string or IO to parse
17
+ def parse(data)
18
+ if !data.respond_to?(:read)
19
+ data = StringIO.new(data || '')
20
+ end
21
+
22
+ if data.eof?
23
+ {}
24
+ else
25
+ doc = Nokogiri::XML(data)
26
+ raise doc.errors.first if doc.errors.length > 0
27
+ doc.to_hash
28
+ end
29
+ end
30
+
31
+ module Conversions #:nodoc:
32
+ module Document #:nodoc:
33
+ def to_hash
34
+ root.to_hash
35
+ end
36
+ end
37
+
38
+ module Node #:nodoc:
39
+ CONTENT_ROOT = '__content__'.freeze
40
+
41
+ # Convert XML document to hash.
42
+ #
43
+ # hash::
44
+ # Hash to merge the converted element into.
45
+ def to_hash(hash={})
46
+ node_hash = {}
47
+
48
+ # Insert node hash into parent hash correctly.
49
+ 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
53
+ end
54
+
55
+ # Handle child elements
56
+ children.each do |c|
57
+ if c.element?
58
+ c.to_hash(node_hash)
59
+ elsif c.text? || c.cdata?
60
+ node_hash[CONTENT_ROOT] ||= ''
61
+ node_hash[CONTENT_ROOT] << c.content
62
+ end
63
+ end
64
+
65
+ # Remove content node if it is blank and there are child tags
66
+ if node_hash.length > 1 && node_hash[CONTENT_ROOT].blank?
67
+ node_hash.delete(CONTENT_ROOT)
68
+ end
69
+
70
+ # Handle attributes
71
+ attribute_nodes.each { |a| node_hash[a.node_name] = a.value }
72
+
73
+ hash
74
+ end
75
+ end
76
+ end
77
+
78
+ Nokogiri::XML::Document.include(Conversions::Document)
79
+ Nokogiri::XML::Node.include(Conversions::Node)
80
+ end
81
+ end
@@ -0,0 +1,85 @@
1
+ begin
2
+ require 'nokogiri'
3
+ rescue LoadError => e
4
+ $stderr.puts "You don't have nokogiri installed in your application. Please add it to your Gemfile and run bundle install"
5
+ raise e
6
+ end
7
+ require 'active_support/core_ext/object/blank'
8
+ require 'stringio'
9
+
10
+ module ActiveSupport
11
+ module XmlMini_NokogiriSAX #:nodoc:
12
+ extend self
13
+
14
+ # Class that will build the hash while the XML document
15
+ # is being parsed using SAX events.
16
+ class HashBuilder < Nokogiri::XML::SAX::Document
17
+
18
+ CONTENT_KEY = '__content__'.freeze
19
+ HASH_SIZE_KEY = '__hash_size__'.freeze
20
+
21
+ attr_reader :hash
22
+
23
+ def current_hash
24
+ @hash_stack.last
25
+ end
26
+
27
+ def start_document
28
+ @hash = {}
29
+ @hash_stack = [@hash]
30
+ end
31
+
32
+ def end_document
33
+ raise "Parse stack not empty!" if @hash_stack.size > 1
34
+ end
35
+
36
+ def error(error_message)
37
+ raise error_message
38
+ end
39
+
40
+ def start_element(name, attrs = [])
41
+ new_hash = { CONTENT_KEY => '' }.merge!(Hash[attrs])
42
+ new_hash[HASH_SIZE_KEY] = new_hash.size + 1
43
+
44
+ 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
48
+ end
49
+
50
+ @hash_stack.push(new_hash)
51
+ end
52
+
53
+ 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
+ current_hash.delete(CONTENT_KEY)
56
+ end
57
+ @hash_stack.pop
58
+ end
59
+
60
+ def characters(string)
61
+ current_hash[CONTENT_KEY] << string
62
+ end
63
+
64
+ alias_method :cdata_block, :characters
65
+ end
66
+
67
+ attr_accessor :document_class
68
+ self.document_class = HashBuilder
69
+
70
+ def parse(data)
71
+ if !data.respond_to?(:read)
72
+ data = StringIO.new(data || '')
73
+ end
74
+
75
+ if data.eof?
76
+ {}
77
+ else
78
+ document = self.document_class.new
79
+ parser = Nokogiri::XML::SAX::Parser.new(document)
80
+ parser.parse(data)
81
+ document.hash
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,128 @@
1
+ require 'active_support/core_ext/kernel/reporting'
2
+ require 'active_support/core_ext/object/blank'
3
+ require 'stringio'
4
+
5
+ module ActiveSupport
6
+ module XmlMini_REXML #:nodoc:
7
+ extend self
8
+
9
+ CONTENT_KEY = '__content__'.freeze
10
+
11
+ # Parse an XML Document string or IO into a simple hash.
12
+ #
13
+ # Same as XmlSimple::xml_in but doesn't shoot itself in the foot,
14
+ # and uses the defaults from Active Support.
15
+ #
16
+ # data::
17
+ # XML Document string or IO to parse
18
+ def parse(data)
19
+ if !data.respond_to?(:read)
20
+ data = StringIO.new(data || '')
21
+ end
22
+
23
+ if data.eof?
24
+ {}
25
+ else
26
+ silence_warnings { require 'rexml/document' } unless defined?(REXML::Document)
27
+ doc = REXML::Document.new(data)
28
+
29
+ if doc.root
30
+ merge_element!({}, doc.root, XmlMini.depth)
31
+ else
32
+ raise REXML::ParseException,
33
+ "The document #{doc.to_s.inspect} does not have a valid root"
34
+ end
35
+ end
36
+ end
37
+
38
+ private
39
+ # Convert an XML element and merge into the hash
40
+ #
41
+ # hash::
42
+ # Hash to merge the converted element into.
43
+ # element::
44
+ # XML element to merge into hash
45
+ def merge_element!(hash, element, depth)
46
+ raise REXML::ParseException, "The document is too deep" if depth == 0
47
+ merge!(hash, element.name, collapse(element, depth))
48
+ end
49
+
50
+ # Actually converts an XML document element into a data structure.
51
+ #
52
+ # element::
53
+ # The document element to be collapsed.
54
+ def collapse(element, depth)
55
+ hash = get_attributes(element)
56
+
57
+ if element.has_elements?
58
+ element.each_element {|child| merge_element!(hash, child, depth - 1) }
59
+ merge_texts!(hash, element) unless empty_content?(element)
60
+ hash
61
+ else
62
+ merge_texts!(hash, element)
63
+ end
64
+ end
65
+
66
+ # Merge all the texts of an element into the hash
67
+ #
68
+ # hash::
69
+ # Hash to add the converted element to.
70
+ # element::
71
+ # XML element whose texts are to me merged into the hash
72
+ def merge_texts!(hash, element)
73
+ unless element.has_text?
74
+ hash
75
+ else
76
+ # must use value to prevent double-escaping
77
+ texts = ''
78
+ element.texts.each { |t| texts << t.value }
79
+ merge!(hash, CONTENT_KEY, texts)
80
+ end
81
+ end
82
+
83
+ # Adds a new key/value pair to an existing Hash. If the key to be added
84
+ # already exists and the existing value associated with key is not
85
+ # an Array, it will be wrapped in an Array. Then the new value is
86
+ # appended to that Array.
87
+ #
88
+ # hash::
89
+ # Hash to add key/value pair to.
90
+ # key::
91
+ # Key to be added.
92
+ # value::
93
+ # Value to be associated with key.
94
+ def merge!(hash, key, value)
95
+ if hash.has_key?(key)
96
+ if hash[key].instance_of?(Array)
97
+ hash[key] << value
98
+ else
99
+ hash[key] = [hash[key], value]
100
+ end
101
+ elsif value.instance_of?(Array)
102
+ hash[key] = [value]
103
+ else
104
+ hash[key] = value
105
+ end
106
+ hash
107
+ end
108
+
109
+ # Converts the attributes array of an XML element into a hash.
110
+ # Returns an empty Hash if node has no attributes.
111
+ #
112
+ # element::
113
+ # XML element to extract attributes from.
114
+ def get_attributes(element)
115
+ attributes = {}
116
+ element.attributes.each { |n,v| attributes[n] = v }
117
+ attributes
118
+ end
119
+
120
+ # Determines if a document element has text content
121
+ #
122
+ # element::
123
+ # XML element to be checked.
124
+ def empty_content?(element)
125
+ element.texts.join.blank?
126
+ end
127
+ end
128
+ end
metadata ADDED
@@ -0,0 +1,350 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activesupport
3
+ version: !ruby/object:Gem::Version
4
+ version: 5.0.7.1
5
+ platform: ruby
6
+ authors:
7
+ - David Heinemeier Hansson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-11-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: i18n
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0.7'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '0.7'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2'
33
+ - !ruby/object:Gem::Dependency
34
+ name: tzinfo
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.1'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.1'
47
+ - !ruby/object:Gem::Dependency
48
+ name: minitest
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '5.1'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '5.1'
61
+ - !ruby/object:Gem::Dependency
62
+ name: concurrent-ruby
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.0'
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 1.0.2
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '1.0'
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 1.0.2
81
+ description: A toolkit of support libraries and Ruby core extensions extracted from
82
+ the Rails framework. Rich support for multibyte strings, internationalization, time
83
+ zones, and testing.
84
+ email: david@loudthinking.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - CHANGELOG.md
90
+ - MIT-LICENSE
91
+ - README.rdoc
92
+ - lib/active_support.rb
93
+ - lib/active_support/all.rb
94
+ - lib/active_support/array_inquirer.rb
95
+ - lib/active_support/backtrace_cleaner.rb
96
+ - lib/active_support/benchmarkable.rb
97
+ - lib/active_support/builder.rb
98
+ - lib/active_support/cache.rb
99
+ - lib/active_support/cache/file_store.rb
100
+ - lib/active_support/cache/mem_cache_store.rb
101
+ - lib/active_support/cache/memory_store.rb
102
+ - lib/active_support/cache/null_store.rb
103
+ - lib/active_support/cache/strategy/local_cache.rb
104
+ - lib/active_support/cache/strategy/local_cache_middleware.rb
105
+ - lib/active_support/callbacks.rb
106
+ - lib/active_support/concern.rb
107
+ - lib/active_support/concurrency/latch.rb
108
+ - lib/active_support/concurrency/share_lock.rb
109
+ - lib/active_support/configurable.rb
110
+ - lib/active_support/core_ext.rb
111
+ - lib/active_support/core_ext/array.rb
112
+ - lib/active_support/core_ext/array/access.rb
113
+ - lib/active_support/core_ext/array/conversions.rb
114
+ - lib/active_support/core_ext/array/extract_options.rb
115
+ - lib/active_support/core_ext/array/grouping.rb
116
+ - lib/active_support/core_ext/array/inquiry.rb
117
+ - lib/active_support/core_ext/array/prepend_and_append.rb
118
+ - lib/active_support/core_ext/array/wrap.rb
119
+ - lib/active_support/core_ext/benchmark.rb
120
+ - lib/active_support/core_ext/big_decimal.rb
121
+ - lib/active_support/core_ext/big_decimal/conversions.rb
122
+ - lib/active_support/core_ext/class.rb
123
+ - lib/active_support/core_ext/class/attribute.rb
124
+ - lib/active_support/core_ext/class/attribute_accessors.rb
125
+ - lib/active_support/core_ext/class/subclasses.rb
126
+ - lib/active_support/core_ext/date.rb
127
+ - lib/active_support/core_ext/date/acts_like.rb
128
+ - lib/active_support/core_ext/date/blank.rb
129
+ - lib/active_support/core_ext/date/calculations.rb
130
+ - lib/active_support/core_ext/date/conversions.rb
131
+ - lib/active_support/core_ext/date/zones.rb
132
+ - lib/active_support/core_ext/date_and_time/calculations.rb
133
+ - lib/active_support/core_ext/date_and_time/compatibility.rb
134
+ - lib/active_support/core_ext/date_and_time/zones.rb
135
+ - lib/active_support/core_ext/date_time.rb
136
+ - lib/active_support/core_ext/date_time/acts_like.rb
137
+ - lib/active_support/core_ext/date_time/blank.rb
138
+ - lib/active_support/core_ext/date_time/calculations.rb
139
+ - lib/active_support/core_ext/date_time/compatibility.rb
140
+ - lib/active_support/core_ext/date_time/conversions.rb
141
+ - lib/active_support/core_ext/digest/uuid.rb
142
+ - lib/active_support/core_ext/enumerable.rb
143
+ - lib/active_support/core_ext/file.rb
144
+ - lib/active_support/core_ext/file/atomic.rb
145
+ - lib/active_support/core_ext/hash.rb
146
+ - lib/active_support/core_ext/hash/compact.rb
147
+ - lib/active_support/core_ext/hash/conversions.rb
148
+ - lib/active_support/core_ext/hash/deep_merge.rb
149
+ - lib/active_support/core_ext/hash/except.rb
150
+ - lib/active_support/core_ext/hash/indifferent_access.rb
151
+ - lib/active_support/core_ext/hash/keys.rb
152
+ - lib/active_support/core_ext/hash/reverse_merge.rb
153
+ - lib/active_support/core_ext/hash/slice.rb
154
+ - lib/active_support/core_ext/hash/transform_values.rb
155
+ - lib/active_support/core_ext/integer.rb
156
+ - lib/active_support/core_ext/integer/inflections.rb
157
+ - lib/active_support/core_ext/integer/multiple.rb
158
+ - lib/active_support/core_ext/integer/time.rb
159
+ - lib/active_support/core_ext/kernel.rb
160
+ - lib/active_support/core_ext/kernel/agnostics.rb
161
+ - lib/active_support/core_ext/kernel/concern.rb
162
+ - lib/active_support/core_ext/kernel/debugger.rb
163
+ - lib/active_support/core_ext/kernel/reporting.rb
164
+ - lib/active_support/core_ext/kernel/singleton_class.rb
165
+ - lib/active_support/core_ext/load_error.rb
166
+ - lib/active_support/core_ext/marshal.rb
167
+ - lib/active_support/core_ext/module.rb
168
+ - lib/active_support/core_ext/module/aliasing.rb
169
+ - lib/active_support/core_ext/module/anonymous.rb
170
+ - lib/active_support/core_ext/module/attr_internal.rb
171
+ - lib/active_support/core_ext/module/attribute_accessors.rb
172
+ - lib/active_support/core_ext/module/attribute_accessors_per_thread.rb
173
+ - lib/active_support/core_ext/module/concerning.rb
174
+ - lib/active_support/core_ext/module/delegation.rb
175
+ - lib/active_support/core_ext/module/deprecation.rb
176
+ - lib/active_support/core_ext/module/introspection.rb
177
+ - lib/active_support/core_ext/module/method_transplanting.rb
178
+ - lib/active_support/core_ext/module/qualified_const.rb
179
+ - lib/active_support/core_ext/module/reachable.rb
180
+ - lib/active_support/core_ext/module/remove_method.rb
181
+ - lib/active_support/core_ext/name_error.rb
182
+ - lib/active_support/core_ext/numeric.rb
183
+ - lib/active_support/core_ext/numeric/bytes.rb
184
+ - lib/active_support/core_ext/numeric/conversions.rb
185
+ - lib/active_support/core_ext/numeric/inquiry.rb
186
+ - lib/active_support/core_ext/numeric/time.rb
187
+ - lib/active_support/core_ext/object.rb
188
+ - lib/active_support/core_ext/object/acts_like.rb
189
+ - lib/active_support/core_ext/object/blank.rb
190
+ - lib/active_support/core_ext/object/conversions.rb
191
+ - lib/active_support/core_ext/object/deep_dup.rb
192
+ - lib/active_support/core_ext/object/duplicable.rb
193
+ - lib/active_support/core_ext/object/inclusion.rb
194
+ - lib/active_support/core_ext/object/instance_variables.rb
195
+ - lib/active_support/core_ext/object/json.rb
196
+ - lib/active_support/core_ext/object/to_param.rb
197
+ - lib/active_support/core_ext/object/to_query.rb
198
+ - lib/active_support/core_ext/object/try.rb
199
+ - lib/active_support/core_ext/object/with_options.rb
200
+ - lib/active_support/core_ext/range.rb
201
+ - lib/active_support/core_ext/range/conversions.rb
202
+ - lib/active_support/core_ext/range/each.rb
203
+ - lib/active_support/core_ext/range/include_range.rb
204
+ - lib/active_support/core_ext/range/overlaps.rb
205
+ - lib/active_support/core_ext/regexp.rb
206
+ - lib/active_support/core_ext/securerandom.rb
207
+ - lib/active_support/core_ext/string.rb
208
+ - lib/active_support/core_ext/string/access.rb
209
+ - lib/active_support/core_ext/string/behavior.rb
210
+ - lib/active_support/core_ext/string/conversions.rb
211
+ - lib/active_support/core_ext/string/exclude.rb
212
+ - lib/active_support/core_ext/string/filters.rb
213
+ - lib/active_support/core_ext/string/indent.rb
214
+ - lib/active_support/core_ext/string/inflections.rb
215
+ - lib/active_support/core_ext/string/inquiry.rb
216
+ - lib/active_support/core_ext/string/multibyte.rb
217
+ - lib/active_support/core_ext/string/output_safety.rb
218
+ - lib/active_support/core_ext/string/starts_ends_with.rb
219
+ - lib/active_support/core_ext/string/strip.rb
220
+ - lib/active_support/core_ext/string/zones.rb
221
+ - lib/active_support/core_ext/struct.rb
222
+ - lib/active_support/core_ext/time.rb
223
+ - lib/active_support/core_ext/time/acts_like.rb
224
+ - lib/active_support/core_ext/time/calculations.rb
225
+ - lib/active_support/core_ext/time/compatibility.rb
226
+ - lib/active_support/core_ext/time/conversions.rb
227
+ - lib/active_support/core_ext/time/marshal.rb
228
+ - lib/active_support/core_ext/time/zones.rb
229
+ - lib/active_support/core_ext/uri.rb
230
+ - lib/active_support/dependencies.rb
231
+ - lib/active_support/dependencies/autoload.rb
232
+ - lib/active_support/dependencies/interlock.rb
233
+ - lib/active_support/deprecation.rb
234
+ - lib/active_support/deprecation/behaviors.rb
235
+ - lib/active_support/deprecation/instance_delegator.rb
236
+ - lib/active_support/deprecation/method_wrappers.rb
237
+ - lib/active_support/deprecation/proxy_wrappers.rb
238
+ - lib/active_support/deprecation/reporting.rb
239
+ - lib/active_support/descendants_tracker.rb
240
+ - lib/active_support/duration.rb
241
+ - lib/active_support/duration/iso8601_parser.rb
242
+ - lib/active_support/duration/iso8601_serializer.rb
243
+ - lib/active_support/evented_file_update_checker.rb
244
+ - lib/active_support/execution_wrapper.rb
245
+ - lib/active_support/executor.rb
246
+ - lib/active_support/file_update_checker.rb
247
+ - lib/active_support/gem_version.rb
248
+ - lib/active_support/gzip.rb
249
+ - lib/active_support/hash_with_indifferent_access.rb
250
+ - lib/active_support/i18n.rb
251
+ - lib/active_support/i18n_railtie.rb
252
+ - lib/active_support/inflections.rb
253
+ - lib/active_support/inflector.rb
254
+ - lib/active_support/inflector/inflections.rb
255
+ - lib/active_support/inflector/methods.rb
256
+ - lib/active_support/inflector/transliterate.rb
257
+ - lib/active_support/json.rb
258
+ - lib/active_support/json/decoding.rb
259
+ - lib/active_support/json/encoding.rb
260
+ - lib/active_support/key_generator.rb
261
+ - lib/active_support/lazy_load_hooks.rb
262
+ - lib/active_support/locale/en.yml
263
+ - lib/active_support/log_subscriber.rb
264
+ - lib/active_support/log_subscriber/test_helper.rb
265
+ - lib/active_support/logger.rb
266
+ - lib/active_support/logger_silence.rb
267
+ - lib/active_support/logger_thread_safe_level.rb
268
+ - lib/active_support/message_encryptor.rb
269
+ - lib/active_support/message_verifier.rb
270
+ - lib/active_support/multibyte.rb
271
+ - lib/active_support/multibyte/chars.rb
272
+ - lib/active_support/multibyte/unicode.rb
273
+ - lib/active_support/notifications.rb
274
+ - lib/active_support/notifications/fanout.rb
275
+ - lib/active_support/notifications/instrumenter.rb
276
+ - lib/active_support/number_helper.rb
277
+ - lib/active_support/number_helper/number_converter.rb
278
+ - lib/active_support/number_helper/number_to_currency_converter.rb
279
+ - lib/active_support/number_helper/number_to_delimited_converter.rb
280
+ - lib/active_support/number_helper/number_to_human_converter.rb
281
+ - lib/active_support/number_helper/number_to_human_size_converter.rb
282
+ - lib/active_support/number_helper/number_to_percentage_converter.rb
283
+ - lib/active_support/number_helper/number_to_phone_converter.rb
284
+ - lib/active_support/number_helper/number_to_rounded_converter.rb
285
+ - lib/active_support/option_merger.rb
286
+ - lib/active_support/ordered_hash.rb
287
+ - lib/active_support/ordered_options.rb
288
+ - lib/active_support/per_thread_registry.rb
289
+ - lib/active_support/proxy_object.rb
290
+ - lib/active_support/rails.rb
291
+ - lib/active_support/railtie.rb
292
+ - lib/active_support/reloader.rb
293
+ - lib/active_support/rescuable.rb
294
+ - lib/active_support/security_utils.rb
295
+ - lib/active_support/string_inquirer.rb
296
+ - lib/active_support/subscriber.rb
297
+ - lib/active_support/tagged_logging.rb
298
+ - lib/active_support/test_case.rb
299
+ - lib/active_support/testing/assertions.rb
300
+ - lib/active_support/testing/autorun.rb
301
+ - lib/active_support/testing/constant_lookup.rb
302
+ - lib/active_support/testing/declarative.rb
303
+ - lib/active_support/testing/deprecation.rb
304
+ - lib/active_support/testing/file_fixtures.rb
305
+ - lib/active_support/testing/isolation.rb
306
+ - lib/active_support/testing/method_call_assertions.rb
307
+ - lib/active_support/testing/setup_and_teardown.rb
308
+ - lib/active_support/testing/stream.rb
309
+ - lib/active_support/testing/tagged_logging.rb
310
+ - lib/active_support/testing/time_helpers.rb
311
+ - lib/active_support/time.rb
312
+ - lib/active_support/time_with_zone.rb
313
+ - lib/active_support/values/time_zone.rb
314
+ - lib/active_support/values/unicode_tables.dat
315
+ - lib/active_support/version.rb
316
+ - lib/active_support/xml_mini.rb
317
+ - lib/active_support/xml_mini/jdom.rb
318
+ - lib/active_support/xml_mini/libxml.rb
319
+ - lib/active_support/xml_mini/libxmlsax.rb
320
+ - lib/active_support/xml_mini/nokogiri.rb
321
+ - lib/active_support/xml_mini/nokogirisax.rb
322
+ - lib/active_support/xml_mini/rexml.rb
323
+ homepage: http://rubyonrails.org
324
+ licenses:
325
+ - MIT
326
+ metadata: {}
327
+ post_install_message:
328
+ rdoc_options:
329
+ - "--encoding"
330
+ - UTF-8
331
+ require_paths:
332
+ - lib
333
+ required_ruby_version: !ruby/object:Gem::Requirement
334
+ requirements:
335
+ - - ">="
336
+ - !ruby/object:Gem::Version
337
+ version: 2.2.2
338
+ required_rubygems_version: !ruby/object:Gem::Requirement
339
+ requirements:
340
+ - - ">="
341
+ - !ruby/object:Gem::Version
342
+ version: '0'
343
+ requirements: []
344
+ rubyforge_project:
345
+ rubygems_version: 2.7.6
346
+ signing_key:
347
+ specification_version: 4
348
+ summary: A toolkit of support libraries and Ruby core extensions extracted from the
349
+ Rails framework.
350
+ test_files: []