activesupport 2.3.18 → 3.0.0.beta

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 (403) hide show
  1. data/CHANGELOG +30 -53
  2. data/lib/active_support.rb +43 -31
  3. data/lib/active_support/all.rb +3 -7
  4. data/lib/active_support/backtrace_cleaner.rb +24 -8
  5. data/lib/active_support/base64.rb +9 -0
  6. data/lib/active_support/benchmarkable.rb +60 -0
  7. data/lib/active_support/buffered_logger.rb +12 -9
  8. data/lib/active_support/cache.rb +75 -55
  9. data/lib/active_support/cache/compressed_mem_cache_store.rb +2 -0
  10. data/lib/active_support/cache/file_store.rb +35 -17
  11. data/lib/active_support/cache/mem_cache_store.rb +29 -20
  12. data/lib/active_support/cache/memory_store.rb +18 -17
  13. data/lib/active_support/cache/strategy/local_cache.rb +9 -1
  14. data/lib/active_support/callbacks.rb +490 -169
  15. data/lib/active_support/concern.rb +29 -0
  16. data/lib/active_support/configurable.rb +35 -0
  17. data/lib/active_support/core_ext.rb +2 -7
  18. data/lib/active_support/core_ext/array.rb +2 -10
  19. data/lib/active_support/core_ext/array/access.rb +39 -46
  20. data/lib/active_support/core_ext/array/conversions.rb +146 -182
  21. data/lib/active_support/core_ext/array/extract_options.rb +12 -18
  22. data/lib/active_support/core_ext/array/grouping.rb +87 -93
  23. data/lib/active_support/core_ext/array/random_access.rb +4 -40
  24. data/lib/active_support/core_ext/array/uniq_by.rb +17 -0
  25. data/lib/active_support/core_ext/array/wrap.rb +22 -0
  26. data/lib/active_support/core_ext/big_decimal.rb +1 -0
  27. data/lib/active_support/core_ext/big_decimal/conversions.rb +27 -0
  28. data/lib/active_support/core_ext/cgi.rb +0 -4
  29. data/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +16 -20
  30. data/lib/active_support/core_ext/class.rb +0 -2
  31. data/lib/active_support/core_ext/class/attribute.rb +8 -39
  32. data/lib/active_support/core_ext/class/attribute_accessors.rb +31 -35
  33. data/lib/active_support/core_ext/class/delegating_attributes.rb +34 -40
  34. data/lib/active_support/core_ext/class/inheritable_attributes.rb +100 -16
  35. data/lib/active_support/core_ext/date/acts_like.rb +8 -0
  36. data/lib/active_support/core_ext/date/calculations.rb +218 -238
  37. data/lib/active_support/core_ext/date/conversions.rb +87 -96
  38. data/lib/active_support/core_ext/date/freeze.rb +31 -0
  39. data/lib/active_support/core_ext/date_time/acts_like.rb +13 -0
  40. data/lib/active_support/core_ext/date_time/calculations.rb +97 -110
  41. data/lib/active_support/core_ext/date_time/conversions.rb +83 -95
  42. data/lib/active_support/core_ext/date_time/zones.rb +17 -0
  43. data/lib/active_support/core_ext/enumerable.rb +14 -15
  44. data/lib/active_support/core_ext/exception.rb +1 -43
  45. data/lib/active_support/core_ext/file.rb +0 -4
  46. data/lib/active_support/core_ext/file/atomic.rb +34 -41
  47. data/lib/active_support/core_ext/float.rb +0 -6
  48. data/lib/active_support/core_ext/float/rounding.rb +15 -20
  49. data/lib/active_support/core_ext/hash.rb +8 -14
  50. data/lib/active_support/core_ext/hash/conversions.rb +236 -236
  51. data/lib/active_support/core_ext/hash/deep_merge.rb +12 -19
  52. data/lib/active_support/core_ext/hash/diff.rb +11 -17
  53. data/lib/active_support/core_ext/hash/except.rb +21 -22
  54. data/lib/active_support/core_ext/hash/indifferent_access.rb +8 -137
  55. data/lib/active_support/core_ext/hash/keys.rb +38 -45
  56. data/lib/active_support/core_ext/hash/reverse_merge.rb +25 -32
  57. data/lib/active_support/core_ext/hash/slice.rb +35 -37
  58. data/lib/active_support/core_ext/integer.rb +1 -7
  59. data/lib/active_support/core_ext/integer/inflections.rb +10 -16
  60. data/lib/active_support/core_ext/integer/multiple.rb +6 -0
  61. data/lib/active_support/core_ext/integer/time.rb +36 -42
  62. data/lib/active_support/core_ext/kernel/reporting.rb +9 -7
  63. data/lib/active_support/core_ext/kernel/requires.rb +3 -1
  64. data/lib/active_support/core_ext/load_error.rb +16 -33
  65. data/lib/active_support/core_ext/logger.rb +3 -2
  66. data/lib/active_support/core_ext/module.rb +3 -16
  67. data/lib/active_support/core_ext/module/aliasing.rb +64 -68
  68. data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +1 -1
  69. data/lib/active_support/core_ext/module/attr_internal.rb +4 -4
  70. data/lib/active_support/core_ext/module/attribute_accessors.rb +36 -41
  71. data/lib/active_support/core_ext/module/delegation.rb +1 -1
  72. data/lib/active_support/core_ext/module/deprecation.rb +9 -0
  73. data/lib/active_support/core_ext/module/introspection.rb +77 -79
  74. data/lib/active_support/core_ext/module/loading.rb +2 -0
  75. data/lib/active_support/core_ext/module/synchronization.rb +4 -1
  76. data/lib/active_support/core_ext/name_error.rb +3 -4
  77. data/lib/active_support/core_ext/numeric.rb +1 -8
  78. data/lib/active_support/core_ext/numeric/bytes.rb +35 -41
  79. data/lib/active_support/core_ext/numeric/time.rb +70 -74
  80. data/lib/active_support/core_ext/object.rb +4 -2
  81. data/lib/active_support/core_ext/object/acts_like.rb +10 -0
  82. data/lib/active_support/core_ext/object/conversions.rb +4 -15
  83. data/lib/active_support/core_ext/object/duplicable.rb +65 -0
  84. data/lib/active_support/core_ext/object/instance_variables.rb +0 -7
  85. data/lib/active_support/core_ext/object/metaclass.rb +5 -6
  86. data/lib/active_support/core_ext/object/misc.rb +2 -93
  87. data/lib/active_support/core_ext/object/returning.rb +42 -0
  88. data/lib/active_support/core_ext/object/to_param.rb +49 -0
  89. data/lib/active_support/core_ext/object/to_query.rb +27 -0
  90. data/lib/active_support/core_ext/{try.rb → object/try.rb} +4 -4
  91. data/lib/active_support/core_ext/object/with_options.rb +24 -0
  92. data/lib/active_support/core_ext/proc.rb +6 -4
  93. data/lib/active_support/core_ext/process/daemon.rb +17 -19
  94. data/lib/active_support/core_ext/range.rb +2 -9
  95. data/lib/active_support/core_ext/range/blockless_step.rb +24 -27
  96. data/lib/active_support/core_ext/range/conversions.rb +17 -23
  97. data/lib/active_support/core_ext/range/include_range.rb +18 -27
  98. data/lib/active_support/core_ext/range/overlaps.rb +6 -13
  99. data/lib/active_support/core_ext/regexp.rb +5 -0
  100. data/lib/active_support/core_ext/rexml.rb +12 -7
  101. data/lib/active_support/core_ext/string.rb +6 -19
  102. data/lib/active_support/core_ext/string/access.rb +88 -95
  103. data/lib/active_support/core_ext/string/behavior.rb +6 -12
  104. data/lib/active_support/core_ext/string/conversions.rb +19 -21
  105. data/lib/active_support/core_ext/string/exclude.rb +6 -0
  106. data/lib/active_support/core_ext/string/filters.rb +17 -23
  107. data/lib/active_support/core_ext/string/inflections.rb +146 -153
  108. data/lib/active_support/{vendor/i18n-0.4.1/i18n/core_ext/string/interpolate.rb → core_ext/string/interpolation.rb} +8 -15
  109. data/lib/active_support/core_ext/string/multibyte.rb +68 -74
  110. data/lib/active_support/core_ext/string/output_safety.rb +21 -17
  111. data/lib/active_support/core_ext/string/starts_ends_with.rb +3 -32
  112. data/lib/active_support/core_ext/string/xchar.rb +10 -3
  113. data/lib/active_support/core_ext/time/acts_like.rb +8 -0
  114. data/lib/active_support/core_ext/time/calculations.rb +276 -308
  115. data/lib/active_support/core_ext/time/conversions.rb +78 -84
  116. data/lib/active_support/core_ext/time/marshal_with_utc_flag.rb +22 -0
  117. data/lib/active_support/core_ext/time/publicize_conversion_methods.rb +10 -0
  118. data/lib/active_support/core_ext/time/zones.rb +73 -81
  119. data/lib/active_support/core_ext/uri.rb +2 -1
  120. data/lib/active_support/dependencies.rb +38 -48
  121. data/lib/active_support/dependencies/autoload.rb +49 -0
  122. data/lib/active_support/deprecation.rb +9 -195
  123. data/lib/active_support/deprecation/behaviors.rb +38 -0
  124. data/lib/active_support/deprecation/method_wrappers.rb +29 -0
  125. data/lib/active_support/deprecation/proxy_wrappers.rb +74 -0
  126. data/lib/active_support/deprecation/reporting.rb +55 -0
  127. data/lib/active_support/duration.rb +6 -2
  128. data/lib/active_support/hash_with_indifferent_access.rb +137 -0
  129. data/lib/active_support/i18n.rb +2 -0
  130. data/lib/active_support/inflections.rb +1 -1
  131. data/lib/active_support/inflector.rb +4 -406
  132. data/lib/active_support/inflector/inflections.rb +211 -0
  133. data/lib/active_support/inflector/methods.rb +139 -0
  134. data/lib/active_support/inflector/transliterate.rb +61 -0
  135. data/lib/active_support/json/backends/jsongem.rb +16 -10
  136. data/lib/active_support/json/backends/yaml.rb +72 -2
  137. data/lib/active_support/json/decoding.rb +2 -16
  138. data/lib/active_support/json/encoding.rb +153 -33
  139. data/lib/active_support/json/variable.rb +4 -3
  140. data/lib/active_support/locale/en.yml +1 -4
  141. data/lib/active_support/memoizable.rb +7 -6
  142. data/lib/active_support/message_encryptor.rb +1 -0
  143. data/lib/active_support/message_verifier.rb +12 -29
  144. data/lib/active_support/multibyte.rb +9 -4
  145. data/lib/active_support/multibyte/chars.rb +25 -17
  146. data/lib/active_support/multibyte/unicode_database.rb +5 -5
  147. data/lib/active_support/multibyte/utils.rb +1 -1
  148. data/lib/active_support/notifications.rb +77 -0
  149. data/lib/active_support/notifications/fanout.rb +69 -0
  150. data/lib/active_support/notifications/instrumenter.rb +50 -0
  151. data/lib/active_support/option_merger.rb +2 -0
  152. data/lib/active_support/ordered_hash.rb +33 -37
  153. data/lib/active_support/ordered_options.rb +3 -1
  154. data/lib/active_support/railtie.rb +64 -0
  155. data/lib/active_support/rescuable.rb +11 -6
  156. data/lib/active_support/ruby/shim.rb +19 -0
  157. data/lib/active_support/test_case.rb +8 -1
  158. data/lib/active_support/testing/assertions.rb +2 -14
  159. data/lib/active_support/testing/declarative.rb +31 -12
  160. data/lib/active_support/testing/deprecation.rb +8 -10
  161. data/lib/active_support/testing/isolation.rb +153 -0
  162. data/lib/active_support/testing/pending.rb +48 -0
  163. data/lib/active_support/testing/performance.rb +342 -339
  164. data/lib/active_support/testing/setup_and_teardown.rb +48 -31
  165. data/lib/active_support/time.rb +34 -0
  166. data/lib/active_support/time/autoload.rb +5 -0
  167. data/lib/active_support/time_with_zone.rb +18 -12
  168. data/lib/active_support/values/time_zone.rb +97 -93
  169. data/lib/active_support/version.rb +3 -3
  170. data/lib/active_support/whiny_nil.rb +1 -4
  171. data/lib/active_support/xml_mini.rb +2 -0
  172. data/lib/active_support/xml_mini/jdom.rb +13 -7
  173. data/lib/active_support/xml_mini/libxml.rb +19 -12
  174. data/lib/active_support/xml_mini/libxmlsax.rb +19 -9
  175. data/lib/active_support/xml_mini/nokogiri.rb +18 -12
  176. data/lib/active_support/xml_mini/nokogirisax.rb +15 -6
  177. data/lib/active_support/xml_mini/rexml.rb +24 -9
  178. metadata +94 -244
  179. data/lib/active_support/cache/drb_store.rb +0 -14
  180. data/lib/active_support/core_ext/array/wrapper.rb +0 -24
  181. data/lib/active_support/core_ext/base64.rb +0 -4
  182. data/lib/active_support/core_ext/base64/encoding.rb +0 -16
  183. data/lib/active_support/core_ext/bigdecimal.rb +0 -6
  184. data/lib/active_support/core_ext/bigdecimal/conversions.rb +0 -37
  185. data/lib/active_support/core_ext/blank.rb +0 -2
  186. data/lib/active_support/core_ext/class/removal.rb +0 -50
  187. data/lib/active_support/core_ext/date.rb +0 -10
  188. data/lib/active_support/core_ext/date/behavior.rb +0 -42
  189. data/lib/active_support/core_ext/date_time.rb +0 -12
  190. data/lib/active_support/core_ext/duplicable.rb +0 -43
  191. data/lib/active_support/core_ext/float/time.rb +0 -27
  192. data/lib/active_support/core_ext/integer/even_odd.rb +0 -29
  193. data/lib/active_support/core_ext/kernel/singleton_class.rb +0 -13
  194. data/lib/active_support/core_ext/module/model_naming.rb +0 -25
  195. data/lib/active_support/core_ext/module/remove_method.rb +0 -6
  196. data/lib/active_support/core_ext/numeric/conversions.rb +0 -19
  197. data/lib/active_support/core_ext/object/extending.rb +0 -80
  198. data/lib/active_support/core_ext/object/singleton_class.rb +0 -13
  199. data/lib/active_support/core_ext/pathname.rb +0 -7
  200. data/lib/active_support/core_ext/pathname/clean_within.rb +0 -14
  201. data/lib/active_support/core_ext/string/bytesize.rb +0 -5
  202. data/lib/active_support/core_ext/string/iterators.rb +0 -23
  203. data/lib/active_support/core_ext/symbol.rb +0 -14
  204. data/lib/active_support/core_ext/time.rb +0 -46
  205. data/lib/active_support/core_ext/time/behavior.rb +0 -13
  206. data/lib/active_support/json/backends/okjson.rb +0 -644
  207. data/lib/active_support/json/backends/yajl.rb +0 -40
  208. data/lib/active_support/json/encoders/date.rb +0 -22
  209. data/lib/active_support/json/encoders/date_time.rb +0 -22
  210. data/lib/active_support/json/encoders/enumerable.rb +0 -17
  211. data/lib/active_support/json/encoders/false_class.rb +0 -7
  212. data/lib/active_support/json/encoders/hash.rb +0 -56
  213. data/lib/active_support/json/encoders/nil_class.rb +0 -7
  214. data/lib/active_support/json/encoders/numeric.rb +0 -21
  215. data/lib/active_support/json/encoders/object.rb +0 -10
  216. data/lib/active_support/json/encoders/regexp.rb +0 -9
  217. data/lib/active_support/json/encoders/string.rb +0 -9
  218. data/lib/active_support/json/encoders/symbol.rb +0 -5
  219. data/lib/active_support/json/encoders/time.rb +0 -22
  220. data/lib/active_support/json/encoders/true_class.rb +0 -7
  221. data/lib/active_support/vendor.rb +0 -36
  222. data/lib/active_support/vendor/builder-2.1.2/blankslate.rb +0 -113
  223. data/lib/active_support/vendor/builder-2.1.2/builder.rb +0 -13
  224. data/lib/active_support/vendor/builder-2.1.2/builder/blankslate.rb +0 -20
  225. data/lib/active_support/vendor/builder-2.1.2/builder/css.rb +0 -250
  226. data/lib/active_support/vendor/builder-2.1.2/builder/xchar.rb +0 -115
  227. data/lib/active_support/vendor/builder-2.1.2/builder/xmlbase.rb +0 -139
  228. data/lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb +0 -63
  229. data/lib/active_support/vendor/builder-2.1.2/builder/xmlmarkup.rb +0 -328
  230. data/lib/active_support/vendor/i18n-0.4.1/i18n.rb +0 -322
  231. data/lib/active_support/vendor/i18n-0.4.1/i18n/backend.rb +0 -20
  232. data/lib/active_support/vendor/i18n-0.4.1/i18n/backend/active_record.rb +0 -61
  233. data/lib/active_support/vendor/i18n-0.4.1/i18n/backend/active_record/missing.rb +0 -65
  234. data/lib/active_support/vendor/i18n-0.4.1/i18n/backend/active_record/store_procs.rb +0 -38
  235. data/lib/active_support/vendor/i18n-0.4.1/i18n/backend/active_record/translation.rb +0 -93
  236. data/lib/active_support/vendor/i18n-0.4.1/i18n/backend/base.rb +0 -237
  237. data/lib/active_support/vendor/i18n-0.4.1/i18n/backend/cache.rb +0 -77
  238. data/lib/active_support/vendor/i18n-0.4.1/i18n/backend/cascade.rb +0 -57
  239. data/lib/active_support/vendor/i18n-0.4.1/i18n/backend/chain.rb +0 -77
  240. data/lib/active_support/vendor/i18n-0.4.1/i18n/backend/cldr.rb +0 -100
  241. data/lib/active_support/vendor/i18n-0.4.1/i18n/backend/fallbacks.rb +0 -69
  242. data/lib/active_support/vendor/i18n-0.4.1/i18n/backend/flatten.rb +0 -113
  243. data/lib/active_support/vendor/i18n-0.4.1/i18n/backend/gettext.rb +0 -75
  244. data/lib/active_support/vendor/i18n-0.4.1/i18n/backend/interpolation_compiler.rb +0 -123
  245. data/lib/active_support/vendor/i18n-0.4.1/i18n/backend/key_value.rb +0 -102
  246. data/lib/active_support/vendor/i18n-0.4.1/i18n/backend/memoize.rb +0 -48
  247. data/lib/active_support/vendor/i18n-0.4.1/i18n/backend/metadata.rb +0 -65
  248. data/lib/active_support/vendor/i18n-0.4.1/i18n/backend/pluralization.rb +0 -57
  249. data/lib/active_support/vendor/i18n-0.4.1/i18n/backend/simple.rb +0 -87
  250. data/lib/active_support/vendor/i18n-0.4.1/i18n/backend/transliterator.rb +0 -98
  251. data/lib/active_support/vendor/i18n-0.4.1/i18n/config.rb +0 -84
  252. data/lib/active_support/vendor/i18n-0.4.1/i18n/core_ext/hash.rb +0 -29
  253. data/lib/active_support/vendor/i18n-0.4.1/i18n/exceptions.rb +0 -61
  254. data/lib/active_support/vendor/i18n-0.4.1/i18n/gettext.rb +0 -27
  255. data/lib/active_support/vendor/i18n-0.4.1/i18n/gettext/helpers.rb +0 -65
  256. data/lib/active_support/vendor/i18n-0.4.1/i18n/gettext/po_parser.rb +0 -329
  257. data/lib/active_support/vendor/i18n-0.4.1/i18n/locale.rb +0 -6
  258. data/lib/active_support/vendor/i18n-0.4.1/i18n/locale/fallbacks.rb +0 -98
  259. data/lib/active_support/vendor/i18n-0.4.1/i18n/locale/tag.rb +0 -28
  260. data/lib/active_support/vendor/i18n-0.4.1/i18n/locale/tag/parents.rb +0 -24
  261. data/lib/active_support/vendor/i18n-0.4.1/i18n/locale/tag/rfc4646.rb +0 -76
  262. data/lib/active_support/vendor/i18n-0.4.1/i18n/locale/tag/simple.rb +0 -41
  263. data/lib/active_support/vendor/i18n-0.4.1/i18n/version.rb +0 -3
  264. data/lib/active_support/vendor/memcache-client-1.7.4/memcache.rb +0 -1107
  265. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo.rb +0 -33
  266. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone.rb +0 -47
  267. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone_info.rb +0 -228
  268. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Algiers.rb +0 -55
  269. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Cairo.rb +0 -219
  270. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Casablanca.rb +0 -40
  271. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Harare.rb +0 -18
  272. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Johannesburg.rb +0 -25
  273. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Monrovia.rb +0 -22
  274. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Nairobi.rb +0 -23
  275. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Argentina/Buenos_Aires.rb +0 -166
  276. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Argentina/San_Juan.rb +0 -86
  277. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Bogota.rb +0 -23
  278. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Caracas.rb +0 -23
  279. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Chicago.rb +0 -283
  280. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Chihuahua.rb +0 -136
  281. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Denver.rb +0 -204
  282. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Godthab.rb +0 -161
  283. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Guatemala.rb +0 -27
  284. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Halifax.rb +0 -274
  285. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Indiana/Indianapolis.rb +0 -149
  286. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Juneau.rb +0 -194
  287. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/La_Paz.rb +0 -22
  288. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Lima.rb +0 -35
  289. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Los_Angeles.rb +0 -232
  290. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Mazatlan.rb +0 -139
  291. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Mexico_City.rb +0 -144
  292. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Monterrey.rb +0 -131
  293. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/New_York.rb +0 -282
  294. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Phoenix.rb +0 -30
  295. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Regina.rb +0 -74
  296. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Santiago.rb +0 -205
  297. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Sao_Paulo.rb +0 -171
  298. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/St_Johns.rb +0 -288
  299. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Tijuana.rb +0 -196
  300. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Almaty.rb +0 -67
  301. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Baghdad.rb +0 -73
  302. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Baku.rb +0 -161
  303. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Bangkok.rb +0 -20
  304. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Chongqing.rb +0 -33
  305. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Colombo.rb +0 -30
  306. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Dhaka.rb +0 -27
  307. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Hong_Kong.rb +0 -87
  308. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Irkutsk.rb +0 -165
  309. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Jakarta.rb +0 -30
  310. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Jerusalem.rb +0 -163
  311. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kabul.rb +0 -20
  312. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kamchatka.rb +0 -163
  313. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Karachi.rb +0 -30
  314. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Katmandu.rb +0 -20
  315. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kolkata.rb +0 -25
  316. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Krasnoyarsk.rb +0 -163
  317. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kuala_Lumpur.rb +0 -31
  318. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kuwait.rb +0 -18
  319. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Magadan.rb +0 -163
  320. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Muscat.rb +0 -18
  321. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Novosibirsk.rb +0 -164
  322. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Rangoon.rb +0 -24
  323. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Riyadh.rb +0 -18
  324. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Seoul.rb +0 -34
  325. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Shanghai.rb +0 -35
  326. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Singapore.rb +0 -33
  327. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Taipei.rb +0 -59
  328. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tashkent.rb +0 -47
  329. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tbilisi.rb +0 -78
  330. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tehran.rb +0 -121
  331. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tokyo.rb +0 -30
  332. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Ulaanbaatar.rb +0 -65
  333. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Urumqi.rb +0 -33
  334. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Vladivostok.rb +0 -164
  335. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yakutsk.rb +0 -163
  336. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yekaterinburg.rb +0 -165
  337. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yerevan.rb +0 -165
  338. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/Azores.rb +0 -270
  339. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/Cape_Verde.rb +0 -23
  340. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/South_Georgia.rb +0 -18
  341. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Adelaide.rb +0 -187
  342. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Brisbane.rb +0 -35
  343. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Darwin.rb +0 -29
  344. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Hobart.rb +0 -193
  345. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Melbourne.rb +0 -185
  346. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Perth.rb +0 -37
  347. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Sydney.rb +0 -185
  348. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Etc/UTC.rb +0 -16
  349. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Amsterdam.rb +0 -228
  350. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Athens.rb +0 -185
  351. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Belgrade.rb +0 -163
  352. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Berlin.rb +0 -188
  353. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Bratislava.rb +0 -13
  354. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Brussels.rb +0 -232
  355. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Bucharest.rb +0 -181
  356. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Budapest.rb +0 -197
  357. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Copenhagen.rb +0 -179
  358. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Dublin.rb +0 -276
  359. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Helsinki.rb +0 -163
  360. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Istanbul.rb +0 -218
  361. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Kiev.rb +0 -168
  362. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Lisbon.rb +0 -268
  363. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Ljubljana.rb +0 -13
  364. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/London.rb +0 -288
  365. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Madrid.rb +0 -211
  366. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Minsk.rb +0 -170
  367. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Moscow.rb +0 -181
  368. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Paris.rb +0 -232
  369. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Prague.rb +0 -187
  370. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Riga.rb +0 -176
  371. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Rome.rb +0 -215
  372. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Sarajevo.rb +0 -13
  373. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Skopje.rb +0 -13
  374. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Sofia.rb +0 -173
  375. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Stockholm.rb +0 -165
  376. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Tallinn.rb +0 -172
  377. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Vienna.rb +0 -183
  378. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Vilnius.rb +0 -170
  379. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Warsaw.rb +0 -212
  380. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Zagreb.rb +0 -13
  381. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Auckland.rb +0 -202
  382. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Fiji.rb +0 -23
  383. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Guam.rb +0 -22
  384. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Honolulu.rb +0 -28
  385. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Majuro.rb +0 -20
  386. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Midway.rb +0 -25
  387. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Noumea.rb +0 -25
  388. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Pago_Pago.rb +0 -26
  389. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Port_Moresby.rb +0 -20
  390. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Tongatapu.rb +0 -27
  391. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/info_timezone.rb +0 -52
  392. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/linked_timezone.rb +0 -51
  393. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/linked_timezone_info.rb +0 -44
  394. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/offset_rationals.rb +0 -98
  395. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/ruby_core_support.rb +0 -56
  396. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/time_or_datetime.rb +0 -292
  397. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone.rb +0 -508
  398. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_definition.rb +0 -56
  399. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_info.rb +0 -40
  400. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_offset_info.rb +0 -94
  401. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_period.rb +0 -198
  402. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_transition_info.rb +0 -129
  403. data/lib/activesupport.rb +0 -2
@@ -1,13 +0,0 @@
1
- class Object
2
- # Returns the object's singleton class.
3
- def singleton_class
4
- class << self
5
- self
6
- end
7
- end unless respond_to?(:singleton_class)
8
-
9
- # class_eval on an object acts like singleton_class_eval.
10
- def class_eval(*args, &block)
11
- singleton_class.class_eval(*args, &block)
12
- end
13
- end
@@ -1,7 +0,0 @@
1
- require 'pathname'
2
- require 'active_support/core_ext/pathname/clean_within'
3
-
4
- class Pathname#:nodoc:
5
- extend ActiveSupport::CoreExtensions::Pathname::CleanWithin
6
- end
7
-
@@ -1,14 +0,0 @@
1
- module ActiveSupport #:nodoc:
2
- module CoreExtensions #:nodoc:
3
- module Pathname #:nodoc:
4
- module CleanWithin
5
- # Clean the paths contained in the provided string.
6
- def clean_within(string)
7
- string.gsub(%r{[\w. ]+(/[\w. ]+)+(\.rb)?(\b|$)}) do |path|
8
- new(path).cleanpath
9
- end
10
- end
11
- end
12
- end
13
- end
14
- end
@@ -1,5 +0,0 @@
1
- unless '1.9'.respond_to?(:bytesize)
2
- class String
3
- alias :bytesize :size
4
- end
5
- end
@@ -1,23 +0,0 @@
1
- require 'strscan'
2
-
3
- module ActiveSupport #:nodoc:
4
- module CoreExtensions #:nodoc:
5
- module String #:nodoc:
6
- # Custom string iterators
7
- module Iterators
8
- def self.append_features(base)
9
- super unless '1.9'.respond_to?(:each_char)
10
- end
11
-
12
- # Yields a single-character string for each character in the string.
13
- # When $KCODE = 'UTF8', multi-byte characters are yielded appropriately.
14
- def each_char
15
- scanner, char = StringScanner.new(self), /./mu
16
- while c = scanner.scan(char)
17
- yield c
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end
@@ -1,14 +0,0 @@
1
- unless :to_proc.respond_to?(:to_proc)
2
- class Symbol
3
- # Turns the symbol into a simple proc, which is especially useful for enumerations. Examples:
4
- #
5
- # # The same as people.collect { |p| p.name }
6
- # people.collect(&:name)
7
- #
8
- # # The same as people.select { |p| p.manager? }.collect { |p| p.salary }
9
- # people.select(&:manager?).collect(&:salary)
10
- def to_proc
11
- Proc.new { |*args| args.shift.__send__(self, *args) }
12
- end
13
- end
14
- end
@@ -1,46 +0,0 @@
1
- require 'date'
2
- require 'time'
3
-
4
- class Time
5
- # Ruby 1.8-cvs and 1.9 define private Time#to_date
6
- %w(to_date to_datetime).each do |method|
7
- public method if private_instance_methods.include?(method)
8
- end
9
-
10
- # Pre-1.9 versions of Ruby have a bug with marshaling Time instances, where utc instances are
11
- # unmarshaled in the local zone, instead of utc. We're layering behavior on the _dump and _load
12
- # methods so that utc instances can be flagged on dump, and coerced back to utc on load.
13
- if RUBY_VERSION < '1.9'
14
- class << self
15
- alias_method :_original_load, :_load
16
- def _load(marshaled_time)
17
- time = _original_load(marshaled_time)
18
- time.instance_eval do
19
- if defined?(@marshal_with_utc_coercion)
20
- val = remove_instance_variable("@marshal_with_utc_coercion")
21
- end
22
- val ? utc : self
23
- end
24
- end
25
- end
26
-
27
- alias_method :_original_dump, :_dump
28
- def _dump(*args)
29
- obj = dup
30
- obj.instance_variable_set('@marshal_with_utc_coercion', utc?)
31
- obj._original_dump(*args)
32
- end
33
- end
34
- end
35
-
36
- require 'active_support/core_ext/time/behavior'
37
- require 'active_support/core_ext/time/calculations'
38
- require 'active_support/core_ext/time/conversions'
39
- require 'active_support/core_ext/time/zones'
40
-
41
- class Time#:nodoc:
42
- include ActiveSupport::CoreExtensions::Time::Behavior
43
- include ActiveSupport::CoreExtensions::Time::Calculations
44
- include ActiveSupport::CoreExtensions::Time::Conversions
45
- include ActiveSupport::CoreExtensions::Time::Zones
46
- end
@@ -1,13 +0,0 @@
1
- module ActiveSupport #:nodoc:
2
- module CoreExtensions #:nodoc:
3
- module Time #:nodoc:
4
- module Behavior
5
- # Enable more predictable duck-typing on Time-like classes. See
6
- # Object#acts_like?.
7
- def acts_like_time?
8
- true
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,644 +0,0 @@
1
- module ActiveSupport
2
- # Include OkJson as a replacement for the Yaml backend
3
- # encoding: UTF-8
4
- #
5
- # Copyright 2011, 2012 Keith Rarick
6
- #
7
- # Permission is hereby granted, free of charge, to any person obtaining a copy
8
- # of this software and associated documentation files (the "Software"), to deal
9
- # in the Software without restriction, including without limitation the rights
10
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
- # copies of the Software, and to permit persons to whom the Software is
12
- # furnished to do so, subject to the following conditions:
13
- #
14
- # The above copyright notice and this permission notice shall be included in
15
- # all copies or substantial portions of the Software.
16
- #
17
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
- # THE SOFTWARE.
24
-
25
- # See https://github.com/kr/okjson for updates.
26
-
27
- require 'stringio'
28
-
29
- # Some parts adapted from
30
- # http://golang.org/src/pkg/json/decode.go and
31
- # http://golang.org/src/pkg/utf8/utf8.go
32
- module OkJson
33
- Upstream = 'LTD7LBKLZWFF7OZK'
34
- extend self
35
-
36
-
37
- # Decodes a json document in string s and
38
- # returns the corresponding ruby value.
39
- # String s must be valid UTF-8. If you have
40
- # a string in some other encoding, convert
41
- # it first.
42
- #
43
- # String values in the resulting structure
44
- # will be UTF-8.
45
- def decode(s)
46
- ts = lex(s)
47
- v, ts = textparse(ts)
48
- if ts.length > 0
49
- raise Error, 'trailing garbage'
50
- end
51
- v
52
- end
53
-
54
-
55
- # Parses a "json text" in the sense of RFC 4627.
56
- # Returns the parsed value and any trailing tokens.
57
- # Note: this is almost the same as valparse,
58
- # except that it does not accept atomic values.
59
- def textparse(ts)
60
- if ts.length < 0
61
- raise Error, 'empty'
62
- end
63
-
64
- typ, _, val = ts[0]
65
- case typ
66
- when '{' then objparse(ts)
67
- when '[' then arrparse(ts)
68
- else
69
- raise Error, "unexpected #{val.inspect}"
70
- end
71
- end
72
-
73
-
74
- # Parses a "value" in the sense of RFC 4627.
75
- # Returns the parsed value and any trailing tokens.
76
- def valparse(ts)
77
- if ts.length < 0
78
- raise Error, 'empty'
79
- end
80
-
81
- typ, _, val = ts[0]
82
- case typ
83
- when '{' then objparse(ts)
84
- when '[' then arrparse(ts)
85
- when :val,:str then [val, ts[1..-1]]
86
- else
87
- raise Error, "unexpected #{val.inspect}"
88
- end
89
- end
90
-
91
-
92
- # Parses an "object" in the sense of RFC 4627.
93
- # Returns the parsed value and any trailing tokens.
94
- def objparse(ts)
95
- ts = eat('{', ts)
96
- obj = {}
97
-
98
- if ts[0][0] == '}'
99
- return obj, ts[1..-1]
100
- end
101
-
102
- k, v, ts = pairparse(ts)
103
- obj[k] = v
104
-
105
- if ts[0][0] == '}'
106
- return obj, ts[1..-1]
107
- end
108
-
109
- loop do
110
- ts = eat(',', ts)
111
-
112
- k, v, ts = pairparse(ts)
113
- obj[k] = v
114
-
115
- if ts[0][0] == '}'
116
- return obj, ts[1..-1]
117
- end
118
- end
119
- end
120
-
121
-
122
- # Parses a "member" in the sense of RFC 4627.
123
- # Returns the parsed values and any trailing tokens.
124
- def pairparse(ts)
125
- (typ, _, k), ts = ts[0], ts[1..-1]
126
- if typ != :str
127
- raise Error, "unexpected #{k.inspect}"
128
- end
129
- ts = eat(':', ts)
130
- v, ts = valparse(ts)
131
- [k, v, ts]
132
- end
133
-
134
-
135
- # Parses an "array" in the sense of RFC 4627.
136
- # Returns the parsed value and any trailing tokens.
137
- def arrparse(ts)
138
- ts = eat('[', ts)
139
- arr = []
140
-
141
- if ts[0][0] == ']'
142
- return arr, ts[1..-1]
143
- end
144
-
145
- v, ts = valparse(ts)
146
- arr << v
147
-
148
- if ts[0][0] == ']'
149
- return arr, ts[1..-1]
150
- end
151
-
152
- loop do
153
- ts = eat(',', ts)
154
-
155
- v, ts = valparse(ts)
156
- arr << v
157
-
158
- if ts[0][0] == ']'
159
- return arr, ts[1..-1]
160
- end
161
- end
162
- end
163
-
164
-
165
- def eat(typ, ts)
166
- if ts[0][0] != typ
167
- raise Error, "expected #{typ} (got #{ts[0].inspect})"
168
- end
169
- ts[1..-1]
170
- end
171
-
172
-
173
- # Scans s and returns a list of json tokens,
174
- # excluding white space (as defined in RFC 4627).
175
- def lex(s)
176
- ts = []
177
- while s.length > 0
178
- typ, lexeme, val = tok(s)
179
- if typ == nil
180
- raise Error, "invalid character at #{s[0,10].inspect}"
181
- end
182
- if typ != :space
183
- ts << [typ, lexeme, val]
184
- end
185
- s = s[lexeme.length..-1]
186
- end
187
- ts
188
- end
189
-
190
-
191
- # Scans the first token in s and
192
- # returns a 3-element list, or nil
193
- # if s does not begin with a valid token.
194
- #
195
- # The first list element is one of
196
- # '{', '}', ':', ',', '[', ']',
197
- # :val, :str, and :space.
198
- #
199
- # The second element is the lexeme.
200
- #
201
- # The third element is the value of the
202
- # token for :val and :str, otherwise
203
- # it is the lexeme.
204
- def tok(s)
205
- case s[0]
206
- when ?{ then ['{', s[0,1], s[0,1]]
207
- when ?} then ['}', s[0,1], s[0,1]]
208
- when ?: then [':', s[0,1], s[0,1]]
209
- when ?, then [',', s[0,1], s[0,1]]
210
- when ?[ then ['[', s[0,1], s[0,1]]
211
- when ?] then [']', s[0,1], s[0,1]]
212
- when ?n then nulltok(s)
213
- when ?t then truetok(s)
214
- when ?f then falsetok(s)
215
- when ?" then strtok(s)
216
- when Spc then [:space, s[0,1], s[0,1]]
217
- when ?\t then [:space, s[0,1], s[0,1]]
218
- when ?\n then [:space, s[0,1], s[0,1]]
219
- when ?\r then [:space, s[0,1], s[0,1]]
220
- else numtok(s)
221
- end
222
- end
223
-
224
-
225
- def nulltok(s); s[0,4] == 'null' ? [:val, 'null', nil] : [] end
226
- def truetok(s); s[0,4] == 'true' ? [:val, 'true', true] : [] end
227
- def falsetok(s); s[0,5] == 'false' ? [:val, 'false', false] : [] end
228
-
229
-
230
- def numtok(s)
231
- m = /-?([1-9][0-9]+|[0-9])([.][0-9]+)?([eE][+-]?[0-9]+)?/.match(s)
232
- if m && m.begin(0) == 0
233
- if m[3] && !m[2]
234
- [:val, m[0], Integer(m[1])*(10**Integer(m[3][1..-1]))]
235
- elsif m[2]
236
- [:val, m[0], Float(m[0])]
237
- else
238
- [:val, m[0], Integer(m[0])]
239
- end
240
- else
241
- []
242
- end
243
- end
244
-
245
-
246
- def strtok(s)
247
- m = /"([^"\\]|\\["\/\\bfnrt]|\\u[0-9a-fA-F]{4})*"/.match(s)
248
- if ! m
249
- raise Error, "invalid string literal at #{abbrev(s)}"
250
- end
251
- [:str, m[0], unquote(m[0])]
252
- end
253
-
254
-
255
- def abbrev(s)
256
- t = s[0,10]
257
- p = t['`']
258
- t = t[0,p] if p
259
- t = t + '...' if t.length < s.length
260
- '`' + t + '`'
261
- end
262
-
263
-
264
- # Converts a quoted json string literal q into a UTF-8-encoded string.
265
- # The rules are different than for Ruby, so we cannot use eval.
266
- # Unquote will raise an error if q contains control characters.
267
- def unquote(q)
268
- q = q[1...-1]
269
- a = q.dup # allocate a big enough string
270
- rubydoesenc = false
271
- # In ruby >= 1.9, a[w] is a codepoint, not a byte.
272
- if a.class.method_defined?(:force_encoding)
273
- a.force_encoding('UTF-8')
274
- rubydoesenc = true
275
- end
276
- r, w = 0, 0
277
- while r < q.length
278
- c = q[r]
279
- case true
280
- when c == ?\\
281
- r += 1
282
- if r >= q.length
283
- raise Error, "string literal ends with a \"\\\": \"#{q}\""
284
- end
285
-
286
- case q[r]
287
- when ?",?\\,?/,?'
288
- a[w] = q[r]
289
- r += 1
290
- w += 1
291
- when ?b,?f,?n,?r,?t
292
- a[w] = Unesc[q[r]]
293
- r += 1
294
- w += 1
295
- when ?u
296
- r += 1
297
- uchar = begin
298
- hexdec4(q[r,4])
299
- rescue RuntimeError => e
300
- raise Error, "invalid escape sequence \\u#{q[r,4]}: #{e}"
301
- end
302
- r += 4
303
- if surrogate? uchar
304
- if q.length >= r+6
305
- uchar1 = hexdec4(q[r+2,4])
306
- uchar = subst(uchar, uchar1)
307
- if uchar != Ucharerr
308
- # A valid pair; consume.
309
- r += 6
310
- end
311
- end
312
- end
313
- if rubydoesenc
314
- a[w] = '' << uchar
315
- w += 1
316
- else
317
- w += ucharenc(a, w, uchar)
318
- end
319
- else
320
- raise Error, "invalid escape char #{q[r]} in \"#{q}\""
321
- end
322
- when c == ?", c < Spc
323
- raise Error, "invalid character in string literal \"#{q}\""
324
- else
325
- # Copy anything else byte-for-byte.
326
- # Valid UTF-8 will remain valid UTF-8.
327
- # Invalid UTF-8 will remain invalid UTF-8.
328
- # In ruby >= 1.9, c is a codepoint, not a byte,
329
- # in which case this is still what we want.
330
- a[w] = c
331
- r += 1
332
- w += 1
333
- end
334
- end
335
- a[0,w]
336
- end
337
-
338
-
339
- # Encodes unicode character u as UTF-8
340
- # bytes in string a at position i.
341
- # Returns the number of bytes written.
342
- def ucharenc(a, i, u)
343
- case true
344
- when u <= Uchar1max
345
- a[i] = (u & 0xff).chr
346
- 1
347
- when u <= Uchar2max
348
- a[i+0] = (Utag2 | ((u>>6)&0xff)).chr
349
- a[i+1] = (Utagx | (u&Umaskx)).chr
350
- 2
351
- when u <= Uchar3max
352
- a[i+0] = (Utag3 | ((u>>12)&0xff)).chr
353
- a[i+1] = (Utagx | ((u>>6)&Umaskx)).chr
354
- a[i+2] = (Utagx | (u&Umaskx)).chr
355
- 3
356
- else
357
- a[i+0] = (Utag4 | ((u>>18)&0xff)).chr
358
- a[i+1] = (Utagx | ((u>>12)&Umaskx)).chr
359
- a[i+2] = (Utagx | ((u>>6)&Umaskx)).chr
360
- a[i+3] = (Utagx | (u&Umaskx)).chr
361
- 4
362
- end
363
- end
364
-
365
-
366
- def hexdec4(s)
367
- if s.length != 4
368
- raise Error, 'short'
369
- end
370
- (nibble(s[0])<<12) | (nibble(s[1])<<8) | (nibble(s[2])<<4) | nibble(s[3])
371
- end
372
-
373
-
374
- def subst(u1, u2)
375
- if Usurr1 <= u1 && u1 < Usurr2 && Usurr2 <= u2 && u2 < Usurr3
376
- return ((u1-Usurr1)<<10) | (u2-Usurr2) + Usurrself
377
- end
378
- return Ucharerr
379
- end
380
-
381
-
382
- def surrogate?(u)
383
- Usurr1 <= u && u < Usurr3
384
- end
385
-
386
-
387
- def nibble(c)
388
- case true
389
- when ?0 <= c && c <= ?9 then c.ord - ?0.ord
390
- when ?a <= c && c <= ?z then c.ord - ?a.ord + 10
391
- when ?A <= c && c <= ?Z then c.ord - ?A.ord + 10
392
- else
393
- raise Error, "invalid hex code #{c}"
394
- end
395
- end
396
-
397
-
398
- # Encodes x into a json text. It may contain only
399
- # Array, Hash, String, Numeric, true, false, nil.
400
- # (Note, this list excludes Symbol.)
401
- # X itself must be an Array or a Hash.
402
- # No other value can be encoded, and an error will
403
- # be raised if x contains any other value, such as
404
- # Nan, Infinity, Symbol, and Proc, or if a Hash key
405
- # is not a String.
406
- # Strings contained in x must be valid UTF-8.
407
- def encode(x)
408
- case x
409
- when Hash then objenc(x)
410
- when Array then arrenc(x)
411
- else
412
- raise Error, 'root value must be an Array or a Hash'
413
- end
414
- end
415
-
416
-
417
- def valenc(x)
418
- case x
419
- when Hash then objenc(x)
420
- when Array then arrenc(x)
421
- when String then strenc(x)
422
- when Numeric then numenc(x)
423
- when true then "true"
424
- when false then "false"
425
- when nil then "null"
426
- else
427
- raise Error, "cannot encode #{x.class}: #{x.inspect}"
428
- end
429
- end
430
-
431
-
432
- def objenc(x)
433
- '{' + x.map{|k,v| keyenc(k) + ':' + valenc(v)}.join(',') + '}'
434
- end
435
-
436
-
437
- def arrenc(a)
438
- '[' + a.map{|x| valenc(x)}.join(',') + ']'
439
- end
440
-
441
-
442
- def keyenc(k)
443
- case k
444
- when String then strenc(k)
445
- else
446
- raise Error, "Hash key is not a string: #{k.inspect}"
447
- end
448
- end
449
-
450
-
451
- def strenc(s)
452
- t = StringIO.new
453
- t.putc(?")
454
- r = 0
455
-
456
- # In ruby >= 1.9, s[r] is a codepoint, not a byte.
457
- rubydoesenc = s.class.method_defined?(:encoding)
458
-
459
- while r < s.length
460
- case s[r]
461
- when ?" then t.print('\\"')
462
- when ?\\ then t.print('\\\\')
463
- when ?\b then t.print('\\b')
464
- when ?\f then t.print('\\f')
465
- when ?\n then t.print('\\n')
466
- when ?\r then t.print('\\r')
467
- when ?\t then t.print('\\t')
468
- else
469
- c = s[r]
470
- case true
471
- when rubydoesenc
472
- begin
473
- c.ord # will raise an error if c is invalid UTF-8
474
- t.write(c)
475
- rescue
476
- t.write(Ustrerr)
477
- end
478
- when Spc <= c && c <= ?~
479
- t.putc(c)
480
- else
481
- n = ucharcopy(t, s, r) # ensure valid UTF-8 output
482
- r += n - 1 # r is incremented below
483
- end
484
- end
485
- r += 1
486
- end
487
- t.putc(?")
488
- t.string
489
- end
490
-
491
-
492
- def numenc(x)
493
- if ((x.nan? || x.infinite?) rescue false)
494
- raise Error, "Numeric cannot be represented: #{x}"
495
- end
496
- "#{x}"
497
- end
498
-
499
-
500
- # Copies the valid UTF-8 bytes of a single character
501
- # from string s at position i to I/O object t, and
502
- # returns the number of bytes copied.
503
- # If no valid UTF-8 char exists at position i,
504
- # ucharcopy writes Ustrerr and returns 1.
505
- def ucharcopy(t, s, i)
506
- n = s.length - i
507
- raise Utf8Error if n < 1
508
-
509
- c0 = s[i].ord
510
-
511
- # 1-byte, 7-bit sequence?
512
- if c0 < Utagx
513
- t.putc(c0)
514
- return 1
515
- end
516
-
517
- raise Utf8Error if c0 < Utag2 # unexpected continuation byte?
518
-
519
- raise Utf8Error if n < 2 # need continuation byte
520
- c1 = s[i+1].ord
521
- raise Utf8Error if c1 < Utagx || Utag2 <= c1
522
-
523
- # 2-byte, 11-bit sequence?
524
- if c0 < Utag3
525
- raise Utf8Error if ((c0&Umask2)<<6 | (c1&Umaskx)) <= Uchar1max
526
- t.putc(c0)
527
- t.putc(c1)
528
- return 2
529
- end
530
-
531
- # need second continuation byte
532
- raise Utf8Error if n < 3
533
-
534
- c2 = s[i+2].ord
535
- raise Utf8Error if c2 < Utagx || Utag2 <= c2
536
-
537
- # 3-byte, 16-bit sequence?
538
- if c0 < Utag4
539
- u = (c0&Umask3)<<12 | (c1&Umaskx)<<6 | (c2&Umaskx)
540
- raise Utf8Error if u <= Uchar2max
541
- t.putc(c0)
542
- t.putc(c1)
543
- t.putc(c2)
544
- return 3
545
- end
546
-
547
- # need third continuation byte
548
- raise Utf8Error if n < 4
549
- c3 = s[i+3].ord
550
- raise Utf8Error if c3 < Utagx || Utag2 <= c3
551
-
552
- # 4-byte, 21-bit sequence?
553
- if c0 < Utag5
554
- u = (c0&Umask4)<<18 | (c1&Umaskx)<<12 | (c2&Umaskx)<<6 | (c3&Umaskx)
555
- raise Utf8Error if u <= Uchar3max
556
- t.putc(c0)
557
- t.putc(c1)
558
- t.putc(c2)
559
- t.putc(c3)
560
- return 4
561
- end
562
-
563
- raise Utf8Error
564
- rescue Utf8Error
565
- t.write(Ustrerr)
566
- return 1
567
- end
568
-
569
-
570
- class Utf8Error < ::StandardError
571
- end
572
-
573
-
574
- class Error < ::StandardError
575
- end
576
-
577
-
578
- Utagx = 0x80 # 1000 0000
579
- Utag2 = 0xc0 # 1100 0000
580
- Utag3 = 0xe0 # 1110 0000
581
- Utag4 = 0xf0 # 1111 0000
582
- Utag5 = 0xF8 # 1111 1000
583
- Umaskx = 0x3f # 0011 1111
584
- Umask2 = 0x1f # 0001 1111
585
- Umask3 = 0x0f # 0000 1111
586
- Umask4 = 0x07 # 0000 0111
587
- Uchar1max = (1<<7) - 1
588
- Uchar2max = (1<<11) - 1
589
- Uchar3max = (1<<16) - 1
590
- Ucharerr = 0xFFFD # unicode "replacement char"
591
- Ustrerr = "\xef\xbf\xbd" # unicode "replacement char"
592
- Usurrself = 0x10000
593
- Usurr1 = 0xd800
594
- Usurr2 = 0xdc00
595
- Usurr3 = 0xe000
596
-
597
- Spc = ' '[0]
598
- Unesc = {?b=>?\b, ?f=>?\f, ?n=>?\n, ?r=>?\r, ?t=>?\t}
599
- end
600
-
601
- module JSON
602
- module Backends
603
- module OkJson
604
- ParseError = ::ActiveSupport::OkJson::Error
605
- extend self
606
-
607
- # Parses a JSON string or IO and convert it into an object
608
- def decode(json)
609
- if json.respond_to?(:read)
610
- json = json.read
611
- end
612
- data = ActiveSupport::OkJson.decode(json)
613
- if ActiveSupport.parse_json_times
614
- convert_dates_from(data)
615
- else
616
- data
617
- end
618
- end
619
-
620
- private
621
- def convert_dates_from(data)
622
- case data
623
- when nil
624
- nil
625
- when DATE_REGEX
626
- begin
627
- DateTime.parse(data)
628
- rescue ArgumentError
629
- data
630
- end
631
- when Array
632
- data.map! { |d| convert_dates_from(d) }
633
- when Hash
634
- data.each do |key, value|
635
- data[key] = convert_dates_from(value)
636
- end
637
- else
638
- data
639
- end
640
- end
641
- end
642
- end
643
- end
644
- end