activesupport 3.1.0 → 5.0.0

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

Potentially problematic release.


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

Files changed (276) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +798 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +13 -7
  5. data/lib/active_support/array_inquirer.rb +44 -0
  6. data/lib/active_support/backtrace_cleaner.rb +38 -34
  7. data/lib/active_support/benchmarkable.rb +17 -28
  8. data/lib/active_support/cache/file_store.rb +85 -70
  9. data/lib/active_support/cache/mem_cache_store.rb +75 -66
  10. data/lib/active_support/cache/memory_store.rb +31 -23
  11. data/lib/active_support/cache/null_store.rb +41 -0
  12. data/lib/active_support/cache/strategy/local_cache.rb +73 -70
  13. data/lib/active_support/cache/strategy/local_cache_middleware.rb +44 -0
  14. data/lib/active_support/cache.rb +360 -294
  15. data/lib/active_support/callbacks.rb +563 -393
  16. data/lib/active_support/concern.rb +42 -34
  17. data/lib/active_support/concurrency/latch.rb +19 -0
  18. data/lib/active_support/concurrency/share_lock.rb +186 -0
  19. data/lib/active_support/configurable.rb +70 -12
  20. data/lib/active_support/core_ext/array/access.rb +53 -9
  21. data/lib/active_support/core_ext/array/conversions.rb +109 -62
  22. data/lib/active_support/core_ext/array/extract_options.rb +2 -2
  23. data/lib/active_support/core_ext/array/grouping.rb +39 -32
  24. data/lib/active_support/core_ext/array/inquiry.rb +17 -0
  25. data/lib/active_support/core_ext/array/prepend_and_append.rb +7 -0
  26. data/lib/active_support/core_ext/array/wrap.rb +16 -18
  27. data/lib/active_support/core_ext/array.rb +2 -2
  28. data/lib/active_support/core_ext/benchmark.rb +7 -0
  29. data/lib/active_support/core_ext/big_decimal/conversions.rb +8 -36
  30. data/lib/active_support/core_ext/class/attribute.rb +47 -34
  31. data/lib/active_support/core_ext/class/attribute_accessors.rb +4 -79
  32. data/lib/active_support/core_ext/class/subclasses.rb +12 -7
  33. data/lib/active_support/core_ext/class.rb +0 -3
  34. data/lib/active_support/core_ext/date/blank.rb +12 -0
  35. data/lib/active_support/core_ext/date/calculations.rb +57 -167
  36. data/lib/active_support/core_ext/date/conversions.rb +31 -42
  37. data/lib/active_support/core_ext/date/zones.rb +2 -10
  38. data/lib/active_support/core_ext/date.rb +5 -0
  39. data/lib/active_support/core_ext/date_and_time/calculations.rb +335 -0
  40. data/lib/active_support/core_ext/date_and_time/compatibility.rb +18 -0
  41. data/lib/active_support/core_ext/date_and_time/zones.rb +40 -0
  42. data/lib/active_support/core_ext/date_time/acts_like.rb +1 -0
  43. data/lib/active_support/core_ext/date_time/blank.rb +12 -0
  44. data/lib/active_support/core_ext/date_time/calculations.rb +132 -65
  45. data/lib/active_support/core_ext/date_time/compatibility.rb +5 -0
  46. data/lib/active_support/core_ext/date_time/conversions.rb +36 -34
  47. data/lib/active_support/core_ext/date_time.rb +5 -0
  48. data/lib/active_support/core_ext/digest/uuid.rb +51 -0
  49. data/lib/active_support/core_ext/enumerable.rb +81 -74
  50. data/lib/active_support/core_ext/file/atomic.rb +53 -26
  51. data/lib/active_support/core_ext/file.rb +0 -1
  52. data/lib/active_support/core_ext/hash/compact.rb +20 -0
  53. data/lib/active_support/core_ext/hash/conversions.rb +175 -70
  54. data/lib/active_support/core_ext/hash/deep_merge.rb +30 -8
  55. data/lib/active_support/core_ext/hash/except.rb +11 -12
  56. data/lib/active_support/core_ext/hash/indifferent_access.rb +7 -8
  57. data/lib/active_support/core_ext/hash/keys.rb +147 -24
  58. data/lib/active_support/core_ext/hash/reverse_merge.rb +2 -3
  59. data/lib/active_support/core_ext/hash/slice.rb +22 -14
  60. data/lib/active_support/core_ext/hash/transform_values.rb +29 -0
  61. data/lib/active_support/core_ext/hash.rb +2 -2
  62. data/lib/active_support/core_ext/integer/inflections.rb +13 -1
  63. data/lib/active_support/core_ext/integer/multiple.rb +4 -0
  64. data/lib/active_support/core_ext/integer/time.rb +12 -22
  65. data/lib/active_support/core_ext/kernel/agnostics.rb +2 -2
  66. data/lib/active_support/core_ext/kernel/concern.rb +12 -0
  67. data/lib/active_support/core_ext/kernel/debugger.rb +2 -15
  68. data/lib/active_support/core_ext/kernel/reporting.rb +12 -62
  69. data/lib/active_support/core_ext/kernel/singleton_class.rb +0 -7
  70. data/lib/active_support/core_ext/kernel.rb +2 -3
  71. data/lib/active_support/core_ext/load_error.rb +14 -7
  72. data/lib/active_support/core_ext/marshal.rb +22 -0
  73. data/lib/active_support/core_ext/module/aliasing.rb +16 -12
  74. data/lib/active_support/core_ext/module/anonymous.rb +12 -8
  75. data/lib/active_support/core_ext/module/attr_internal.rb +2 -5
  76. data/lib/active_support/core_ext/module/attribute_accessors.rb +165 -13
  77. data/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb +141 -0
  78. data/lib/active_support/core_ext/module/concerning.rb +135 -0
  79. data/lib/active_support/core_ext/module/delegation.rb +141 -68
  80. data/lib/active_support/core_ext/module/deprecation.rb +17 -3
  81. data/lib/active_support/core_ext/module/introspection.rb +9 -31
  82. data/lib/active_support/core_ext/module/method_transplanting.rb +3 -0
  83. data/lib/active_support/core_ext/module/qualified_const.rb +70 -0
  84. data/lib/active_support/core_ext/module/reachable.rb +1 -3
  85. data/lib/active_support/core_ext/module/remove_method.rb +24 -5
  86. data/lib/active_support/core_ext/module.rb +3 -3
  87. data/lib/active_support/core_ext/name_error.rb +15 -2
  88. data/lib/active_support/core_ext/numeric/bytes.rb +20 -0
  89. data/lib/active_support/core_ext/numeric/conversions.rb +145 -0
  90. data/lib/active_support/core_ext/numeric/inquiry.rb +26 -0
  91. data/lib/active_support/core_ext/numeric/time.rb +31 -36
  92. data/lib/active_support/core_ext/numeric.rb +2 -0
  93. data/lib/active_support/core_ext/object/acts_like.rb +4 -4
  94. data/lib/active_support/core_ext/object/blank.rb +52 -18
  95. data/lib/active_support/core_ext/object/deep_dup.rb +53 -0
  96. data/lib/active_support/core_ext/object/duplicable.rb +12 -20
  97. data/lib/active_support/core_ext/object/inclusion.rb +13 -1
  98. data/lib/active_support/core_ext/object/instance_variables.rb +7 -12
  99. data/lib/active_support/core_ext/object/json.rb +205 -0
  100. data/lib/active_support/core_ext/object/to_param.rb +1 -55
  101. data/lib/active_support/core_ext/object/to_query.rb +66 -9
  102. data/lib/active_support/core_ext/object/try.rb +124 -33
  103. data/lib/active_support/core_ext/object/with_options.rb +37 -11
  104. data/lib/active_support/core_ext/object.rb +2 -1
  105. data/lib/active_support/core_ext/range/conversions.rb +17 -7
  106. data/lib/active_support/core_ext/range/each.rb +21 -0
  107. data/lib/active_support/core_ext/range/include_range.rb +20 -18
  108. data/lib/active_support/core_ext/range/overlaps.rb +1 -1
  109. data/lib/active_support/core_ext/range.rb +1 -2
  110. data/lib/active_support/core_ext/securerandom.rb +23 -0
  111. data/lib/active_support/core_ext/string/access.rb +95 -90
  112. data/lib/active_support/core_ext/string/behavior.rb +1 -1
  113. data/lib/active_support/core_ext/string/conversions.rb +41 -38
  114. data/lib/active_support/core_ext/string/exclude.rb +6 -1
  115. data/lib/active_support/core_ext/string/filters.rb +70 -17
  116. data/lib/active_support/core_ext/string/indent.rb +43 -0
  117. data/lib/active_support/core_ext/string/inflections.rb +139 -59
  118. data/lib/active_support/core_ext/string/inquiry.rb +2 -2
  119. data/lib/active_support/core_ext/string/multibyte.rb +46 -65
  120. data/lib/active_support/core_ext/string/output_safety.rb +153 -56
  121. data/lib/active_support/core_ext/string/strip.rb +3 -6
  122. data/lib/active_support/core_ext/string/zones.rb +14 -0
  123. data/lib/active_support/core_ext/string.rb +2 -3
  124. data/lib/active_support/core_ext/struct.rb +3 -0
  125. data/lib/active_support/core_ext/time/calculations.rb +173 -173
  126. data/lib/active_support/core_ext/time/compatibility.rb +5 -0
  127. data/lib/active_support/core_ext/time/conversions.rb +33 -29
  128. data/lib/active_support/core_ext/time/marshal.rb +2 -56
  129. data/lib/active_support/core_ext/time/zones.rb +57 -32
  130. data/lib/active_support/core_ext/time.rb +5 -0
  131. data/lib/active_support/core_ext/uri.rb +13 -19
  132. data/lib/active_support/core_ext.rb +3 -2
  133. data/lib/active_support/dependencies/autoload.rb +47 -20
  134. data/lib/active_support/dependencies/interlock.rb +51 -0
  135. data/lib/active_support/dependencies.rb +315 -265
  136. data/lib/active_support/deprecation/behaviors.rb +71 -30
  137. data/lib/active_support/deprecation/instance_delegator.rb +24 -0
  138. data/lib/active_support/deprecation/method_wrappers.rb +59 -18
  139. data/lib/active_support/deprecation/proxy_wrappers.rb +82 -14
  140. data/lib/active_support/deprecation/reporting.rb +61 -14
  141. data/lib/active_support/deprecation.rb +38 -13
  142. data/lib/active_support/descendants_tracker.rb +34 -19
  143. data/lib/active_support/duration/iso8601_parser.rb +122 -0
  144. data/lib/active_support/duration/iso8601_serializer.rb +51 -0
  145. data/lib/active_support/duration.rb +85 -14
  146. data/lib/active_support/evented_file_update_checker.rb +194 -0
  147. data/lib/active_support/execution_wrapper.rb +117 -0
  148. data/lib/active_support/executor.rb +6 -0
  149. data/lib/active_support/file_update_checker.rb +138 -17
  150. data/lib/active_support/gem_version.rb +15 -0
  151. data/lib/active_support/gzip.rb +11 -5
  152. data/lib/active_support/hash_with_indifferent_access.rb +199 -49
  153. data/lib/active_support/i18n.rb +6 -2
  154. data/lib/active_support/i18n_railtie.rb +40 -21
  155. data/lib/active_support/inflections.rb +22 -13
  156. data/lib/active_support/inflector/inflections.rb +175 -144
  157. data/lib/active_support/inflector/methods.rb +328 -91
  158. data/lib/active_support/inflector/transliterate.rb +51 -37
  159. data/lib/active_support/json/decoding.rb +31 -22
  160. data/lib/active_support/json/encoding.rb +88 -248
  161. data/lib/active_support/key_generator.rb +71 -0
  162. data/lib/active_support/lazy_load_hooks.rb +27 -25
  163. data/lib/active_support/locale/en.yml +102 -3
  164. data/lib/active_support/log_subscriber/test_helper.rb +24 -21
  165. data/lib/active_support/log_subscriber.rb +36 -49
  166. data/lib/active_support/logger.rb +106 -0
  167. data/lib/active_support/logger_silence.rb +28 -0
  168. data/lib/active_support/logger_thread_safe_level.rb +31 -0
  169. data/lib/active_support/message_encryptor.rb +72 -36
  170. data/lib/active_support/message_verifier.rb +96 -24
  171. data/lib/active_support/multibyte/chars.rb +88 -333
  172. data/lib/active_support/multibyte/unicode.rb +156 -136
  173. data/lib/active_support/multibyte.rb +5 -28
  174. data/lib/active_support/notifications/fanout.rb +115 -19
  175. data/lib/active_support/notifications/instrumenter.rb +52 -15
  176. data/lib/active_support/notifications.rb +168 -33
  177. data/lib/active_support/number_helper/number_converter.rb +182 -0
  178. data/lib/active_support/number_helper/number_to_currency_converter.rb +44 -0
  179. data/lib/active_support/number_helper/number_to_delimited_converter.rb +28 -0
  180. data/lib/active_support/number_helper/number_to_human_converter.rb +68 -0
  181. data/lib/active_support/number_helper/number_to_human_size_converter.rb +62 -0
  182. data/lib/active_support/number_helper/number_to_percentage_converter.rb +12 -0
  183. data/lib/active_support/number_helper/number_to_phone_converter.rb +58 -0
  184. data/lib/active_support/number_helper/number_to_rounded_converter.rb +92 -0
  185. data/lib/active_support/number_helper.rb +368 -0
  186. data/lib/active_support/option_merger.rb +1 -1
  187. data/lib/active_support/ordered_hash.rb +18 -183
  188. data/lib/active_support/ordered_options.rb +44 -24
  189. data/lib/active_support/per_thread_registry.rb +58 -0
  190. data/lib/active_support/proxy_object.rb +13 -0
  191. data/lib/active_support/rails.rb +27 -0
  192. data/lib/active_support/railtie.rb +25 -34
  193. data/lib/active_support/reloader.rb +129 -0
  194. data/lib/active_support/rescuable.rb +98 -48
  195. data/lib/active_support/security_utils.rb +27 -0
  196. data/lib/active_support/string_inquirer.rb +14 -9
  197. data/lib/active_support/subscriber.rb +120 -0
  198. data/lib/active_support/tagged_logging.rb +78 -0
  199. data/lib/active_support/test_case.rb +69 -17
  200. data/lib/active_support/testing/assertions.rb +43 -41
  201. data/lib/active_support/testing/autorun.rb +12 -0
  202. data/lib/active_support/testing/constant_lookup.rb +50 -0
  203. data/lib/active_support/testing/declarative.rb +7 -21
  204. data/lib/active_support/testing/deprecation.rb +14 -33
  205. data/lib/active_support/testing/file_fixtures.rb +34 -0
  206. data/lib/active_support/testing/isolation.rb +53 -95
  207. data/lib/active_support/testing/method_call_assertions.rb +41 -0
  208. data/lib/active_support/testing/setup_and_teardown.rb +21 -82
  209. data/lib/active_support/testing/stream.rb +42 -0
  210. data/lib/active_support/testing/tagged_logging.rb +25 -0
  211. data/lib/active_support/testing/time_helpers.rb +134 -0
  212. data/lib/active_support/time.rb +6 -23
  213. data/lib/active_support/time_with_zone.rb +239 -92
  214. data/lib/active_support/values/time_zone.rb +236 -160
  215. data/lib/active_support/values/unicode_tables.dat +0 -0
  216. data/lib/active_support/version.rb +5 -7
  217. data/lib/active_support/xml_mini/jdom.rb +19 -13
  218. data/lib/active_support/xml_mini/libxml.rb +3 -4
  219. data/lib/active_support/xml_mini/libxmlsax.rb +2 -3
  220. data/lib/active_support/xml_mini/nokogiri.rb +3 -4
  221. data/lib/active_support/xml_mini/nokogirisax.rb +2 -3
  222. data/lib/active_support/xml_mini/rexml.rb +8 -10
  223. data/lib/active_support/xml_mini.rb +66 -34
  224. data/lib/active_support.rb +40 -23
  225. metadata +185 -134
  226. data/CHANGELOG +0 -1534
  227. data/lib/active_support/base64.rb +0 -42
  228. data/lib/active_support/basic_object.rb +0 -21
  229. data/lib/active_support/buffered_logger.rb +0 -137
  230. data/lib/active_support/cache/compressed_mem_cache_store.rb +0 -13
  231. data/lib/active_support/cache/synchronized_memory_store.rb +0 -11
  232. data/lib/active_support/core_ext/array/random_access.rb +0 -30
  233. data/lib/active_support/core_ext/array/uniq_by.rb +0 -16
  234. data/lib/active_support/core_ext/class/delegating_attributes.rb +0 -44
  235. data/lib/active_support/core_ext/class/inheritable_attributes.rb +0 -178
  236. data/lib/active_support/core_ext/date/freeze.rb +0 -31
  237. data/lib/active_support/core_ext/date_time/zones.rb +0 -21
  238. data/lib/active_support/core_ext/exception.rb +0 -3
  239. data/lib/active_support/core_ext/file/path.rb +0 -5
  240. data/lib/active_support/core_ext/float/rounding.rb +0 -19
  241. data/lib/active_support/core_ext/float.rb +0 -1
  242. data/lib/active_support/core_ext/hash/deep_dup.rb +0 -11
  243. data/lib/active_support/core_ext/hash/diff.rb +0 -13
  244. data/lib/active_support/core_ext/kernel/requires.rb +0 -28
  245. data/lib/active_support/core_ext/logger.rb +0 -81
  246. data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +0 -31
  247. data/lib/active_support/core_ext/module/method_names.rb +0 -14
  248. data/lib/active_support/core_ext/module/synchronization.rb +0 -43
  249. data/lib/active_support/core_ext/object/to_json.rb +0 -19
  250. data/lib/active_support/core_ext/proc.rb +0 -14
  251. data/lib/active_support/core_ext/process/daemon.rb +0 -23
  252. data/lib/active_support/core_ext/process.rb +0 -1
  253. data/lib/active_support/core_ext/range/blockless_step.rb +0 -29
  254. data/lib/active_support/core_ext/range/cover.rb +0 -3
  255. data/lib/active_support/core_ext/rexml.rb +0 -46
  256. data/lib/active_support/core_ext/string/encoding.rb +0 -11
  257. data/lib/active_support/core_ext/string/interpolation.rb +0 -2
  258. data/lib/active_support/core_ext/string/xchar.rb +0 -18
  259. data/lib/active_support/core_ext/time/publicize_conversion_methods.rb +0 -10
  260. data/lib/active_support/file_watcher.rb +0 -36
  261. data/lib/active_support/json/variable.rb +0 -9
  262. data/lib/active_support/memoizable.rb +0 -105
  263. data/lib/active_support/multibyte/exceptions.rb +0 -8
  264. data/lib/active_support/multibyte/utils.rb +0 -60
  265. data/lib/active_support/ruby/shim.rb +0 -22
  266. data/lib/active_support/secure_random.rb +0 -6
  267. data/lib/active_support/testing/mochaing.rb +0 -7
  268. data/lib/active_support/testing/pending.rb +0 -52
  269. data/lib/active_support/testing/performance/jruby.rb +0 -115
  270. data/lib/active_support/testing/performance/rubinius.rb +0 -113
  271. data/lib/active_support/testing/performance/ruby/mri.rb +0 -57
  272. data/lib/active_support/testing/performance/ruby/yarv.rb +0 -57
  273. data/lib/active_support/testing/performance/ruby.rb +0 -152
  274. data/lib/active_support/testing/performance.rb +0 -317
  275. data/lib/active_support/time/autoload.rb +0 -5
  276. data/lib/active_support/whiny_nil.rb +0 -60
@@ -2,9 +2,8 @@ require 'libxml'
2
2
  require 'active_support/core_ext/object/blank'
3
3
  require 'stringio'
4
4
 
5
- # = XmlMini LibXML implementation using a SAX-based parser
6
5
  module ActiveSupport
7
- module XmlMini_LibXMLSAX
6
+ module XmlMini_LibXMLSAX #:nodoc:
8
7
  extend self
9
8
 
10
9
  # Class that will build the hash while the XML document
@@ -33,7 +32,7 @@ module ActiveSupport
33
32
  end
34
33
 
35
34
  def on_start_element(name, attrs = {})
36
- new_hash = { CONTENT_KEY => '' }.merge(attrs)
35
+ new_hash = { CONTENT_KEY => '' }.merge!(attrs)
37
36
  new_hash[HASH_SIZE_KEY] = new_hash.size + 1
38
37
 
39
38
  case current_hash[name]
@@ -7,7 +7,6 @@ end
7
7
  require 'active_support/core_ext/object/blank'
8
8
  require 'stringio'
9
9
 
10
- # = XmlMini Nokogiri implementation
11
10
  module ActiveSupport
12
11
  module XmlMini_Nokogiri #:nodoc:
13
12
  extend self
@@ -41,7 +40,7 @@ module ActiveSupport
41
40
  module Node #:nodoc:
42
41
  CONTENT_ROOT = '__content__'.freeze
43
42
 
44
- # Convert XML document to hash
43
+ # Convert XML document to hash.
45
44
  #
46
45
  # hash::
47
46
  # Hash to merge the converted element into.
@@ -78,7 +77,7 @@ module ActiveSupport
78
77
  end
79
78
  end
80
79
 
81
- Nokogiri::XML::Document.send(:include, Conversions::Document)
82
- Nokogiri::XML::Node.send(:include, Conversions::Node)
80
+ Nokogiri::XML::Document.include(Conversions::Document)
81
+ Nokogiri::XML::Node.include(Conversions::Node)
83
82
  end
84
83
  end
@@ -7,9 +7,8 @@ end
7
7
  require 'active_support/core_ext/object/blank'
8
8
  require 'stringio'
9
9
 
10
- # = XmlMini Nokogiri implementation using a SAX-based parser
11
10
  module ActiveSupport
12
- module XmlMini_NokogiriSAX
11
+ module XmlMini_NokogiriSAX #:nodoc:
13
12
  extend self
14
13
 
15
14
  # Class that will build the hash while the XML document
@@ -39,7 +38,7 @@ module ActiveSupport
39
38
  end
40
39
 
41
40
  def start_element(name, attrs = [])
42
- new_hash = { CONTENT_KEY => '' }.merge(Hash[attrs])
41
+ new_hash = { CONTENT_KEY => '' }.merge!(Hash[attrs])
43
42
  new_hash[HASH_SIZE_KEY] = new_hash.size + 1
44
43
 
45
44
  case current_hash[name]
@@ -2,14 +2,13 @@ require 'active_support/core_ext/kernel/reporting'
2
2
  require 'active_support/core_ext/object/blank'
3
3
  require 'stringio'
4
4
 
5
- # = XmlMini ReXML implementation
6
5
  module ActiveSupport
7
6
  module XmlMini_REXML #:nodoc:
8
7
  extend self
9
8
 
10
9
  CONTENT_KEY = '__content__'.freeze
11
10
 
12
- # Parse an XML Document string or IO into a simple hash
11
+ # Parse an XML Document string or IO into a simple hash.
13
12
  #
14
13
  # Same as XmlSimple::xml_in but doesn't shoot itself in the foot,
15
14
  # and uses the defaults from Active Support.
@@ -21,16 +20,14 @@ module ActiveSupport
21
20
  data = StringIO.new(data || '')
22
21
  end
23
22
 
24
- char = data.getc
25
- if char.nil?
23
+ if data.eof?
26
24
  {}
27
25
  else
28
- data.ungetc(char)
29
26
  silence_warnings { require 'rexml/document' } unless defined?(REXML::Document)
30
27
  doc = REXML::Document.new(data)
31
28
 
32
29
  if doc.root
33
- merge_element!({}, doc.root)
30
+ merge_element!({}, doc.root, XmlMini.depth)
34
31
  else
35
32
  raise REXML::ParseException,
36
33
  "The document #{doc.to_s.inspect} does not have a valid root"
@@ -45,19 +42,20 @@ module ActiveSupport
45
42
  # Hash to merge the converted element into.
46
43
  # element::
47
44
  # XML element to merge into hash
48
- def merge_element!(hash, element)
49
- merge!(hash, element.name, collapse(element))
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))
50
48
  end
51
49
 
52
50
  # Actually converts an XML document element into a data structure.
53
51
  #
54
52
  # element::
55
53
  # The document element to be collapsed.
56
- def collapse(element)
54
+ def collapse(element, depth)
57
55
  hash = get_attributes(element)
58
56
 
59
57
  if element.has_elements?
60
- element.each_element {|child| merge_element!(hash, child) }
58
+ element.each_element {|child| merge_element!(hash, child, depth - 1) }
61
59
  merge_texts!(hash, element) unless empty_content?(element)
62
60
  hash
63
61
  else
@@ -1,5 +1,9 @@
1
+ require 'time'
2
+ require 'base64'
3
+ require 'bigdecimal'
1
4
  require 'active_support/core_ext/module/delegation'
2
5
  require 'active_support/core_ext/string/inflections'
6
+ require 'active_support/core_ext/date_time/calculations'
3
7
 
4
8
  module ActiveSupport
5
9
  # = XmlMini
@@ -28,43 +32,47 @@ module ActiveSupport
28
32
  "binary" => "base64"
29
33
  } unless defined?(DEFAULT_ENCODINGS)
30
34
 
31
- TYPE_NAMES = {
32
- "Symbol" => "symbol",
33
- "Fixnum" => "integer",
34
- "Bignum" => "integer",
35
- "BigDecimal" => "decimal",
36
- "Float" => "float",
37
- "TrueClass" => "boolean",
38
- "FalseClass" => "boolean",
39
- "Date" => "date",
40
- "DateTime" => "datetime",
41
- "Time" => "datetime",
42
- "Array" => "array",
43
- "Hash" => "hash"
44
- } unless defined?(TYPE_NAMES)
35
+ unless defined?(TYPE_NAMES)
36
+ TYPE_NAMES = {
37
+ "Symbol" => "symbol",
38
+ "Integer" => "integer",
39
+ "BigDecimal" => "decimal",
40
+ "Float" => "float",
41
+ "TrueClass" => "boolean",
42
+ "FalseClass" => "boolean",
43
+ "Date" => "date",
44
+ "DateTime" => "dateTime",
45
+ "Time" => "dateTime",
46
+ "Array" => "array",
47
+ "Hash" => "hash"
48
+ }
49
+
50
+ # No need to map these on Ruby 2.4+
51
+ TYPE_NAMES["Fixnum"] = "integer" unless Fixnum == Integer
52
+ TYPE_NAMES["Bignum"] = "integer" unless Bignum == Integer
53
+ end
45
54
 
46
55
  FORMATTING = {
47
56
  "symbol" => Proc.new { |symbol| symbol.to_s },
48
57
  "date" => Proc.new { |date| date.to_s(:db) },
49
- "datetime" => Proc.new { |time| time.xmlschema },
50
- "binary" => Proc.new { |binary| ActiveSupport::Base64.encode64(binary) },
58
+ "dateTime" => Proc.new { |time| time.xmlschema },
59
+ "binary" => Proc.new { |binary| ::Base64.encode64(binary) },
51
60
  "yaml" => Proc.new { |yaml| yaml.to_yaml }
52
61
  } unless defined?(FORMATTING)
53
62
 
54
- # TODO: use Time.xmlschema instead of Time.parse;
55
- # use regexp instead of Date.parse
63
+ # TODO use regexp instead of Date.parse
56
64
  unless defined?(PARSING)
57
65
  PARSING = {
58
- "symbol" => Proc.new { |symbol| symbol.to_sym },
66
+ "symbol" => Proc.new { |symbol| symbol.to_s.to_sym },
59
67
  "date" => Proc.new { |date| ::Date.parse(date) },
60
- "datetime" => Proc.new { |time| ::Time.parse(time).utc rescue ::DateTime.parse(time).utc },
68
+ "datetime" => Proc.new { |time| Time.xmlschema(time).utc rescue ::DateTime.parse(time).utc },
61
69
  "integer" => Proc.new { |integer| integer.to_i },
62
70
  "float" => Proc.new { |float| float.to_f },
63
71
  "decimal" => Proc.new { |number| BigDecimal(number) },
64
- "boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.strip) },
72
+ "boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.to_s.strip) },
65
73
  "string" => Proc.new { |string| string.to_s },
66
74
  "yaml" => Proc.new { |yaml| YAML::load(yaml) rescue yaml },
67
- "base64Binary" => Proc.new { |bin| ActiveSupport::Base64.decode64(bin) },
75
+ "base64Binary" => Proc.new { |bin| ::Base64.decode64(bin) },
68
76
  "binary" => Proc.new { |bin, entity| _parse_binary(bin, entity) },
69
77
  "file" => Proc.new { |file, entity| _parse_file(file, entity) }
70
78
  }
@@ -75,23 +83,27 @@ module ActiveSupport
75
83
  )
76
84
  end
77
85
 
78
- attr_reader :backend
86
+ attr_accessor :depth
87
+ self.depth = 100
88
+
79
89
  delegate :parse, :to => :backend
80
90
 
91
+ def backend
92
+ current_thread_backend || @backend
93
+ end
94
+
81
95
  def backend=(name)
82
- if name.is_a?(Module)
83
- @backend = name
84
- else
85
- require "active_support/xml_mini/#{name.to_s.downcase}"
86
- @backend = ActiveSupport.const_get("XmlMini_#{name}")
87
- end
96
+ backend = name && cast_backend_name_to_module(name)
97
+ self.current_thread_backend = backend if current_thread_backend
98
+ @backend = backend
88
99
  end
89
100
 
90
101
  def with_backend(name)
91
- old_backend, self.backend = backend, name
102
+ old_backend = current_thread_backend
103
+ self.current_thread_backend = name && cast_backend_name_to_module(name)
92
104
  yield
93
105
  ensure
94
- self.backend = old_backend
106
+ self.current_thread_backend = old_backend
95
107
  end
96
108
 
97
109
  def to_tag(key, value, options)
@@ -110,6 +122,7 @@ module ActiveSupport
110
122
  type_name ||= TYPE_NAMES[value.class.name]
111
123
  type_name ||= value.class.name if value && !value.respond_to?(:to_str)
112
124
  type_name = type_name.to_s if type_name
125
+ type_name = "dateTime" if type_name == "datetime"
113
126
 
114
127
  key = rename_key(key.to_s, options)
115
128
 
@@ -144,23 +157,42 @@ module ActiveSupport
144
157
  "#{left}#{middle.tr('_ ', '--')}#{right}"
145
158
  end
146
159
 
147
- # TODO: Add support for other encodings
160
+ # TODO: Add support for other encodings
148
161
  def _parse_binary(bin, entity) #:nodoc:
149
162
  case entity['encoding']
150
163
  when 'base64'
151
- ActiveSupport::Base64.decode64(bin)
164
+ ::Base64.decode64(bin)
152
165
  else
153
166
  bin
154
167
  end
155
168
  end
156
169
 
157
170
  def _parse_file(file, entity)
158
- f = StringIO.new(ActiveSupport::Base64.decode64(file))
171
+ f = StringIO.new(::Base64.decode64(file))
159
172
  f.extend(FileLike)
160
173
  f.original_filename = entity['name']
161
174
  f.content_type = entity['content_type']
162
175
  f
163
176
  end
177
+
178
+ private
179
+
180
+ def current_thread_backend
181
+ Thread.current[:xml_mini_backend]
182
+ end
183
+
184
+ def current_thread_backend=(name)
185
+ Thread.current[:xml_mini_backend] = name && cast_backend_name_to_module(name)
186
+ end
187
+
188
+ def cast_backend_name_to_module(name)
189
+ if name.is_a?(Module)
190
+ name
191
+ else
192
+ require "active_support/xml_mini/#{name.downcase}"
193
+ ActiveSupport.const_get("XmlMini_#{name}")
194
+ end
195
+ end
164
196
  end
165
197
 
166
198
  XmlMini.backend = 'REXML'
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (c) 2005-2011 David Heinemeier Hansson
2
+ # Copyright (c) 2005-2016 David Heinemeier Hansson
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -22,61 +22,78 @@
22
22
  #++
23
23
 
24
24
  require 'securerandom'
25
-
26
- module ActiveSupport
27
- class << self
28
- attr_accessor :load_all_hooks
29
- def on_load_all(&hook) load_all_hooks << hook end
30
- def load_all!; load_all_hooks.each { |hook| hook.call } end
31
- end
32
- self.load_all_hooks = []
33
-
34
- on_load_all do
35
- [Dependencies, Deprecation, Gzip, MessageVerifier, Multibyte]
36
- end
37
- end
38
-
39
25
  require "active_support/dependencies/autoload"
40
26
  require "active_support/version"
27
+ require "active_support/logger"
28
+ require "active_support/lazy_load_hooks"
29
+ require "active_support/core_ext/date_and_time/compatibility"
41
30
 
42
31
  module ActiveSupport
43
32
  extend ActiveSupport::Autoload
44
33
 
34
+ autoload :Concern
35
+ autoload :Dependencies
45
36
  autoload :DescendantsTracker
37
+ autoload :ExecutionWrapper
38
+ autoload :Executor
46
39
  autoload :FileUpdateChecker
40
+ autoload :EventedFileUpdateChecker
47
41
  autoload :LogSubscriber
48
42
  autoload :Notifications
43
+ autoload :Reloader
49
44
 
50
- # TODO: Narrow this list down
51
45
  eager_autoload do
52
46
  autoload :BacktraceCleaner
53
- autoload :Base64
54
- autoload :BasicObject
47
+ autoload :ProxyObject
55
48
  autoload :Benchmarkable
56
- autoload :BufferedLogger
57
49
  autoload :Cache
58
50
  autoload :Callbacks
59
- autoload :Concern
60
51
  autoload :Configurable
61
52
  autoload :Deprecation
62
53
  autoload :Gzip
63
54
  autoload :Inflector
64
55
  autoload :JSON
65
- autoload :Memoizable
56
+ autoload :KeyGenerator
66
57
  autoload :MessageEncryptor
67
58
  autoload :MessageVerifier
68
59
  autoload :Multibyte
60
+ autoload :NumberHelper
69
61
  autoload :OptionMerger
70
62
  autoload :OrderedHash
71
63
  autoload :OrderedOptions
72
- autoload :Rescuable
73
- autoload :SecureRandom
74
64
  autoload :StringInquirer
65
+ autoload :TaggedLogging
75
66
  autoload :XmlMini
67
+ autoload :ArrayInquirer
76
68
  end
77
69
 
70
+ autoload :Rescuable
78
71
  autoload :SafeBuffer, "active_support/core_ext/string/output_safety"
79
72
  autoload :TestCase
73
+
74
+ def self.eager_load!
75
+ super
76
+
77
+ NumberHelper.eager_load!
78
+ end
79
+
80
+ cattr_accessor :test_order # :nodoc:
81
+
82
+ def self.halt_callback_chains_on_return_false
83
+ Callbacks.halt_and_display_warning_on_return_false
84
+ end
85
+
86
+ def self.halt_callback_chains_on_return_false=(value)
87
+ Callbacks.halt_and_display_warning_on_return_false = value
88
+ end
89
+
90
+ def self.to_time_preserves_timezone
91
+ DateAndTime::Compatibility.preserve_timezone
92
+ end
93
+
94
+ def self.to_time_preserves_timezone=(value)
95
+ DateAndTime::Compatibility.preserve_timezone = value
96
+ end
80
97
  end
81
98
 
82
99
  autoload :I18n, "active_support/i18n"