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
@@ -51,8 +51,8 @@ module ActiveSupport
51
51
 
52
52
  private
53
53
  def deprecation_message(callstack, message = nil)
54
- message ||= "You are using deprecated behavior which will be removed from Rails 2.2"
55
- "DEPRECATION WARNING: #{message} See http://www.rubyonrails.org/deprecation for details. #{deprecation_caller_message(callstack)}"
54
+ message ||= "You are using deprecated behavior which will be removed from the next major or minor release."
55
+ "DEPRECATION WARNING: #{message}. #{deprecation_caller_message(callstack)}"
56
56
  end
57
57
 
58
58
  def deprecation_caller_message(callstack)
@@ -92,7 +92,7 @@ module ActiveSupport
92
92
  class_eval(<<-EOS, __FILE__, __LINE__)
93
93
  def #{target}_with_deprecation#{punctuation}(*args, &block)
94
94
  ::ActiveSupport::Deprecation.warn(self.class.deprecated_method_warning(:#{method_name}, #{options[method_name].inspect}), caller)
95
- send(:#{target}_without_deprecation#{punctuation}, *args, &block)
95
+ #{target}_without_deprecation#{punctuation}(*args, &block)
96
96
  end
97
97
  EOS
98
98
  end
@@ -109,7 +109,7 @@ module ActiveSupport
109
109
  end
110
110
 
111
111
  def deprecation_horizon
112
- '2.2'
112
+ '2.3'
113
113
  end
114
114
  end
115
115
 
@@ -162,6 +162,22 @@ module ActiveSupport
162
162
  end
163
163
  end
164
164
 
165
+ class DeprecatedObjectProxy < DeprecationProxy
166
+ def initialize(object, message)
167
+ @object = object
168
+ @message = message
169
+ end
170
+
171
+ private
172
+ def target
173
+ @object
174
+ end
175
+
176
+ def warn(callstack, called, args)
177
+ ActiveSupport::Deprecation.warn(@message, callstack)
178
+ end
179
+ end
180
+
165
181
  # Stand-in for <tt>@request</tt>, <tt>@attributes</tt>, <tt>@params</tt>, etc.
166
182
  # which emits deprecation warnings on any method call (except +inspect+).
167
183
  class DeprecatedInstanceVariableProxy < DeprecationProxy #:nodoc:
@@ -185,6 +201,10 @@ module ActiveSupport
185
201
  @new_const = new_const
186
202
  end
187
203
 
204
+ def class
205
+ target.class
206
+ end
207
+
188
208
  private
189
209
  def target
190
210
  @new_const.to_s.constantize
@@ -1,4 +1,6 @@
1
+ # encoding: utf-8
1
2
  require 'singleton'
3
+ require 'iconv'
2
4
 
3
5
  module ActiveSupport
4
6
  # The Inflector transforms words from singular to plural, class names to table names, modularized class names to ones without,
@@ -10,10 +12,12 @@ module ActiveSupport
10
12
  # If you discover an incorrect inflection and require it for your application, you'll need
11
13
  # to correct it yourself (explained below).
12
14
  module Inflector
15
+ extend self
16
+
13
17
  # A singleton instance of this class is yielded by Inflector.inflections, which can then be used to specify additional
14
18
  # inflection rules. Examples:
15
19
  #
16
- # Inflector.inflections do |inflect|
20
+ # ActiveSupport::Inflector.inflections do |inflect|
17
21
  # inflect.plural /^(ox)$/i, '\1\2en'
18
22
  # inflect.singular /^(ox)en/i, '\1'
19
23
  #
@@ -28,21 +32,25 @@ module ActiveSupport
28
32
  class Inflections
29
33
  include Singleton
30
34
 
31
- attr_reader :plurals, :singulars, :uncountables
35
+ attr_reader :plurals, :singulars, :uncountables, :humans
32
36
 
33
37
  def initialize
34
- @plurals, @singulars, @uncountables = [], [], []
38
+ @plurals, @singulars, @uncountables, @humans = [], [], [], []
35
39
  end
36
40
 
37
41
  # Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression.
38
42
  # The replacement should always be a string that may include references to the matched data from the rule.
39
43
  def plural(rule, replacement)
44
+ @uncountables.delete(rule) if rule.is_a?(String)
45
+ @uncountables.delete(replacement)
40
46
  @plurals.insert(0, [rule, replacement])
41
47
  end
42
48
 
43
49
  # Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression.
44
50
  # The replacement should always be a string that may include references to the matched data from the rule.
45
51
  def singular(rule, replacement)
52
+ @uncountables.delete(rule) if rule.is_a?(String)
53
+ @uncountables.delete(replacement)
46
54
  @singulars.insert(0, [rule, replacement])
47
55
  end
48
56
 
@@ -53,6 +61,8 @@ module ActiveSupport
53
61
  # irregular 'octopus', 'octopi'
54
62
  # irregular 'person', 'people'
55
63
  def irregular(singular, plural)
64
+ @uncountables.delete(singular)
65
+ @uncountables.delete(plural)
56
66
  if singular[0,1].upcase == plural[0,1].upcase
57
67
  plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1])
58
68
  singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1])
@@ -74,9 +84,20 @@ module ActiveSupport
74
84
  (@uncountables << words).flatten!
75
85
  end
76
86
 
87
+ # Specifies a humanized form of a string by a regular expression rule or by a string mapping.
88
+ # When using a regular expression based replacement, the normal humanize formatting is called after the replacement.
89
+ # When a string is used, the human form should be specified as desired (example: 'The name', not 'the_name')
90
+ #
91
+ # Examples:
92
+ # human /_cnt$/i, '\1_count'
93
+ # human "legacy_col_person_name", "Name"
94
+ def human(rule, replacement)
95
+ @humans.insert(0, [rule, replacement])
96
+ end
97
+
77
98
  # Clears the loaded inflections within a given scope (default is <tt>:all</tt>).
78
99
  # Give the scope as a symbol of the inflection type, the options are: <tt>:plurals</tt>,
79
- # <tt>:singulars</tt>, <tt>:uncountables</tt>.
100
+ # <tt>:singulars</tt>, <tt>:uncountables</tt>, <tt>:humans</tt>.
80
101
  #
81
102
  # Examples:
82
103
  # clear :all
@@ -91,13 +112,11 @@ module ActiveSupport
91
112
  end
92
113
  end
93
114
 
94
- extend self
95
-
96
115
  # Yields a singleton instance of Inflector::Inflections so you can specify additional
97
116
  # inflector rules.
98
117
  #
99
118
  # Example:
100
- # Inflector.inflections do |inflect|
119
+ # ActiveSupport::Inflector.inflections do |inflect|
101
120
  # inflect.uncountable "rails"
102
121
  # end
103
122
  def inflections
@@ -115,7 +134,6 @@ module ActiveSupport
115
134
  # "octopus".pluralize # => "octopi"
116
135
  # "sheep".pluralize # => "sheep"
117
136
  # "words".pluralize # => "words"
118
- # "the blue mailman".pluralize # => "the blue mailmen"
119
137
  # "CamelOctopus".pluralize # => "CamelOctopi"
120
138
  def pluralize(word)
121
139
  result = word.to_s.dup
@@ -134,8 +152,7 @@ module ActiveSupport
134
152
  # "posts".singularize # => "post"
135
153
  # "octopi".singularize # => "octopus"
136
154
  # "sheep".singluarize # => "sheep"
137
- # "word".singluarize # => "word"
138
- # "the blue mailmen".singularize # => "the blue mailman"
155
+ # "word".singularize # => "word"
139
156
  # "CamelOctopi".singularize # => "CamelOctopus"
140
157
  def singularize(word)
141
158
  result = word.to_s.dup
@@ -162,7 +179,7 @@ module ActiveSupport
162
179
  if first_letter_in_uppercase
163
180
  lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
164
181
  else
165
- lower_case_and_underscored_word.first + camelize(lower_case_and_underscored_word)[1..-1]
182
+ lower_case_and_underscored_word.first.downcase + camelize(lower_case_and_underscored_word)[1..-1]
166
183
  end
167
184
  end
168
185
 
@@ -209,7 +226,10 @@ module ActiveSupport
209
226
  # "employee_salary" # => "Employee salary"
210
227
  # "author_id" # => "Author"
211
228
  def humanize(lower_case_and_underscored_word)
212
- lower_case_and_underscored_word.to_s.gsub(/_id$/, "").gsub(/_/, " ").capitalize
229
+ result = lower_case_and_underscored_word.to_s.dup
230
+
231
+ inflections.humans.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
232
+ result.gsub(/_id$/, "").gsub(/_/, " ").capitalize
213
233
  end
214
234
 
215
235
  # Removes the module part from the expression in the string.
@@ -221,6 +241,50 @@ module ActiveSupport
221
241
  class_name_in_module.to_s.gsub(/^.*::/, '')
222
242
  end
223
243
 
244
+ # Replaces special characters in a string so that it may be used as part of a 'pretty' URL.
245
+ #
246
+ # ==== Examples
247
+ #
248
+ # class Person
249
+ # def to_param
250
+ # "#{id}-#{name.parameterize}"
251
+ # end
252
+ # end
253
+ #
254
+ # @person = Person.find(1)
255
+ # # => #<Person id: 1, name: "Donald E. Knuth">
256
+ #
257
+ # <%= link_to(@person.name, person_path %>
258
+ # # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a>
259
+ def parameterize(string, sep = '-')
260
+ re_sep = Regexp.escape(sep)
261
+ # replace accented chars with ther ascii equivalents
262
+ parameterized_string = transliterate(string)
263
+ # Turn unwanted chars into the seperator
264
+ parameterized_string.gsub!(/[^a-z0-9\-_\+]+/i, sep)
265
+ # No more than one of the separator in a row.
266
+ parameterized_string.squeeze!(sep)
267
+ # Remove leading/trailing separator.
268
+ parameterized_string.gsub!(/^#{re_sep}|#{re_sep}$/i, '')
269
+ parameterized_string.downcase
270
+ end
271
+
272
+
273
+ # Replaces accented characters with their ascii equivalents.
274
+ def transliterate(string)
275
+ Iconv.iconv('ascii//ignore//translit', 'utf-8', string).to_s
276
+ end
277
+
278
+ # The iconv transliteration code doesn't function correctly
279
+ # on some platforms, but it's very fast where it does function.
280
+ if "foo" != Inflector.transliterate("föö")
281
+ undef_method :transliterate
282
+ def transliterate(string)
283
+ string.mb_chars.normalize(:kd). # Decompose accented characters
284
+ gsub(/[^\x00-\x7F]+/, '') # Remove anything non-ASCII entirely (e.g. diacritics).
285
+ end
286
+ end
287
+
224
288
  # Create the name of a table like Rails does for models to table names. This method
225
289
  # uses the +pluralize+ method on the last word in the string.
226
290
  #
@@ -259,32 +323,47 @@ module ActiveSupport
259
323
  underscore(demodulize(class_name)) + (separate_class_name_and_id_with_underscore ? "_id" : "id")
260
324
  end
261
325
 
262
- # Tries to find a constant with the name specified in the argument string:
263
- #
264
- # "Module".constantize # => Module
265
- # "Test::Unit".constantize # => Test::Unit
266
- #
267
- # The name is assumed to be the one of a top-level constant, no matter whether
268
- # it starts with "::" or not. No lexical context is taken into account:
269
- #
270
- # C = 'outside'
271
- # module M
272
- # C = 'inside'
273
- # C # => 'inside'
274
- # "C".constantize # => 'outside', same as ::C
275
- # end
276
- #
277
- # NameError is raised when the name is not in CamelCase or the constant is
278
- # unknown.
279
- def constantize(camel_cased_word)
280
- names = camel_cased_word.split('::')
281
- names.shift if names.empty? || names.first.empty?
282
-
283
- constant = Object
284
- names.each do |name|
285
- constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
326
+ # Ruby 1.9 introduces an inherit argument for Module#const_get and
327
+ # #const_defined? and changes their default behavior.
328
+ if Module.method(:const_get).arity == 1
329
+ # Tries to find a constant with the name specified in the argument string:
330
+ #
331
+ # "Module".constantize # => Module
332
+ # "Test::Unit".constantize # => Test::Unit
333
+ #
334
+ # The name is assumed to be the one of a top-level constant, no matter whether
335
+ # it starts with "::" or not. No lexical context is taken into account:
336
+ #
337
+ # C = 'outside'
338
+ # module M
339
+ # C = 'inside'
340
+ # C # => 'inside'
341
+ # "C".constantize # => 'outside', same as ::C
342
+ # end
343
+ #
344
+ # NameError is raised when the name is not in CamelCase or the constant is
345
+ # unknown.
346
+ def constantize(camel_cased_word)
347
+ names = camel_cased_word.split('::')
348
+ names.shift if names.empty? || names.first.empty?
349
+
350
+ constant = Object
351
+ names.each do |name|
352
+ constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
353
+ end
354
+ constant
355
+ end
356
+ else
357
+ def constantize(camel_cased_word) #:nodoc:
358
+ names = camel_cased_word.split('::')
359
+ names.shift if names.empty? || names.first.empty?
360
+
361
+ constant = Object
362
+ names.each do |name|
363
+ constant = constant.const_get(name, false) || constant.const_missing(name)
364
+ end
365
+ constant
286
366
  end
287
- constant
288
367
  end
289
368
 
290
369
  # Turns a number into an ordinal string used to denote the position in an
@@ -310,4 +389,9 @@ module ActiveSupport
310
389
  end
311
390
  end
312
391
 
313
- require File.dirname(__FILE__) + '/inflections'
392
+ # in case active_support/inflector is required without the rest of active_support
393
+ require 'active_support/inflections'
394
+ require 'active_support/core_ext/string/inflections'
395
+ unless String.included_modules.include?(ActiveSupport::CoreExtensions::String::Inflections)
396
+ String.send :include, ActiveSupport::CoreExtensions::String::Inflections
397
+ end
@@ -1,5 +1,5 @@
1
1
  module ActiveSupport
2
- # If true, use ISO 8601 format for dates and times. Otherwise, fall back to the Active Support legacy format.
2
+ # If true, use ISO 8601 format for dates and times. Otherwise, fall back to the Active Support legacy format.
3
3
  mattr_accessor :use_standard_json_time_format
4
4
 
5
5
  class << self
@@ -1,7 +1,14 @@
1
1
  class Date
2
- # Returns a JSON string representing the date.
2
+ # Returns a JSON string representing the date. If ActiveSupport.use_standard_json_time_format is set to true, the
3
+ # ISO 8601 format is used.
3
4
  #
4
- # ==== Example:
5
+ # ==== Examples:
6
+ #
7
+ # # With ActiveSupport.use_standard_json_time_format = true
8
+ # Date.new(2005,2,1).to_json
9
+ # # => "2005-02-01"
10
+ #
11
+ # # With ActiveSupport.use_standard_json_time_format = false
5
12
  # Date.new(2005,2,1).to_json
6
13
  # # => "2005/02/01"
7
14
  def to_json(options = nil)
@@ -1,7 +1,14 @@
1
1
  class DateTime
2
- # Returns a JSON string representing the datetime.
2
+ # Returns a JSON string representing the datetime. If ActiveSupport.use_standard_json_time_format is set to true, the
3
+ # ISO 8601 format is used.
3
4
  #
4
- # ==== Example:
5
+ # ==== Examples:
6
+ #
7
+ # # With ActiveSupport.use_standard_json_time_format = true
8
+ # DateTime.civil(2005,2,1,15,15,10).to_json
9
+ # # => "2005-02-01T15:15:10+00:00"
10
+ #
11
+ # # With ActiveSupport.use_standard_json_time_format = false
5
12
  # DateTime.civil(2005,2,1,15,15,10).to_json
6
13
  # # => "2005/02/01 15:15:10 +0000"
7
14
  def to_json(options = nil)
@@ -1,9 +1,16 @@
1
1
  class Time
2
- # Returns a JSON string representing the time.
2
+ # Returns a JSON string representing the time. If ActiveSupport.use_standard_json_time_format is set to true, the
3
+ # ISO 8601 format is used.
3
4
  #
4
- # ==== Example:
5
+ # ==== Examples:
6
+ #
7
+ # # With ActiveSupport.use_standard_json_time_format = true
8
+ # Time.utc(2005,2,1,15,15,10).to_json
9
+ # # => "2005-02-01T15:15:10Z"
10
+ #
11
+ # # With ActiveSupport.use_standard_json_time_format = false
5
12
  # Time.utc(2005,2,1,15,15,10).to_json
6
- # # => 2005/02/01 15:15:10 +0000"
13
+ # # => "2005/02/01 15:15:10 +0000"
7
14
  def to_json(options = nil)
8
15
  if ActiveSupport.use_standard_json_time_format
9
16
  xmlschema.inspect
@@ -0,0 +1,32 @@
1
+ en:
2
+ date:
3
+ formats:
4
+ # Use the strftime parameters for formats.
5
+ # When no format has been given, it uses default.
6
+ # You can provide other formats here if you like!
7
+ default: "%Y-%m-%d"
8
+ short: "%b %d"
9
+ long: "%B %d, %Y"
10
+
11
+ day_names: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
12
+ abbr_day_names: [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
13
+
14
+ # Don't forget the nil at the beginning; there's no such thing as a 0th month
15
+ month_names: [~, January, February, March, April, May, June, July, August, September, October, November, December]
16
+ abbr_month_names: [~, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
17
+ # Used in date_select and datime_select.
18
+ order: [ :year, :month, :day ]
19
+
20
+ time:
21
+ formats:
22
+ default: "%a, %d %b %Y %H:%M:%S %z"
23
+ short: "%d %b %H:%M"
24
+ long: "%B %d, %Y %H:%M"
25
+ am: "am"
26
+ pm: "pm"
27
+
28
+ # Used in array.to_sentence.
29
+ support:
30
+ array:
31
+ sentence_connector: "and"
32
+ skip_last_comma: false
@@ -0,0 +1,82 @@
1
+ module ActiveSupport
2
+ module Memoizable
3
+ MEMOIZED_IVAR = Proc.new do |symbol|
4
+ "@_memoized_#{symbol.to_s.sub(/\?\Z/, '_query').sub(/!\Z/, '_bang')}".to_sym
5
+ end
6
+
7
+ module Freezable
8
+ def self.included(base)
9
+ base.class_eval do
10
+ unless base.method_defined?(:freeze_without_memoizable)
11
+ alias_method_chain :freeze, :memoizable
12
+ end
13
+ end
14
+ end
15
+
16
+ def freeze_with_memoizable
17
+ memoize_all unless frozen?
18
+ freeze_without_memoizable
19
+ end
20
+
21
+ def memoize_all
22
+ methods.each do |m|
23
+ if m.to_s =~ /^_unmemoized_(.*)/
24
+ if method(m).arity == 0
25
+ __send__($1)
26
+ else
27
+ ivar = MEMOIZED_IVAR.call($1)
28
+ instance_variable_set(ivar, {})
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ def unmemoize_all
35
+ methods.each do |m|
36
+ if m.to_s =~ /^_unmemoized_(.*)/
37
+ ivar = MEMOIZED_IVAR.call($1)
38
+ instance_variable_get(ivar).clear if instance_variable_defined?(ivar)
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ def memoize(*symbols)
45
+ symbols.each do |symbol|
46
+ original_method = :"_unmemoized_#{symbol}"
47
+ memoized_ivar = MEMOIZED_IVAR.call(symbol)
48
+
49
+ class_eval <<-EOS, __FILE__, __LINE__
50
+ include Freezable
51
+
52
+ raise "Already memoized #{symbol}" if method_defined?(:#{original_method})
53
+ alias #{original_method} #{symbol}
54
+
55
+ if instance_method(:#{symbol}).arity == 0
56
+ def #{symbol}(reload = false)
57
+ if reload || !defined?(#{memoized_ivar}) || #{memoized_ivar}.empty?
58
+ #{memoized_ivar} = [#{original_method}.freeze]
59
+ end
60
+ #{memoized_ivar}[0]
61
+ end
62
+ else
63
+ def #{symbol}(*args)
64
+ #{memoized_ivar} ||= {} unless frozen?
65
+ reload = args.pop if args.last == true || args.last == :reload
66
+
67
+ if defined?(#{memoized_ivar}) && #{memoized_ivar}
68
+ if !reload && #{memoized_ivar}.has_key?(args)
69
+ #{memoized_ivar}[args]
70
+ elsif #{memoized_ivar}
71
+ #{memoized_ivar}[args] = #{original_method}(*args).freeze
72
+ end
73
+ else
74
+ #{original_method}(*args)
75
+ end
76
+ end
77
+ end
78
+ EOS
79
+ end
80
+ end
81
+ end
82
+ end