activesupport 3.0.0.beta4 → 3.0.pre

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 (333) hide show
  1. data/CHANGELOG +1 -100
  2. data/lib/active_support.rb +4 -38
  3. data/lib/active_support/autoload.rb +28 -0
  4. data/lib/active_support/backtrace_cleaner.rb +9 -31
  5. data/lib/active_support/benchmarkable.rb +0 -1
  6. data/lib/active_support/buffered_logger.rb +1 -0
  7. data/lib/active_support/cache.rb +81 -436
  8. data/lib/active_support/cache/compressed_mem_cache_store.rb +13 -6
  9. data/lib/active_support/cache/file_store.rb +41 -139
  10. data/lib/active_support/cache/mem_cache_store.rb +75 -120
  11. data/lib/active_support/cache/memory_store.rb +27 -127
  12. data/lib/active_support/cache/strategy/local_cache.rb +58 -111
  13. data/lib/active_support/cache/synchronized_memory_store.rb +38 -2
  14. data/lib/active_support/callbacks.rb +48 -87
  15. data/lib/active_support/configurable.rb +18 -19
  16. data/lib/active_support/core_ext/array.rb +0 -1
  17. data/lib/active_support/core_ext/array/access.rb +1 -1
  18. data/lib/active_support/core_ext/array/conversions.rb +54 -29
  19. data/lib/active_support/core_ext/array/extract_options.rb +1 -16
  20. data/lib/active_support/core_ext/array/random_access.rb +5 -19
  21. data/lib/active_support/core_ext/array/wrap.rb +9 -13
  22. data/lib/active_support/core_ext/benchmark.rb +12 -0
  23. data/lib/active_support/core_ext/boolean.rb +1 -0
  24. data/lib/active_support/core_ext/boolean/conversions.rb +11 -0
  25. data/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +0 -2
  26. data/lib/active_support/core_ext/class.rb +1 -1
  27. data/lib/active_support/core_ext/class/attribute_accessors.rb +27 -33
  28. data/lib/active_support/core_ext/class/delegating_attributes.rb +41 -35
  29. data/lib/active_support/core_ext/class/inheritable_attributes.rb +13 -22
  30. data/lib/active_support/core_ext/class/removal.rb +53 -0
  31. data/lib/active_support/core_ext/date.rb +7 -0
  32. data/lib/active_support/core_ext/date/calculations.rb +8 -30
  33. data/lib/active_support/core_ext/date/conversions.rb +2 -2
  34. data/lib/active_support/core_ext/date_time.rb +5 -0
  35. data/lib/active_support/core_ext/date_time/calculations.rb +1 -2
  36. data/lib/active_support/core_ext/date_time/conversions.rb +5 -23
  37. data/lib/active_support/core_ext/enumerable.rb +9 -5
  38. data/lib/active_support/core_ext/exception.rb +47 -0
  39. data/lib/active_support/core_ext/file.rb +0 -1
  40. data/lib/active_support/core_ext/file/atomic.rb +2 -3
  41. data/lib/active_support/core_ext/float/rounding.rb +2 -3
  42. data/lib/active_support/core_ext/hash/conversions.rb +145 -65
  43. data/lib/active_support/core_ext/hash/deep_merge.rb +7 -6
  44. data/lib/active_support/core_ext/hash/except.rb +0 -8
  45. data/lib/active_support/core_ext/hash/indifferent_access.rb +0 -5
  46. data/lib/active_support/core_ext/hash/keys.rb +11 -10
  47. data/lib/active_support/core_ext/hash/slice.rb +0 -6
  48. data/lib/active_support/core_ext/integer.rb +1 -1
  49. data/lib/active_support/core_ext/integer/even_odd.rb +16 -0
  50. data/lib/active_support/core_ext/kernel.rb +1 -1
  51. data/lib/active_support/core_ext/kernel/daemonizing.rb +7 -0
  52. data/lib/active_support/core_ext/kernel/debugger.rb +2 -3
  53. data/lib/active_support/core_ext/kernel/reporting.rb +1 -2
  54. data/lib/active_support/core_ext/load_error.rb +30 -17
  55. data/lib/active_support/core_ext/logger.rb +1 -1
  56. data/lib/active_support/core_ext/module.rb +3 -5
  57. data/lib/active_support/core_ext/module/aliasing.rb +1 -1
  58. data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +1 -1
  59. data/lib/active_support/core_ext/module/attr_internal.rb +2 -2
  60. data/lib/active_support/core_ext/module/attribute_accessors.rb +21 -25
  61. data/lib/active_support/core_ext/module/delegation.rb +10 -21
  62. data/lib/active_support/core_ext/module/inclusion.rb +30 -0
  63. data/lib/active_support/core_ext/module/introspection.rb +8 -8
  64. data/lib/active_support/core_ext/module/loading.rb +23 -0
  65. data/lib/active_support/core_ext/module/synchronization.rb +1 -2
  66. data/lib/active_support/core_ext/name_error.rb +1 -3
  67. data/lib/active_support/core_ext/nil.rb +1 -0
  68. data/lib/active_support/core_ext/nil/conversions.rb +5 -0
  69. data/lib/active_support/core_ext/object.rb +2 -6
  70. data/lib/active_support/core_ext/object/blank.rb +2 -20
  71. data/lib/active_support/core_ext/object/conversions.rb +16 -2
  72. data/lib/active_support/core_ext/object/duplicable.rb +1 -23
  73. data/lib/active_support/core_ext/object/extending.rb +77 -8
  74. data/lib/active_support/core_ext/object/instance_variables.rb +7 -0
  75. data/lib/active_support/core_ext/object/metaclass.rb +13 -0
  76. data/lib/active_support/core_ext/object/misc.rb +1 -0
  77. data/lib/active_support/core_ext/object/tap.rb +16 -0
  78. data/lib/active_support/core_ext/object/with_options.rb +0 -2
  79. data/lib/active_support/core_ext/proc.rb +4 -4
  80. data/lib/active_support/core_ext/regexp.rb +22 -0
  81. data/lib/active_support/core_ext/rexml.rb +1 -4
  82. data/lib/active_support/core_ext/string.rb +2 -3
  83. data/lib/active_support/core_ext/string/access.rb +2 -4
  84. data/lib/active_support/core_ext/string/bytesize.rb +5 -0
  85. data/lib/active_support/core_ext/string/conversions.rb +1 -36
  86. data/lib/active_support/core_ext/string/filters.rb +0 -29
  87. data/lib/active_support/core_ext/string/inflections.rb +12 -1
  88. data/lib/active_support/core_ext/string/interpolation.rb +92 -2
  89. data/lib/active_support/core_ext/string/iterators.rb +13 -0
  90. data/lib/active_support/core_ext/string/multibyte.rb +19 -16
  91. data/lib/active_support/core_ext/string/output_safety.rb +35 -101
  92. data/lib/active_support/core_ext/string/starts_ends_with.rb +14 -0
  93. data/lib/active_support/core_ext/string/xchar.rb +1 -1
  94. data/lib/active_support/core_ext/symbol.rb +1 -0
  95. data/lib/active_support/core_ext/symbol/to_proc.rb +14 -0
  96. data/lib/active_support/core_ext/time.rb +10 -0
  97. data/lib/active_support/core_ext/time/calculations.rb +7 -9
  98. data/lib/active_support/core_ext/time/conversions.rb +0 -1
  99. data/lib/active_support/core_ext/time/marshal_with_utc_flag.rb +22 -0
  100. data/lib/active_support/core_ext/uri.rb +4 -10
  101. data/lib/active_support/dependencies.rb +192 -179
  102. data/lib/active_support/deprecated_callbacks.rb +283 -0
  103. data/lib/active_support/deprecation/behaviors.rb +1 -1
  104. data/lib/active_support/deprecation/method_wrappers.rb +9 -10
  105. data/lib/active_support/deprecation/reporting.rb +1 -2
  106. data/lib/active_support/duration.rb +2 -6
  107. data/lib/active_support/hash_with_indifferent_access.rb +1 -9
  108. data/lib/active_support/inflections.rb +1 -1
  109. data/lib/active_support/inflector.rb +407 -4
  110. data/lib/active_support/json/backends/jsongem.rb +9 -12
  111. data/lib/active_support/json/decoding.rb +1 -16
  112. data/lib/active_support/json/encoding.rb +12 -42
  113. data/lib/active_support/locale/en.yml +1 -4
  114. data/lib/active_support/memoizable.rb +1 -1
  115. data/lib/active_support/message_encryptor.rb +0 -1
  116. data/lib/active_support/message_verifier.rb +5 -6
  117. data/lib/active_support/multibyte.rb +22 -7
  118. data/lib/active_support/multibyte/chars.rb +392 -164
  119. data/lib/active_support/multibyte/unicode_database.rb +71 -0
  120. data/lib/active_support/multibyte/utils.rb +7 -6
  121. data/lib/active_support/notifications.rb +113 -23
  122. data/lib/active_support/ordered_hash.rb +11 -35
  123. data/lib/active_support/ordered_options.rb +0 -6
  124. data/lib/active_support/rescuable.rb +4 -7
  125. data/lib/active_support/ruby/shim.rb +6 -4
  126. data/lib/active_support/test_case.rb +7 -2
  127. data/lib/active_support/testing/assertions.rb +0 -15
  128. data/lib/active_support/testing/declarative.rb +1 -1
  129. data/lib/active_support/testing/isolation.rb +19 -63
  130. data/lib/active_support/testing/performance.rb +337 -342
  131. data/lib/active_support/testing/setup_and_teardown.rb +29 -51
  132. data/lib/active_support/time.rb +3 -23
  133. data/lib/active_support/time_with_zone.rb +10 -5
  134. data/lib/active_support/values/time_zone.rb +84 -40
  135. data/lib/active_support/values/unicode_tables.dat +0 -0
  136. data/lib/active_support/vendor.rb +16 -0
  137. data/lib/active_support/vendor/builder-2.1.2/lib/blankslate.rb +113 -0
  138. data/lib/active_support/vendor/builder-2.1.2/lib/builder.rb +13 -0
  139. data/lib/active_support/vendor/builder-2.1.2/lib/builder/blankslate.rb +20 -0
  140. data/lib/active_support/vendor/builder-2.1.2/lib/builder/css.rb +250 -0
  141. data/lib/active_support/vendor/builder-2.1.2/lib/builder/xchar.rb +115 -0
  142. data/lib/active_support/vendor/builder-2.1.2/lib/builder/xmlbase.rb +139 -0
  143. data/lib/active_support/vendor/builder-2.1.2/lib/builder/xmlevents.rb +63 -0
  144. data/lib/active_support/vendor/builder-2.1.2/lib/builder/xmlmarkup.rb +328 -0
  145. data/lib/active_support/vendor/i18n-0.1.3/MIT-LICENSE +20 -0
  146. data/lib/active_support/vendor/i18n-0.1.3/README.textile +20 -0
  147. data/lib/active_support/vendor/i18n-0.1.3/Rakefile +5 -0
  148. data/lib/active_support/vendor/i18n-0.1.3/i18n.gemspec +27 -0
  149. data/lib/active_support/vendor/i18n-0.1.3/lib/i18n.rb +204 -0
  150. data/lib/active_support/vendor/i18n-0.1.3/lib/i18n/backend/simple.rb +215 -0
  151. data/lib/active_support/vendor/i18n-0.1.3/lib/i18n/exceptions.rb +53 -0
  152. data/lib/active_support/vendor/i18n-0.1.3/test/all.rb +5 -0
  153. data/lib/active_support/vendor/i18n-0.1.3/test/i18n_exceptions_test.rb +99 -0
  154. data/lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb +124 -0
  155. data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.rb +1 -0
  156. data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.yml +3 -0
  157. data/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb +567 -0
  158. data/lib/active_support/vendor/memcache-client-1.7.5/lib/memcache.rb +1133 -0
  159. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo.rb +33 -0
  160. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/data_timezone.rb +47 -0
  161. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/data_timezone_info.rb +228 -0
  162. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Algiers.rb +55 -0
  163. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Cairo.rb +219 -0
  164. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Casablanca.rb +42 -0
  165. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Harare.rb +18 -0
  166. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Johannesburg.rb +25 -0
  167. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Monrovia.rb +22 -0
  168. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Nairobi.rb +23 -0
  169. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Argentina/Buenos_Aires.rb +166 -0
  170. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Argentina/San_Juan.rb +86 -0
  171. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Bogota.rb +23 -0
  172. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Caracas.rb +23 -0
  173. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Chicago.rb +283 -0
  174. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Chihuahua.rb +136 -0
  175. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Denver.rb +204 -0
  176. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Godthab.rb +161 -0
  177. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Guatemala.rb +27 -0
  178. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Halifax.rb +274 -0
  179. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Indiana/Indianapolis.rb +149 -0
  180. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Juneau.rb +194 -0
  181. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/La_Paz.rb +22 -0
  182. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Lima.rb +35 -0
  183. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Los_Angeles.rb +232 -0
  184. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Mazatlan.rb +139 -0
  185. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Mexico_City.rb +144 -0
  186. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Monterrey.rb +131 -0
  187. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/New_York.rb +282 -0
  188. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Phoenix.rb +30 -0
  189. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Regina.rb +74 -0
  190. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Santiago.rb +205 -0
  191. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Sao_Paulo.rb +171 -0
  192. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/St_Johns.rb +288 -0
  193. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Tijuana.rb +196 -0
  194. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Almaty.rb +67 -0
  195. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Baghdad.rb +73 -0
  196. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Baku.rb +161 -0
  197. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Bangkok.rb +20 -0
  198. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Chongqing.rb +33 -0
  199. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Colombo.rb +30 -0
  200. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Dhaka.rb +27 -0
  201. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Hong_Kong.rb +87 -0
  202. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Irkutsk.rb +165 -0
  203. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Jakarta.rb +30 -0
  204. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Jerusalem.rb +163 -0
  205. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kabul.rb +20 -0
  206. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kamchatka.rb +163 -0
  207. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Karachi.rb +32 -0
  208. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kathmandu.rb +20 -0
  209. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kolkata.rb +25 -0
  210. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Krasnoyarsk.rb +163 -0
  211. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kuala_Lumpur.rb +31 -0
  212. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kuwait.rb +18 -0
  213. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Magadan.rb +163 -0
  214. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Muscat.rb +18 -0
  215. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Novosibirsk.rb +164 -0
  216. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Rangoon.rb +24 -0
  217. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Riyadh.rb +18 -0
  218. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Seoul.rb +34 -0
  219. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Shanghai.rb +35 -0
  220. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Singapore.rb +33 -0
  221. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Taipei.rb +59 -0
  222. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Tashkent.rb +47 -0
  223. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Tbilisi.rb +78 -0
  224. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Tehran.rb +121 -0
  225. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Tokyo.rb +30 -0
  226. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Ulaanbaatar.rb +65 -0
  227. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Urumqi.rb +33 -0
  228. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Vladivostok.rb +164 -0
  229. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Yakutsk.rb +163 -0
  230. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Yekaterinburg.rb +165 -0
  231. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Yerevan.rb +165 -0
  232. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Atlantic/Azores.rb +270 -0
  233. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Atlantic/Cape_Verde.rb +23 -0
  234. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Atlantic/South_Georgia.rb +18 -0
  235. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Adelaide.rb +187 -0
  236. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Brisbane.rb +35 -0
  237. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Darwin.rb +29 -0
  238. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Hobart.rb +193 -0
  239. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Melbourne.rb +185 -0
  240. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Perth.rb +37 -0
  241. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Sydney.rb +185 -0
  242. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Etc/UTC.rb +16 -0
  243. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Amsterdam.rb +228 -0
  244. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Athens.rb +185 -0
  245. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Belgrade.rb +163 -0
  246. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Berlin.rb +188 -0
  247. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Bratislava.rb +13 -0
  248. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Brussels.rb +232 -0
  249. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Bucharest.rb +181 -0
  250. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Budapest.rb +197 -0
  251. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Copenhagen.rb +179 -0
  252. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Dublin.rb +276 -0
  253. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Helsinki.rb +163 -0
  254. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Istanbul.rb +218 -0
  255. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Kiev.rb +168 -0
  256. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Lisbon.rb +268 -0
  257. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Ljubljana.rb +13 -0
  258. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/London.rb +288 -0
  259. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Madrid.rb +211 -0
  260. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Minsk.rb +170 -0
  261. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Moscow.rb +181 -0
  262. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Paris.rb +232 -0
  263. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Prague.rb +187 -0
  264. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Riga.rb +176 -0
  265. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Rome.rb +215 -0
  266. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Sarajevo.rb +13 -0
  267. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Skopje.rb +13 -0
  268. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Sofia.rb +173 -0
  269. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Stockholm.rb +165 -0
  270. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Tallinn.rb +172 -0
  271. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Vienna.rb +183 -0
  272. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Vilnius.rb +170 -0
  273. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Warsaw.rb +212 -0
  274. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Zagreb.rb +13 -0
  275. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Auckland.rb +202 -0
  276. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Fiji.rb +23 -0
  277. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Guam.rb +22 -0
  278. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Honolulu.rb +28 -0
  279. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Majuro.rb +20 -0
  280. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Midway.rb +25 -0
  281. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Noumea.rb +25 -0
  282. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Pago_Pago.rb +26 -0
  283. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Port_Moresby.rb +20 -0
  284. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Tongatapu.rb +27 -0
  285. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/info_timezone.rb +52 -0
  286. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/linked_timezone.rb +51 -0
  287. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/linked_timezone_info.rb +44 -0
  288. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/offset_rationals.rb +98 -0
  289. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/ruby_core_support.rb +56 -0
  290. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/time_or_datetime.rb +292 -0
  291. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone.rb +508 -0
  292. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone_definition.rb +56 -0
  293. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone_info.rb +40 -0
  294. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone_offset_info.rb +94 -0
  295. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone_period.rb +198 -0
  296. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone_transition_info.rb +129 -0
  297. data/lib/active_support/version.rb +2 -3
  298. data/lib/active_support/whiny_nil.rb +7 -9
  299. data/lib/active_support/xml_mini.rb +1 -126
  300. data/lib/active_support/xml_mini/jdom.rb +0 -2
  301. data/lib/active_support/xml_mini/libxml.rb +86 -24
  302. data/lib/active_support/xml_mini/nokogiri.rb +24 -27
  303. data/lib/active_support/xml_mini/rexml.rb +1 -7
  304. metadata +191 -49
  305. data/lib/active_support/builder.rb +0 -6
  306. data/lib/active_support/core_ext/array/uniq_by.rb +0 -17
  307. data/lib/active_support/core_ext/class/attribute.rb +0 -67
  308. data/lib/active_support/core_ext/class/subclasses.rb +0 -55
  309. data/lib/active_support/core_ext/file/path.rb +0 -5
  310. data/lib/active_support/core_ext/integer/multiple.rb +0 -6
  311. data/lib/active_support/core_ext/kernel/singleton_class.rb +0 -13
  312. data/lib/active_support/core_ext/module/anonymous.rb +0 -24
  313. data/lib/active_support/core_ext/module/method_names.rb +0 -14
  314. data/lib/active_support/core_ext/module/reachable.rb +0 -10
  315. data/lib/active_support/core_ext/module/remove_method.rb +0 -6
  316. data/lib/active_support/core_ext/object/to_param.rb +0 -49
  317. data/lib/active_support/core_ext/object/to_query.rb +0 -27
  318. data/lib/active_support/core_ext/string/encoding.rb +0 -11
  319. data/lib/active_support/core_ext/string/exclude.rb +0 -6
  320. data/lib/active_support/core_ext/time/marshal.rb +0 -56
  321. data/lib/active_support/dependencies/autoload.rb +0 -50
  322. data/lib/active_support/i18n.rb +0 -8
  323. data/lib/active_support/inflector/inflections.rb +0 -211
  324. data/lib/active_support/inflector/methods.rb +0 -141
  325. data/lib/active_support/inflector/transliterate.rb +0 -97
  326. data/lib/active_support/json/backends/yajl.rb +0 -40
  327. data/lib/active_support/lazy_load_hooks.rb +0 -27
  328. data/lib/active_support/multibyte/unicode.rb +0 -393
  329. data/lib/active_support/notifications/fanout.rb +0 -93
  330. data/lib/active_support/notifications/instrumenter.rb +0 -56
  331. data/lib/active_support/railtie.rb +0 -100
  332. data/lib/active_support/xml_mini/libxmlsax.rb +0 -85
  333. data/lib/active_support/xml_mini/nokogirisax.rb +0 -83
@@ -1,12 +1,19 @@
1
1
  module ActiveSupport
2
2
  module Cache
3
3
  class CompressedMemCacheStore < MemCacheStore
4
- def initialize(*args)
5
- ActiveSupport::Deprecation.warn('ActiveSupport::Cache::CompressedMemCacheStore has been deprecated in favor of ActiveSupport::Cache::MemCacheStore(:compress => true).', caller)
6
- addresses = args.dup
7
- options = addresses.extract_options!
8
- args = addresses + [options.merge(:compress => true)]
9
- super(*args)
4
+ def read(name, options = nil)
5
+ if value = super(name, (options || {}).merge(:raw => true))
6
+ if raw?(options)
7
+ value
8
+ else
9
+ Marshal.load(ActiveSupport::Gzip.decompress(value))
10
+ end
11
+ end
12
+ end
13
+
14
+ def write(name, value, options = nil)
15
+ value = ActiveSupport::Gzip.compress(Marshal.dump(value)) unless raw?(options)
16
+ super(name, value, (options || {}).merge(:raw => true))
10
17
  end
11
18
  end
12
19
  end
@@ -3,171 +3,73 @@ require 'active_support/core_ext/file/atomic'
3
3
  module ActiveSupport
4
4
  module Cache
5
5
  # A cache store implementation which stores everything on the filesystem.
6
- #
7
- # FileStore implements the Strategy::LocalCache strategy which implements
8
- # an in memory cache inside of a block.
9
6
  class FileStore < Store
10
7
  attr_reader :cache_path
11
8
 
12
- DIR_FORMATTER = "%03X"
13
- ESCAPE_FILENAME_CHARS = /[^a-z0-9_.-]/i
14
- UNESCAPE_FILENAME_CHARS = /%[0-9A-F]{2}/
15
-
16
- def initialize(cache_path, options = nil)
17
- super(options)
9
+ def initialize(cache_path)
18
10
  @cache_path = cache_path
19
- extend Strategy::LocalCache
20
- end
21
-
22
- def clear(options = nil)
23
- root_dirs = Dir.entries(cache_path).reject{|f| ['.', '..'].include?(f)}
24
- FileUtils.rm_r(root_dirs.collect{|f| File.join(cache_path, f)})
25
- end
26
-
27
- def cleanup(options = nil)
28
- options = merged_options(options)
29
- each_key(options) do |key|
30
- entry = read_entry(key, options)
31
- delete_entry(key, options) if entry && entry.expired?
32
- end
33
11
  end
34
12
 
35
- def increment(name, amount = 1, options = nil)
36
- file_name = key_file_path(namespaced_key(name, options))
37
- lock_file(file_name) do
38
- options = merged_options(options)
39
- if num = read(name, options)
40
- num = num.to_i + amount
41
- write(name, num, options)
42
- num
43
- else
44
- nil
13
+ # Reads a value from the cache.
14
+ #
15
+ # Possible options:
16
+ # - +:expires_in+ - the number of seconds that this value may stay in
17
+ # the cache.
18
+ def read(name, options = nil)
19
+ super do
20
+ file_name = real_file_path(name)
21
+ expires = expires_in(options)
22
+
23
+ if File.exist?(file_name) && (expires <= 0 || Time.now - File.mtime(file_name) < expires)
24
+ File.open(file_name, 'rb') { |f| Marshal.load(f) }
45
25
  end
46
26
  end
47
27
  end
48
28
 
49
- def decrement(name, amount = 1, options = nil)
50
- file_name = key_file_path(namespaced_key(name, options))
51
- lock_file(file_name) do
52
- options = merged_options(options)
53
- if num = read(name, options)
54
- num = num.to_i - amount
55
- write(name, num, options)
56
- num
57
- else
58
- nil
59
- end
29
+ # Writes a value to the cache.
30
+ def write(name, value, options = nil)
31
+ super do
32
+ ensure_cache_path(File.dirname(real_file_path(name)))
33
+ File.atomic_write(real_file_path(name), cache_path) { |f| Marshal.dump(value, f) }
34
+ value
60
35
  end
36
+ rescue => e
37
+ logger.error "Couldn't create cache directory: #{name} (#{e.message})" if logger
61
38
  end
62
39
 
63
- def delete_matched(matcher, options = nil)
64
- options = merged_options(options)
65
- instrument(:delete_matched, matcher.inspect) do
66
- matcher = key_matcher(matcher, options)
67
- search_dir(cache_path) do |path|
68
- key = file_path_key(path)
69
- delete_entry(key, options) if key.match(matcher)
70
- end
40
+ def delete(name, options = nil)
41
+ super do
42
+ File.delete(real_file_path(name))
71
43
  end
44
+ rescue SystemCallError => e
45
+ # If there's no cache, then there's nothing to complain about
72
46
  end
73
47
 
74
- protected
75
-
76
- def read_entry(key, options)
77
- file_name = key_file_path(key)
78
- if File.exist?(file_name)
79
- entry = File.open(file_name) { |f| Marshal.load(f) }
80
- if entry && !entry.expired? && !entry.expires_in && !self.options[:expires_in]
81
- # Check for deprecated use of +:expires_in+ option from versions < 3.0
82
- deprecated_expires_in = options[:expires_in]
83
- if deprecated_expires_in
84
- ActiveSupport::Deprecation.warn('Setting :expires_in on read has been deprecated in favor of setting it on write.', caller)
85
- if entry.created_at + deprecated_expires_in.to_f <= Time.now.to_f
86
- delete_entry(key, options)
87
- entry = nil
88
- end
89
- end
90
- end
91
- entry
92
- end
93
- rescue
94
- nil
95
- end
96
-
97
- def write_entry(key, entry, options)
98
- file_name = key_file_path(key)
99
- ensure_cache_path(File.dirname(file_name))
100
- File.atomic_write(file_name, cache_path) {|f| Marshal.dump(entry, f)}
101
- true
102
- end
103
-
104
- def delete_entry(key, options)
105
- file_name = key_file_path(key)
106
- if File.exist?(file_name)
107
- begin
108
- File.delete(file_name)
109
- delete_empty_directories(File.dirname(file_name))
110
- true
111
- rescue => e
112
- # Just in case the error was caused by another process deleting the file first.
113
- raise e if File.exist?(file_name)
114
- false
115
- end
116
- end
117
- end
118
-
119
- private
120
- # Lock a file for a block so only one process can modify it at a time.
121
- def lock_file(file_name, &block) # :nodoc:
122
- if File.exist?(file_name)
123
- File.open(file_name, 'r') do |f|
48
+ def delete_matched(matcher, options = nil)
49
+ super do
50
+ search_dir(@cache_path) do |f|
51
+ if f =~ matcher
124
52
  begin
125
- f.flock File::LOCK_EX
126
- yield
127
- ensure
128
- f.flock File::LOCK_UN
53
+ File.delete(f)
54
+ rescue SystemCallError => e
55
+ # If there's no cache, then there's nothing to complain about
129
56
  end
130
57
  end
131
- else
132
- yield
133
58
  end
134
59
  end
60
+ end
135
61
 
136
- # Translate a key into a file path.
137
- def key_file_path(key)
138
- fname = key.to_s.gsub(ESCAPE_FILENAME_CHARS){|match| "%#{match.ord.to_s(16).upcase}"}
139
- hash = Zlib.adler32(fname)
140
- hash, dir_1 = hash.divmod(0x1000)
141
- dir_2 = hash.modulo(0x1000)
142
- fname_paths = []
143
- # Make sure file name is < 255 characters so it doesn't exceed file system limits.
144
- if fname.size <= 255
145
- fname_paths << fname
146
- else
147
- while fname.size <= 255
148
- fname_path << fname[0, 255]
149
- fname = fname[255, -1]
150
- end
151
- end
152
- File.join(cache_path, DIR_FORMATTER % dir_1, DIR_FORMATTER % dir_2, *fname_paths)
153
- end
154
-
155
- # Translate a file path into a key.
156
- def file_path_key(path)
157
- fname = path[cache_path.size, path.size].split(File::SEPARATOR, 4).last
158
- fname.gsub(UNESCAPE_FILENAME_CHARS){|match| $1.ord.to_s(16)}
62
+ def exist?(name, options = nil)
63
+ super do
64
+ File.exist?(real_file_path(name))
159
65
  end
66
+ end
160
67
 
161
- # Delete empty directories in the cache.
162
- def delete_empty_directories(dir)
163
- return if dir == cache_path
164
- if Dir.entries(dir).reject{|f| ['.', '..'].include?(f)}.empty?
165
- File.delete(dir) rescue nil
166
- delete_empty_directories(File.dirname(dir))
167
- end
68
+ private
69
+ def real_file_path(name)
70
+ '%s/%s.cache' % [@cache_path, name.gsub('?', '.').gsub(':', '.')]
168
71
  end
169
72
 
170
- # Make sure a file path's directories exist.
171
73
  def ensure_cache_path(path)
172
74
  FileUtils.makedirs(path) unless File.exist?(path)
173
75
  end
@@ -1,10 +1,4 @@
1
- begin
2
- require 'memcache'
3
- rescue LoadError => e
4
- $stderr.puts "You don't have memcache installed in your application. Please add it to your Gemfile and run bundle install"
5
- raise e
6
- end
7
- require 'digest/md5'
1
+ require 'memcache'
8
2
 
9
3
  module ActiveSupport
10
4
  module Cache
@@ -18,9 +12,8 @@ module ActiveSupport
18
12
  # and MemCacheStore will load balance between all available servers. If a
19
13
  # server goes down, then MemCacheStore will ignore it until it goes back
20
14
  # online.
21
- #
22
- # MemCacheStore implements the Strategy::LocalCache strategy which implements
23
- # an in memory cache inside of a block.
15
+ # - Time-based expiry support. See #write and the <tt>:expires_in</tt> option.
16
+ # - Per-request in memory cache for all communication with the MemCache server(s).
24
17
  class MemCacheStore < Store
25
18
  module Response # :nodoc:
26
19
  STORED = "STORED\r\n"
@@ -30,8 +23,6 @@ module ActiveSupport
30
23
  DELETED = "DELETED\r\n"
31
24
  end
32
25
 
33
- ESCAPE_KEY_CHARS = /[\x00-\x20%\x7F-\xFF]/
34
-
35
26
  def self.build_mem_cache(*addresses)
36
27
  addresses = addresses.flatten
37
28
  options = addresses.extract_options!
@@ -47,145 +38,109 @@ module ActiveSupport
47
38
  #
48
39
  # If no addresses are specified, then MemCacheStore will connect to
49
40
  # localhost port 11211 (the default memcached port).
50
- #
51
- # Instead of addresses one can pass in a MemCache-like object. For example:
52
- #
53
- # require 'memcached' # gem install memcached; uses C bindings to libmemcached
54
- # ActiveSupport::Cache::MemCacheStore.new(Memcached::Rails.new("localhost:11211"))
55
41
  def initialize(*addresses)
56
- addresses = addresses.flatten
57
- options = addresses.extract_options!
58
- super(options)
59
-
60
42
  if addresses.first.respond_to?(:get)
61
43
  @data = addresses.first
62
44
  else
63
- mem_cache_options = options.dup
64
- UNIVERSAL_OPTIONS.each{|name| mem_cache_options.delete(name)}
65
- @data = self.class.build_mem_cache(*(addresses + [mem_cache_options]))
45
+ @data = self.class.build_mem_cache(*addresses)
66
46
  end
67
47
 
68
48
  extend Strategy::LocalCache
69
- extend LocalCacheWithRaw
70
49
  end
71
50
 
72
- # Reads multiple keys from the cache using a single call to the
73
- # servers for all keys. Options can be passed in the last argument.
74
- def read_multi(*names)
75
- options = names.extract_options!
76
- options = merged_options(options)
77
- keys_to_names = names.inject({}){|map, name| map[escape_key(namespaced_key(name, options))] = name; map}
78
- raw_values = @data.get_multi(keys_to_names.keys, :raw => true)
79
- values = {}
80
- raw_values.each do |key, value|
81
- entry = deserialize_entry(value)
82
- values[keys_to_names[key]] = entry.value unless entry.expired?
51
+ # Reads multiple keys from the cache.
52
+ def read_multi(*keys)
53
+ @data.get_multi keys
54
+ end
55
+
56
+ def read(key, options = nil) # :nodoc:
57
+ super do
58
+ @data.get(key, raw?(options))
59
+ end
60
+ rescue MemCache::MemCacheError => e
61
+ logger.error("MemCacheError (#{e}): #{e.message}")
62
+ nil
63
+ end
64
+
65
+ # Writes a value to the cache.
66
+ #
67
+ # Possible options:
68
+ # - <tt>:unless_exist</tt> - set to true if you don't want to update the cache
69
+ # if the key is already set.
70
+ # - <tt>:expires_in</tt> - the number of seconds that this value may stay in
71
+ # the cache. See ActiveSupport::Cache::Store#write for an example.
72
+ def write(key, value, options = nil)
73
+ super do
74
+ method = options && options[:unless_exist] ? :add : :set
75
+ # memcache-client will break the connection if you send it an integer
76
+ # in raw mode, so we convert it to a string to be sure it continues working.
77
+ value = value.to_s if raw?(options)
78
+ response = @data.send(method, key, value, expires_in(options), raw?(options))
79
+ response == Response::STORED
80
+ end
81
+ rescue MemCache::MemCacheError => e
82
+ logger.error("MemCacheError (#{e}): #{e.message}")
83
+ false
84
+ end
85
+
86
+ def delete(key, options = nil) # :nodoc:
87
+ super do
88
+ response = @data.delete(key, expires_in(options))
89
+ response == Response::DELETED
83
90
  end
84
- values
91
+ rescue MemCache::MemCacheError => e
92
+ logger.error("MemCacheError (#{e}): #{e.message}")
93
+ false
85
94
  end
86
95
 
87
- # Increment a cached value. This method uses the memcached incr atomic
88
- # operator and can only be used on values written with the :raw option.
89
- # Calling it on a value not stored with :raw will initialize that value
90
- # to zero.
91
- def increment(name, amount = 1, options = nil) # :nodoc:
92
- options = merged_options(options)
93
- response = instrument(:increment, name, :amount => amount) do
94
- @data.incr(escape_key(namespaced_key(name, options)), amount)
96
+ def exist?(key, options = nil) # :nodoc:
97
+ # Doesn't call super, cause exist? in memcache is in fact a read
98
+ # But who cares? Reading is very fast anyway
99
+ # Local cache is checked first, if it doesn't know then memcache itself is read from
100
+ super do
101
+ !read(key, options).nil?
95
102
  end
96
- response == Response::NOT_FOUND ? nil : response.to_i
103
+ end
104
+
105
+ def increment(key, amount = 1) # :nodoc:
106
+ response = instrument(:increment, key, :amount => amount) do
107
+ @data.incr(key, amount)
108
+ end
109
+
110
+ response == Response::NOT_FOUND ? nil : response
97
111
  rescue MemCache::MemCacheError
98
112
  nil
99
113
  end
100
114
 
101
- # Decrement a cached value. This method uses the memcached decr atomic
102
- # operator and can only be used on values written with the :raw option.
103
- # Calling it on a value not stored with :raw will initialize that value
104
- # to zero.
105
- def decrement(name, amount = 1, options = nil) # :nodoc:
106
- options = merged_options(options)
107
- response = instrument(:decrement, name, :amount => amount) do
108
- @data.decr(escape_key(namespaced_key(name, options)), amount)
115
+ def decrement(key, amount = 1) # :nodoc:
116
+ response = instrument(:decrement, key, :amount => amount) do
117
+ @data.decr(key, amount)
109
118
  end
110
- response == Response::NOT_FOUND ? nil : response.to_i
119
+
120
+ response == Response::NOT_FOUND ? nil : response
111
121
  rescue MemCache::MemCacheError
112
122
  nil
113
123
  end
114
124
 
115
- # Clear the entire cache on all memcached servers. This method should
116
- # be used with care when using a shared cache.
117
- def clear(options = nil)
125
+ def delete_matched(matcher, options = nil) # :nodoc:
126
+ # don't do any local caching at present, just pass
127
+ # through and let the error happen
128
+ super
129
+ raise "Not supported by Memcache"
130
+ end
131
+
132
+ def clear
118
133
  @data.flush_all
119
134
  end
120
135
 
121
- # Get the statistics from the memcached servers.
122
136
  def stats
123
137
  @data.stats
124
138
  end
125
139
 
126
- protected
127
- # Read an entry from the cache.
128
- def read_entry(key, options) # :nodoc:
129
- deserialize_entry(@data.get(escape_key(key), true))
130
- rescue MemCache::MemCacheError => e
131
- logger.error("MemCacheError (#{e}): #{e.message}") if logger
132
- nil
133
- end
134
-
135
- # Write an entry to the cache.
136
- def write_entry(key, entry, options) # :nodoc:
137
- method = options && options[:unless_exist] ? :add : :set
138
- value = options[:raw] ? entry.value.to_s : entry
139
- expires_in = options[:expires_in].to_i
140
- if expires_in > 0 && !options[:raw]
141
- # Set the memcache expire a few minutes in the future to support race condition ttls on read
142
- expires_in += 5.minutes
143
- end
144
- response = @data.send(method, escape_key(key), value, expires_in, options[:raw])
145
- response == Response::STORED
146
- rescue MemCache::MemCacheError => e
147
- logger.error("MemCacheError (#{e}): #{e.message}") if logger
148
- false
149
- end
150
-
151
- # Delete an entry from the cache.
152
- def delete_entry(key, options) # :nodoc:
153
- response = @data.delete(escape_key(key))
154
- response == Response::DELETED
155
- rescue MemCache::MemCacheError => e
156
- logger.error("MemCacheError (#{e}): #{e.message}") if logger
157
- false
158
- end
159
-
160
140
  private
161
- def escape_key(key)
162
- key = key.to_s.gsub(ESCAPE_KEY_CHARS){|match| "%#{match[0].to_s(16).upcase}"}
163
- key = "#{key[0, 213]}:md5:#{Digest::MD5.hexdigest(key)}" if key.size > 250
164
- key
165
- end
166
-
167
- def deserialize_entry(raw_value)
168
- if raw_value
169
- entry = Marshal.load(raw_value) rescue raw_value
170
- entry.is_a?(Entry) ? entry : Entry.new(entry)
171
- else
172
- nil
173
- end
141
+ def raw?(options)
142
+ options && options[:raw]
174
143
  end
175
-
176
- # Provide support for raw values in the local cache strategy.
177
- module LocalCacheWithRaw # :nodoc:
178
- protected
179
- def write_entry(key, entry, options) # :nodoc:
180
- retval = super
181
- if options[:raw] && local_cache && retval
182
- raw_entry = Entry.new(entry.value.to_s)
183
- raw_entry.expires_at = entry.expires_at
184
- local_cache.write_entry(key, raw_entry, options)
185
- end
186
- retval
187
- end
188
- end
189
144
  end
190
145
  end
191
146
  end