activesupport 2.1.2 → 2.2.2

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 (240) hide show
  1. data/CHANGELOG +64 -5
  2. data/lib/active_support.rb +6 -6
  3. data/lib/active_support/base64.rb +13 -2
  4. data/lib/active_support/basic_object.rb +1 -1
  5. data/lib/active_support/buffered_logger.rb +15 -14
  6. data/lib/active_support/cache.rb +116 -40
  7. data/lib/active_support/cache/compressed_mem_cache_store.rb +7 -2
  8. data/lib/active_support/cache/file_store.rb +7 -5
  9. data/lib/active_support/cache/mem_cache_store.rb +48 -21
  10. data/lib/active_support/cache/memory_store.rb +16 -2
  11. data/lib/active_support/cache/synchronized_memory_store.rb +47 -0
  12. data/lib/active_support/callbacks.rb +14 -9
  13. data/lib/active_support/core_ext/array/access.rb +27 -0
  14. data/lib/active_support/core_ext/array/conversions.rb +12 -7
  15. data/lib/active_support/core_ext/array/grouping.rb +53 -10
  16. data/lib/active_support/core_ext/base64/encoding.rb +3 -0
  17. data/lib/active_support/core_ext/bigdecimal/conversions.rb +18 -22
  18. data/lib/active_support/core_ext/blank.rb +5 -0
  19. data/lib/active_support/core_ext/class/inheritable_attributes.rb +5 -5
  20. data/lib/active_support/core_ext/date/behavior.rb +3 -0
  21. data/lib/active_support/core_ext/date/calculations.rb +24 -9
  22. data/lib/active_support/core_ext/date_time/calculations.rb +19 -5
  23. data/lib/active_support/core_ext/duplicable.rb +6 -0
  24. data/lib/active_support/core_ext/enumerable.rb +42 -4
  25. data/lib/active_support/core_ext/file.rb +4 -20
  26. data/lib/active_support/core_ext/file/atomic.rb +46 -0
  27. data/lib/active_support/core_ext/float.rb +2 -0
  28. data/lib/active_support/core_ext/float/time.rb +27 -0
  29. data/lib/active_support/core_ext/hash.rb +2 -1
  30. data/lib/active_support/core_ext/hash/conversions.rb +1 -1
  31. data/lib/active_support/core_ext/hash/deep_merge.rb +23 -0
  32. data/lib/active_support/core_ext/hash/except.rb +1 -1
  33. data/lib/active_support/core_ext/hash/reverse_merge.rb +12 -5
  34. data/lib/active_support/core_ext/hash/slice.rb +7 -4
  35. data/lib/active_support/core_ext/integer.rb +2 -0
  36. data/lib/active_support/core_ext/integer/time.rb +45 -0
  37. data/lib/active_support/core_ext/kernel/debugger.rb +4 -4
  38. data/lib/active_support/core_ext/logger.rb +128 -1
  39. data/lib/active_support/core_ext/module.rb +11 -1
  40. data/lib/active_support/core_ext/module/aliasing.rb +71 -67
  41. data/lib/active_support/core_ext/module/delegation.rb +32 -1
  42. data/lib/active_support/core_ext/module/introspection.rb +81 -66
  43. data/lib/active_support/core_ext/module/model_naming.rb +8 -7
  44. data/lib/active_support/core_ext/module/synchronization.rb +39 -0
  45. data/lib/active_support/core_ext/numeric/time.rb +0 -10
  46. data/lib/active_support/core_ext/object.rb +1 -0
  47. data/lib/active_support/core_ext/object/extending.rb +29 -7
  48. data/lib/active_support/core_ext/object/instance_variables.rb +1 -1
  49. data/lib/active_support/core_ext/object/metaclass.rb +13 -0
  50. data/lib/active_support/core_ext/object/misc.rb +36 -21
  51. data/lib/active_support/core_ext/rexml.rb +2 -2
  52. data/lib/active_support/core_ext/string.rb +6 -2
  53. data/lib/active_support/core_ext/string/access.rb +5 -5
  54. data/lib/active_support/core_ext/string/behavior.rb +13 -0
  55. data/lib/active_support/core_ext/string/inflections.rb +21 -2
  56. data/lib/active_support/core_ext/string/multibyte.rb +81 -0
  57. data/lib/active_support/core_ext/time/calculations.rb +39 -12
  58. data/lib/active_support/core_ext/time/conversions.rb +1 -0
  59. data/lib/active_support/core_ext/time/zones.rb +1 -1
  60. data/lib/active_support/dependencies.rb +178 -110
  61. data/lib/active_support/deprecation.rb +24 -4
  62. data/lib/active_support/inflector.rb +122 -38
  63. data/lib/active_support/json.rb +1 -1
  64. data/lib/active_support/json/encoders/date.rb +9 -2
  65. data/lib/active_support/json/encoders/date_time.rb +9 -2
  66. data/lib/active_support/json/encoders/time.rb +10 -3
  67. data/lib/active_support/locale/en.yml +32 -0
  68. data/lib/active_support/memoizable.rb +82 -0
  69. data/lib/active_support/multibyte.rb +31 -7
  70. data/lib/active_support/multibyte/chars.rb +664 -122
  71. data/lib/active_support/multibyte/exceptions.rb +8 -0
  72. data/lib/active_support/multibyte/unicode_database.rb +71 -0
  73. data/lib/active_support/option_merger.rb +2 -10
  74. data/lib/active_support/ordered_hash.rb +15 -0
  75. data/lib/active_support/rescuable.rb +108 -0
  76. data/lib/active_support/secure_random.rb +197 -0
  77. data/lib/active_support/string_inquirer.rb +11 -1
  78. data/lib/active_support/test_case.rb +16 -5
  79. data/lib/active_support/testing/core_ext/test.rb +6 -0
  80. data/lib/active_support/{core_ext → testing/core_ext}/test/unit/assertions.rb +14 -6
  81. data/lib/active_support/testing/performance.rb +452 -0
  82. data/lib/active_support/testing/setup_and_teardown.rb +34 -7
  83. data/lib/active_support/time_with_zone.rb +66 -42
  84. data/lib/active_support/values/time_zone.rb +11 -4
  85. data/lib/active_support/values/unicode_tables.dat +0 -0
  86. data/lib/active_support/vendor.rb +13 -5
  87. data/lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb +1 -1
  88. data/lib/active_support/vendor/i18n-0.0.1/i18n.rb +194 -0
  89. data/lib/active_support/vendor/i18n-0.0.1/i18n/backend/simple.rb +216 -0
  90. data/lib/active_support/vendor/i18n-0.0.1/i18n/exceptions.rb +53 -0
  91. data/lib/active_support/vendor/{memcache-client-1.5.0 → memcache-client-1.5.1}/memcache.rb +5 -5
  92. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo.rb +0 -0
  93. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/data_timezone.rb +0 -0
  94. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/data_timezone_info.rb +0 -0
  95. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Africa/Algiers.rb +0 -0
  96. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Africa/Cairo.rb +0 -0
  97. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Africa/Casablanca.rb +0 -0
  98. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Africa/Harare.rb +0 -0
  99. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Africa/Johannesburg.rb +0 -0
  100. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Africa/Monrovia.rb +0 -0
  101. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Africa/Nairobi.rb +0 -0
  102. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/America/Argentina/Buenos_Aires.rb +0 -0
  103. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Argentina/San_Juan.rb +86 -0
  104. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/America/Bogota.rb +0 -0
  105. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/America/Caracas.rb +0 -0
  106. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/America/Chicago.rb +0 -0
  107. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/America/Chihuahua.rb +0 -0
  108. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/America/Denver.rb +0 -0
  109. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/America/Godthab.rb +0 -0
  110. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/America/Guatemala.rb +0 -0
  111. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/America/Halifax.rb +0 -0
  112. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/America/Indiana/Indianapolis.rb +0 -0
  113. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/America/Juneau.rb +0 -0
  114. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/America/La_Paz.rb +0 -0
  115. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/America/Lima.rb +0 -0
  116. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/America/Los_Angeles.rb +0 -0
  117. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/America/Mazatlan.rb +0 -0
  118. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/America/Mexico_City.rb +0 -0
  119. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/America/Monterrey.rb +0 -0
  120. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/America/New_York.rb +0 -0
  121. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/America/Phoenix.rb +0 -0
  122. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/America/Regina.rb +0 -0
  123. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/America/Santiago.rb +0 -0
  124. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/America/Sao_Paulo.rb +0 -0
  125. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/America/St_Johns.rb +0 -0
  126. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/America/Tijuana.rb +0 -0
  127. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Almaty.rb +0 -0
  128. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Baghdad.rb +0 -0
  129. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Baku.rb +0 -0
  130. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Bangkok.rb +0 -0
  131. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Chongqing.rb +0 -0
  132. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Colombo.rb +30 -0
  133. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Dhaka.rb +0 -0
  134. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Hong_Kong.rb +0 -0
  135. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Irkutsk.rb +0 -0
  136. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Jakarta.rb +0 -0
  137. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Jerusalem.rb +0 -0
  138. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Kabul.rb +0 -0
  139. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Kamchatka.rb +0 -0
  140. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Karachi.rb +0 -0
  141. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Katmandu.rb +0 -0
  142. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Kolkata.rb +0 -0
  143. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Krasnoyarsk.rb +0 -0
  144. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Kuala_Lumpur.rb +0 -0
  145. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Kuwait.rb +0 -0
  146. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Magadan.rb +0 -0
  147. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Muscat.rb +0 -0
  148. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Novosibirsk.rb +0 -0
  149. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Rangoon.rb +0 -0
  150. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Riyadh.rb +0 -0
  151. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Seoul.rb +0 -0
  152. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Shanghai.rb +0 -0
  153. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Singapore.rb +0 -0
  154. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Taipei.rb +0 -0
  155. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Tashkent.rb +0 -0
  156. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Tbilisi.rb +0 -0
  157. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Tehran.rb +0 -0
  158. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Tokyo.rb +0 -0
  159. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Ulaanbaatar.rb +0 -0
  160. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Urumqi.rb +0 -0
  161. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Vladivostok.rb +0 -0
  162. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Yakutsk.rb +0 -0
  163. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Yekaterinburg.rb +0 -0
  164. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Asia/Yerevan.rb +0 -0
  165. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Atlantic/Azores.rb +0 -0
  166. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Atlantic/Cape_Verde.rb +0 -0
  167. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Atlantic/South_Georgia.rb +0 -0
  168. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Australia/Adelaide.rb +0 -0
  169. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Australia/Brisbane.rb +0 -0
  170. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Australia/Darwin.rb +0 -0
  171. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Australia/Hobart.rb +0 -0
  172. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Australia/Melbourne.rb +0 -0
  173. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Australia/Perth.rb +0 -0
  174. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Australia/Sydney.rb +0 -0
  175. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Etc/UTC.rb +0 -0
  176. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Amsterdam.rb +0 -0
  177. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Athens.rb +0 -0
  178. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Belgrade.rb +0 -0
  179. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Berlin.rb +0 -0
  180. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Bratislava.rb +0 -0
  181. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Brussels.rb +0 -0
  182. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Bucharest.rb +0 -0
  183. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Budapest.rb +0 -0
  184. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Copenhagen.rb +0 -0
  185. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Dublin.rb +0 -0
  186. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Helsinki.rb +0 -0
  187. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Istanbul.rb +0 -0
  188. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Kiev.rb +0 -0
  189. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Lisbon.rb +0 -0
  190. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Ljubljana.rb +0 -0
  191. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/London.rb +0 -0
  192. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Madrid.rb +0 -0
  193. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Minsk.rb +0 -0
  194. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Moscow.rb +0 -0
  195. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Paris.rb +0 -0
  196. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Prague.rb +0 -0
  197. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Riga.rb +0 -0
  198. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Rome.rb +0 -0
  199. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Sarajevo.rb +0 -0
  200. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Skopje.rb +0 -0
  201. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Sofia.rb +0 -0
  202. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Stockholm.rb +0 -0
  203. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Tallinn.rb +0 -0
  204. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Vienna.rb +0 -0
  205. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Vilnius.rb +0 -0
  206. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Warsaw.rb +0 -0
  207. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Europe/Zagreb.rb +0 -0
  208. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Pacific/Auckland.rb +0 -0
  209. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Pacific/Fiji.rb +0 -0
  210. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Pacific/Guam.rb +0 -0
  211. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Pacific/Honolulu.rb +0 -0
  212. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Pacific/Majuro.rb +0 -0
  213. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Pacific/Midway.rb +0 -0
  214. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Pacific/Noumea.rb +0 -0
  215. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Pacific/Pago_Pago.rb +0 -0
  216. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Pacific/Port_Moresby.rb +0 -0
  217. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/definitions/Pacific/Tongatapu.rb +0 -0
  218. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/info_timezone.rb +0 -0
  219. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/linked_timezone.rb +0 -0
  220. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/linked_timezone_info.rb +0 -0
  221. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/offset_rationals.rb +0 -0
  222. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/ruby_core_support.rb +0 -0
  223. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/time_or_datetime.rb +0 -0
  224. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/timezone.rb +0 -0
  225. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/timezone_definition.rb +0 -0
  226. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/timezone_info.rb +0 -0
  227. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/timezone_offset_info.rb +0 -0
  228. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/timezone_period.rb +0 -0
  229. data/lib/active_support/vendor/{tzinfo-0.3.11 → tzinfo-0.3.12}/tzinfo/timezone_transition_info.rb +0 -0
  230. data/lib/active_support/vendor/xml-simple-1.0.11/xmlsimple.rb +3 -3
  231. data/lib/active_support/version.rb +1 -1
  232. metadata +185 -167
  233. data/lib/active_support/clean_logger.rb +0 -127
  234. data/lib/active_support/core_ext/string/unicode.rb +0 -66
  235. data/lib/active_support/core_ext/test.rb +0 -1
  236. data/lib/active_support/multibyte/generators/generate_tables.rb +0 -149
  237. data/lib/active_support/multibyte/handlers/passthru_handler.rb +0 -9
  238. data/lib/active_support/multibyte/handlers/utf8_handler.rb +0 -564
  239. data/lib/active_support/multibyte/handlers/utf8_handler_proc.rb +0 -43
  240. data/lib/active_support/vendor/tzinfo-0.3.11/tzinfo/definitions/America/Argentina/San_Juan.rb +0 -170
@@ -10,19 +10,46 @@ module ActiveSupport
10
10
  end
11
11
 
12
12
  def self.included(base)
13
- base.send :include, ActiveSupport::Callbacks
14
- base.define_callbacks :setup, :teardown
13
+ base.class_eval do
14
+ include ActiveSupport::Callbacks
15
+ define_callbacks :setup, :teardown
15
16
 
17
+ if defined?(::Mini)
18
+ undef_method :run
19
+ alias_method :run, :run_with_callbacks_and_miniunit
20
+ else
21
+ begin
22
+ require 'mocha'
23
+ undef_method :run
24
+ alias_method :run, :run_with_callbacks_and_mocha
25
+ rescue LoadError
26
+ undef_method :run
27
+ alias_method :run, :run_with_callbacks_and_testunit
28
+ end
29
+ end
30
+ end
31
+ end
32
+
33
+ def run_with_callbacks_and_miniunit(runner)
34
+ result = '.'
16
35
  begin
17
- require 'mocha'
18
- base.alias_method_chain :run, :callbacks_and_mocha
19
- rescue LoadError
20
- base.alias_method_chain :run, :callbacks
36
+ run_callbacks :setup
37
+ result = super
38
+ rescue Exception => e
39
+ result = runner.puke(self.class, self.name, e)
40
+ ensure
41
+ begin
42
+ teardown
43
+ run_callbacks :teardown, :enumerator => :reverse_each
44
+ rescue Exception => e
45
+ result = runner.puke(self.class, self.name, e)
46
+ end
21
47
  end
48
+ result
22
49
  end
23
50
 
24
51
  # This redefinition is unfortunate but test/unit shows us no alternative.
25
- def run_with_callbacks(result) #:nodoc:
52
+ def run_with_callbacks_and_testunit(result) #:nodoc:
26
53
  return if @method_name.to_s == "default_test"
27
54
 
28
55
  yield(Test::Unit::TestCase::STARTED, name)
@@ -1,6 +1,6 @@
1
1
  require 'tzinfo'
2
2
  module ActiveSupport
3
- # A Time-like class that can represent a time in any time zone. Necessary because standard Ruby Time instances are
3
+ # A Time-like class that can represent a time in any time zone. Necessary because standard Ruby Time instances are
4
4
  # limited to UTC and the system's <tt>ENV['TZ']</tt> zone.
5
5
  #
6
6
  # You shouldn't ever need to create a TimeWithZone instance directly via <tt>new</tt> -- instead, Rails provides the methods
@@ -32,12 +32,12 @@ module ActiveSupport
32
32
  class TimeWithZone
33
33
  include Comparable
34
34
  attr_reader :time_zone
35
-
35
+
36
36
  def initialize(utc_time, time_zone, local_time = nil, period = nil)
37
37
  @utc, @time_zone, @time = utc_time, time_zone, local_time
38
38
  @period = @utc ? period : get_period_and_ensure_valid_local_time
39
39
  end
40
-
40
+
41
41
  # Returns a Time or DateTime instance that represents the time in +time_zone+.
42
42
  def time
43
43
  @time ||= period.to_local(@utc)
@@ -51,7 +51,7 @@ module ActiveSupport
51
51
  alias_method :getgm, :utc
52
52
  alias_method :getutc, :utc
53
53
  alias_method :gmtime, :utc
54
-
54
+
55
55
  # Returns the underlying TZInfo::TimezonePeriod.
56
56
  def period
57
57
  @period ||= time_zone.period_for_utc(@utc)
@@ -62,38 +62,38 @@ module ActiveSupport
62
62
  return self if time_zone == new_zone
63
63
  utc.in_time_zone(new_zone)
64
64
  end
65
-
65
+
66
66
  # Returns a <tt>Time.local()</tt> instance of the simultaneous time in your system's <tt>ENV['TZ']</tt> zone
67
67
  def localtime
68
68
  utc.getlocal
69
69
  end
70
70
  alias_method :getlocal, :localtime
71
-
71
+
72
72
  def dst?
73
73
  period.dst?
74
74
  end
75
75
  alias_method :isdst, :dst?
76
-
76
+
77
77
  def utc?
78
78
  time_zone.name == 'UTC'
79
79
  end
80
80
  alias_method :gmt?, :utc?
81
-
81
+
82
82
  def utc_offset
83
83
  period.utc_total_offset
84
84
  end
85
85
  alias_method :gmt_offset, :utc_offset
86
86
  alias_method :gmtoff, :utc_offset
87
-
87
+
88
88
  def formatted_offset(colon = true, alternate_utc_string = nil)
89
89
  utc? && alternate_utc_string || utc_offset.to_utc_offset_s(colon)
90
90
  end
91
-
91
+
92
92
  # Time uses +zone+ to display the time zone abbreviation, so we're duck-typing it.
93
93
  def zone
94
94
  period.zone_identifier.to_s
95
95
  end
96
-
96
+
97
97
  def inspect
98
98
  "#{time.strftime('%a, %d %b %Y %H:%M:%S')} #{zone} #{formatted_offset}"
99
99
  end
@@ -102,7 +102,19 @@ module ActiveSupport
102
102
  "#{time.strftime("%Y-%m-%dT%H:%M:%S")}#{formatted_offset(true, 'Z')}"
103
103
  end
104
104
  alias_method :iso8601, :xmlschema
105
-
105
+
106
+ # Returns a JSON string representing the TimeWithZone. If ActiveSupport.use_standard_json_time_format is set to
107
+ # true, the ISO 8601 format is used.
108
+ #
109
+ # ==== Examples:
110
+ #
111
+ # # With ActiveSupport.use_standard_json_time_format = true
112
+ # Time.utc(2005,2,1,15,15,10).in_time_zone.to_json
113
+ # # => "2005-02-01T15:15:10Z"
114
+ #
115
+ # # With ActiveSupport.use_standard_json_time_format = false
116
+ # Time.utc(2005,2,1,15,15,10).in_time_zone.to_json
117
+ # # => "2005/02/01 15:15:10 +0000"
106
118
  def to_json(options = nil)
107
119
  if ActiveSupport.use_standard_json_time_format
108
120
  xmlschema.inspect
@@ -110,7 +122,7 @@ module ActiveSupport
110
122
  %("#{time.strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)}")
111
123
  end
112
124
  end
113
-
125
+
114
126
  def to_yaml(options = {})
115
127
  if options.kind_of?(YAML::Emitter)
116
128
  utc.to_yaml(options)
@@ -118,19 +130,19 @@ module ActiveSupport
118
130
  time.to_yaml(options).gsub('Z', formatted_offset(true, 'Z'))
119
131
  end
120
132
  end
121
-
133
+
122
134
  def httpdate
123
135
  utc.httpdate
124
136
  end
125
-
137
+
126
138
  def rfc2822
127
139
  to_s(:rfc822)
128
140
  end
129
141
  alias_method :rfc822, :rfc2822
130
-
142
+
131
143
  # <tt>:db</tt> format outputs time in UTC; all others output time in local.
132
144
  # Uses TimeWithZone's +strftime+, so <tt>%Z</tt> and <tt>%z</tt> work correctly.
133
- def to_s(format = :default)
145
+ def to_s(format = :default)
134
146
  return utc.to_s(format) if format == :db
135
147
  if formatter = ::Time::DATE_FORMATS[format]
136
148
  formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
@@ -138,27 +150,39 @@ module ActiveSupport
138
150
  "#{time.strftime("%Y-%m-%d %H:%M:%S")} #{formatted_offset(false, 'UTC')}" # mimicking Ruby 1.9 Time#to_s format
139
151
  end
140
152
  end
141
-
153
+
142
154
  # Replaces <tt>%Z</tt> and <tt>%z</tt> directives with +zone+ and +formatted_offset+, respectively, before passing to
143
155
  # Time#strftime, so that zone information is correct
144
156
  def strftime(format)
145
157
  format = format.gsub('%Z', zone).gsub('%z', formatted_offset(false))
146
158
  time.strftime(format)
147
159
  end
148
-
160
+
149
161
  # Use the time in UTC for comparisons.
150
162
  def <=>(other)
151
163
  utc <=> other
152
164
  end
153
-
165
+
154
166
  def between?(min, max)
155
167
  utc.between?(min, max)
156
168
  end
157
-
169
+
170
+ def past?
171
+ utc.past?
172
+ end
173
+
174
+ def today?
175
+ time.today?
176
+ end
177
+
178
+ def future?
179
+ utc.future?
180
+ end
181
+
158
182
  def eql?(other)
159
183
  utc == other
160
184
  end
161
-
185
+
162
186
  def +(other)
163
187
  # If we're adding a Duration of variable length (i.e., years, months, days), move forward from #time,
164
188
  # otherwise move forward from #utc, for accuracy when moving across DST boundaries
@@ -182,7 +206,7 @@ module ActiveSupport
182
206
  result.in_time_zone(time_zone)
183
207
  end
184
208
  end
185
-
209
+
186
210
  def since(other)
187
211
  # If we're adding a Duration of variable length (i.e., years, months, days), move forward from #time,
188
212
  # otherwise move forward from #utc, for accuracy when moving across DST boundaries
@@ -192,7 +216,7 @@ module ActiveSupport
192
216
  utc.since(other).in_time_zone(time_zone)
193
217
  end
194
218
  end
195
-
219
+
196
220
  def ago(other)
197
221
  since(-other)
198
222
  end
@@ -206,47 +230,47 @@ module ActiveSupport
206
230
  utc.advance(options).in_time_zone(time_zone)
207
231
  end
208
232
  end
209
-
210
- %w(year mon month day mday hour min sec).each do |method_name|
233
+
234
+ %w(year mon month day mday wday yday hour min sec to_date).each do |method_name|
211
235
  class_eval <<-EOV
212
236
  def #{method_name}
213
237
  time.#{method_name}
214
238
  end
215
239
  EOV
216
240
  end
217
-
241
+
218
242
  def usec
219
243
  time.respond_to?(:usec) ? time.usec : 0
220
244
  end
221
-
245
+
222
246
  def to_a
223
247
  [time.sec, time.min, time.hour, time.day, time.mon, time.year, time.wday, time.yday, dst?, zone]
224
248
  end
225
-
249
+
226
250
  def to_f
227
251
  utc.to_f
228
- end
229
-
252
+ end
253
+
230
254
  def to_i
231
255
  utc.to_i
232
256
  end
233
257
  alias_method :hash, :to_i
234
258
  alias_method :tv_sec, :to_i
235
-
259
+
236
260
  # A TimeWithZone acts like a Time, so just return +self+.
237
261
  def to_time
238
262
  self
239
263
  end
240
-
264
+
241
265
  def to_datetime
242
266
  utc.to_datetime.new_offset(Rational(utc_offset, 86_400))
243
267
  end
244
-
268
+
245
269
  # So that +self+ <tt>acts_like?(:time)</tt>.
246
270
  def acts_like_time?
247
271
  true
248
272
  end
249
-
273
+
250
274
  # Say we're a Time to thwart type checking.
251
275
  def is_a?(klass)
252
276
  klass == ::Time || super
@@ -261,9 +285,9 @@ module ActiveSupport
261
285
  def marshal_dump
262
286
  [utc, time_zone.name, time]
263
287
  end
264
-
288
+
265
289
  def marshal_load(variables)
266
- initialize(variables[0].utc, ::Time.send!(:get_zone, variables[1]), variables[2].utc)
290
+ initialize(variables[0].utc, ::Time.__send__(:get_zone, variables[1]), variables[2].utc)
267
291
  end
268
292
 
269
293
  # Ensure proxy class responds to all methods that underlying time instance responds to.
@@ -278,10 +302,10 @@ module ActiveSupport
278
302
  result = time.__send__(sym, *args, &block)
279
303
  result.acts_like?(:time) ? self.class.new(nil, time_zone, result) : result
280
304
  end
281
-
282
- private
305
+
306
+ private
283
307
  def get_period_and_ensure_valid_local_time
284
- # we don't want a Time.local instance enforcing its own DST rules as well,
308
+ # we don't want a Time.local instance enforcing its own DST rules as well,
285
309
  # so transfer time values to a utc constructor if necessary
286
310
  @time = transfer_time_values_to_utc_constructor(@time) unless @time.utc?
287
311
  begin
@@ -292,11 +316,11 @@ module ActiveSupport
292
316
  retry
293
317
  end
294
318
  end
295
-
319
+
296
320
  def transfer_time_values_to_utc_constructor(time)
297
321
  ::Time.utc_time(time.year, time.month, time.day, time.hour, time.min, time.sec, time.respond_to?(:usec) ? time.usec : 0)
298
322
  end
299
-
323
+
300
324
  def duration_of_variable_length?(obj)
301
325
  ActiveSupport::Duration === obj && obj.parts.flatten.detect {|p| [:years, :months, :days].include? p }
302
326
  end
@@ -124,7 +124,7 @@ module ActiveSupport
124
124
  "Kathmandu" => "Asia/Katmandu",
125
125
  "Astana" => "Asia/Dhaka",
126
126
  "Dhaka" => "Asia/Dhaka",
127
- "Sri Jayawardenepura" => "Asia/Dhaka",
127
+ "Sri Jayawardenepura" => "Asia/Colombo",
128
128
  "Almaty" => "Asia/Almaty",
129
129
  "Novosibirsk" => "Asia/Novosibirsk",
130
130
  "Rangoon" => "Asia/Rangoon",
@@ -201,6 +201,12 @@ module ActiveSupport
201
201
  result
202
202
  end
203
203
 
204
+ # Compare #name and TZInfo identifier to a supplied regexp, returning true
205
+ # if a match is found.
206
+ def =~(re)
207
+ return true if name =~ re || MAPPING[name] =~ re
208
+ end
209
+
204
210
  # Returns a textual representation of this time zone.
205
211
  def to_s
206
212
  "(GMT#{formatted_offset}) #{name}"
@@ -298,7 +304,8 @@ module ActiveSupport
298
304
  "Mexico City", "Monterrey", "Central America" ],
299
305
  [-18_000, "Eastern Time (US & Canada)", "Indiana (East)", "Bogota",
300
306
  "Lima", "Quito" ],
301
- [-14_400, "Atlantic Time (Canada)", "Caracas", "La Paz", "Santiago" ],
307
+ [-16_200, "Caracas" ],
308
+ [-14_400, "Atlantic Time (Canada)", "La Paz", "Santiago" ],
302
309
  [-12_600, "Newfoundland" ],
303
310
  [-10_800, "Brasilia", "Buenos Aires", "Georgetown", "Greenland" ],
304
311
  [ -7_200, "Mid-Atlantic" ],
@@ -319,9 +326,9 @@ module ActiveSupport
319
326
  [ 14_400, "Abu Dhabi", "Muscat", "Baku", "Tbilisi", "Yerevan" ],
320
327
  [ 16_200, "Kabul" ],
321
328
  [ 18_000, "Ekaterinburg", "Islamabad", "Karachi", "Tashkent" ],
322
- [ 19_800, "Chennai", "Kolkata", "Mumbai", "New Delhi" ],
329
+ [ 19_800, "Chennai", "Kolkata", "Mumbai", "New Delhi", "Sri Jayawardenepura" ],
323
330
  [ 20_700, "Kathmandu" ],
324
- [ 21_600, "Astana", "Dhaka", "Sri Jayawardenepura", "Almaty",
331
+ [ 21_600, "Astana", "Dhaka", "Almaty",
325
332
  "Novosibirsk" ],
326
333
  [ 23_400, "Rangoon" ],
327
334
  [ 25_200, "Bangkok", "Hanoi", "Jakarta", "Krasnoyarsk" ],
@@ -14,13 +14,21 @@ rescue Gem::LoadError
14
14
  end
15
15
 
16
16
  begin
17
- gem 'memcache-client', '~> 1.5.0'
17
+ gem 'memcache-client', '~> 1.5.1'
18
18
  rescue Gem::LoadError
19
- $:.unshift "#{File.dirname(__FILE__)}/vendor/memcache-client-1.5.0"
19
+ $:.unshift "#{File.dirname(__FILE__)}/vendor/memcache-client-1.5.1"
20
20
  end
21
21
 
22
22
  begin
23
- gem 'tzinfo', '~> 0.3.11'
23
+ gem 'tzinfo', '~> 0.3.12'
24
24
  rescue Gem::LoadError
25
- $:.unshift "#{File.dirname(__FILE__)}/vendor/tzinfo-0.3.11"
26
- end
25
+ $:.unshift "#{File.dirname(__FILE__)}/vendor/tzinfo-0.3.12"
26
+ end
27
+
28
+ # TODO I18n gem has not been released yet
29
+ # begin
30
+ # gem 'i18n', '~> 0.0.1'
31
+ # rescue Gem::LoadError
32
+ $:.unshift "#{File.dirname(__FILE__)}/vendor/i18n-0.0.1"
33
+ require 'i18n'
34
+ # end
@@ -20,7 +20,7 @@ module Builder
20
20
  # markup.
21
21
  #
22
22
  # Usage:
23
- # xe = Builder::XmlEvents.new(hander)
23
+ # xe = Builder::XmlEvents.new(handler)
24
24
  # xe.title("HI") # Sends start_tag/end_tag/text messages to the handler.
25
25
  #
26
26
  # Indentation may also be selected by providing value for the
@@ -0,0 +1,194 @@
1
+ # Authors:: Matt Aimonetti (http://railsontherun.com/),
2
+ # Sven Fuchs (http://www.artweb-design.de),
3
+ # Joshua Harvey (http://www.workingwithrails.com/person/759-joshua-harvey),
4
+ # Saimon Moore (http://saimonmoore.net),
5
+ # Stephan Soller (http://www.arkanis-development.de/)
6
+ # Copyright:: Copyright (c) 2008 The Ruby i18n Team
7
+ # License:: MIT
8
+ require 'i18n/backend/simple'
9
+ require 'i18n/exceptions'
10
+
11
+ module I18n
12
+ @@backend = nil
13
+ @@load_path = nil
14
+ @@default_locale = :'en'
15
+ @@exception_handler = :default_exception_handler
16
+
17
+ class << self
18
+ # Returns the current backend. Defaults to +Backend::Simple+.
19
+ def backend
20
+ @@backend ||= Backend::Simple.new
21
+ end
22
+
23
+ # Sets the current backend. Used to set a custom backend.
24
+ def backend=(backend)
25
+ @@backend = backend
26
+ end
27
+
28
+ # Returns the current default locale. Defaults to 'en'
29
+ def default_locale
30
+ @@default_locale
31
+ end
32
+
33
+ # Sets the current default locale. Used to set a custom default locale.
34
+ def default_locale=(locale)
35
+ @@default_locale = locale
36
+ end
37
+
38
+ # Returns the current locale. Defaults to I18n.default_locale.
39
+ def locale
40
+ Thread.current[:locale] ||= default_locale
41
+ end
42
+
43
+ # Sets the current locale pseudo-globally, i.e. in the Thread.current hash.
44
+ def locale=(locale)
45
+ Thread.current[:locale] = locale
46
+ end
47
+
48
+ # Sets the exception handler.
49
+ def exception_handler=(exception_handler)
50
+ @@exception_handler = exception_handler
51
+ end
52
+
53
+ # Allow clients to register paths providing translation data sources. The
54
+ # backend defines acceptable sources.
55
+ #
56
+ # E.g. the provided SimpleBackend accepts a list of paths to translation
57
+ # files which are either named *.rb and contain plain Ruby Hashes or are
58
+ # named *.yml and contain YAML data. So for the SimpleBackend clients may
59
+ # register translation files like this:
60
+ # I18n.load_path << 'path/to/locale/en.yml'
61
+ def load_path
62
+ @@load_path ||= []
63
+ end
64
+
65
+ # Sets the load path instance. Custom implementations are expected to
66
+ # behave like a Ruby Array.
67
+ def load_path=(load_path)
68
+ @@load_path = load_path
69
+ end
70
+
71
+ # Tells the backend to reload translations. Used in situations like the
72
+ # Rails development environment. Backends can implement whatever strategy
73
+ # is useful.
74
+ def reload!
75
+ backend.reload!
76
+ end
77
+
78
+ # Translates, pluralizes and interpolates a given key using a given locale,
79
+ # scope, and default, as well as interpolation values.
80
+ #
81
+ # *LOOKUP*
82
+ #
83
+ # Translation data is organized as a nested hash using the upper-level keys
84
+ # as namespaces. <em>E.g.</em>, ActionView ships with the translation:
85
+ # <tt>:date => {:formats => {:short => "%b %d"}}</tt>.
86
+ #
87
+ # Translations can be looked up at any level of this hash using the key argument
88
+ # and the scope option. <em>E.g.</em>, in this example <tt>I18n.t :date</tt>
89
+ # returns the whole translations hash <tt>{:formats => {:short => "%b %d"}}</tt>.
90
+ #
91
+ # Key can be either a single key or a dot-separated key (both Strings and Symbols
92
+ # work). <em>E.g.</em>, the short format can be looked up using both:
93
+ # I18n.t 'date.formats.short'
94
+ # I18n.t :'date.formats.short'
95
+ #
96
+ # Scope can be either a single key, a dot-separated key or an array of keys
97
+ # or dot-separated keys. Keys and scopes can be combined freely. So these
98
+ # examples will all look up the same short date format:
99
+ # I18n.t 'date.formats.short'
100
+ # I18n.t 'formats.short', :scope => 'date'
101
+ # I18n.t 'short', :scope => 'date.formats'
102
+ # I18n.t 'short', :scope => %w(date formats)
103
+ #
104
+ # *INTERPOLATION*
105
+ #
106
+ # Translations can contain interpolation variables which will be replaced by
107
+ # values passed to #translate as part of the options hash, with the keys matching
108
+ # the interpolation variable names.
109
+ #
110
+ # <em>E.g.</em>, with a translation <tt>:foo => "foo {{bar}}"</tt> the option
111
+ # value for the key +bar+ will be interpolated into the translation:
112
+ # I18n.t :foo, :bar => 'baz' # => 'foo baz'
113
+ #
114
+ # *PLURALIZATION*
115
+ #
116
+ # Translation data can contain pluralized translations. Pluralized translations
117
+ # are arrays of singluar/plural versions of translations like <tt>['Foo', 'Foos']</tt>.
118
+ #
119
+ # Note that <tt>I18n::Backend::Simple</tt> only supports an algorithm for English
120
+ # pluralization rules. Other algorithms can be supported by custom backends.
121
+ #
122
+ # This returns the singular version of a pluralized translation:
123
+ # I18n.t :foo, :count => 1 # => 'Foo'
124
+ #
125
+ # These both return the plural version of a pluralized translation:
126
+ # I18n.t :foo, :count => 0 # => 'Foos'
127
+ # I18n.t :foo, :count => 2 # => 'Foos'
128
+ #
129
+ # The <tt>:count</tt> option can be used both for pluralization and interpolation.
130
+ # <em>E.g.</em>, with the translation
131
+ # <tt>:foo => ['{{count}} foo', '{{count}} foos']</tt>, count will
132
+ # be interpolated to the pluralized translation:
133
+ # I18n.t :foo, :count => 1 # => '1 foo'
134
+ #
135
+ # *DEFAULTS*
136
+ #
137
+ # This returns the translation for <tt>:foo</tt> or <tt>default</tt> if no translation was found:
138
+ # I18n.t :foo, :default => 'default'
139
+ #
140
+ # This returns the translation for <tt>:foo</tt> or the translation for <tt>:bar</tt> if no
141
+ # translation for <tt>:foo</tt> was found:
142
+ # I18n.t :foo, :default => :bar
143
+ #
144
+ # Returns the translation for <tt>:foo</tt> or the translation for <tt>:bar</tt>
145
+ # or <tt>default</tt> if no translations for <tt>:foo</tt> and <tt>:bar</tt> were found.
146
+ # I18n.t :foo, :default => [:bar, 'default']
147
+ #
148
+ # <b>BULK LOOKUP</b>
149
+ #
150
+ # This returns an array with the translations for <tt>:foo</tt> and <tt>:bar</tt>.
151
+ # I18n.t [:foo, :bar]
152
+ #
153
+ # Can be used with dot-separated nested keys:
154
+ # I18n.t [:'baz.foo', :'baz.bar']
155
+ #
156
+ # Which is the same as using a scope option:
157
+ # I18n.t [:foo, :bar], :scope => :baz
158
+ def translate(key, options = {})
159
+ locale = options.delete(:locale) || I18n.locale
160
+ backend.translate(locale, key, options)
161
+ rescue I18n::ArgumentError => e
162
+ raise e if options[:raise]
163
+ send(@@exception_handler, e, locale, key, options)
164
+ end
165
+ alias :t :translate
166
+
167
+ # Localizes certain objects, such as dates and numbers to local formatting.
168
+ def localize(object, options = {})
169
+ locale = options[:locale] || I18n.locale
170
+ format = options[:format] || :default
171
+ backend.localize(locale, object, format)
172
+ end
173
+ alias :l :localize
174
+
175
+ protected
176
+ # Handles exceptions raised in the backend. All exceptions except for
177
+ # MissingTranslationData exceptions are re-raised. When a MissingTranslationData
178
+ # was caught and the option :raise is not set the handler returns an error
179
+ # message string containing the key/scope.
180
+ def default_exception_handler(exception, locale, key, options)
181
+ return exception.message if MissingTranslationData === exception
182
+ raise exception
183
+ end
184
+
185
+ # Merges the given locale, key and scope into a single array of keys.
186
+ # Splits keys that contain dots into multiple keys. Makes sure all
187
+ # keys are Symbols.
188
+ def normalize_translation_keys(locale, key, scope)
189
+ keys = [locale] + Array(scope) + [key]
190
+ keys = keys.map { |k| k.to_s.split(/\./) }
191
+ keys.flatten.map { |k| k.to_sym }
192
+ end
193
+ end
194
+ end