activesupport 2.0.5 → 2.1.0

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

Potentially problematic release.


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

Files changed (236) hide show
  1. data/CHANGELOG +183 -5
  2. data/lib/active_support.rb +6 -2
  3. data/lib/active_support/base64.rb +5 -0
  4. data/lib/active_support/basic_object.rb +23 -4
  5. data/lib/active_support/buffered_logger.rb +17 -3
  6. data/lib/active_support/cache.rb +145 -0
  7. data/lib/active_support/cache/compressed_mem_cache_store.rb +15 -0
  8. data/lib/active_support/cache/drb_store.rb +15 -0
  9. data/lib/active_support/cache/file_store.rb +70 -0
  10. data/lib/active_support/cache/mem_cache_store.rb +100 -0
  11. data/lib/active_support/cache/memory_store.rb +38 -0
  12. data/lib/active_support/callbacks.rb +275 -0
  13. data/lib/active_support/core_ext/array/access.rb +2 -4
  14. data/lib/active_support/core_ext/array/conversions.rb +89 -5
  15. data/lib/active_support/core_ext/array/extract_options.rb +2 -1
  16. data/lib/active_support/core_ext/array/grouping.rb +3 -8
  17. data/lib/active_support/core_ext/array/random_access.rb +1 -1
  18. data/lib/active_support/core_ext/base64.rb +4 -0
  19. data/lib/active_support/core_ext/base64/encoding.rb +13 -0
  20. data/lib/active_support/core_ext/benchmark.rb +12 -0
  21. data/lib/active_support/core_ext/bigdecimal.rb +4 -0
  22. data/lib/active_support/core_ext/bigdecimal/conversions.rb +39 -4
  23. data/lib/active_support/core_ext/blank.rb +5 -2
  24. data/lib/active_support/core_ext/class/attribute_accessors.rb +7 -1
  25. data/lib/active_support/core_ext/class/delegating_attributes.rb +7 -1
  26. data/lib/active_support/core_ext/class/inheritable_attributes.rb +1 -1
  27. data/lib/active_support/core_ext/class/removal.rb +26 -0
  28. data/lib/active_support/core_ext/date/calculations.rb +28 -1
  29. data/lib/active_support/core_ext/date/conversions.rb +1 -0
  30. data/lib/active_support/core_ext/date_time.rb +2 -0
  31. data/lib/active_support/core_ext/date_time/calculations.rb +37 -2
  32. data/lib/active_support/core_ext/date_time/conversions.rb +27 -14
  33. data/lib/active_support/core_ext/enumerable.rb +16 -9
  34. data/lib/active_support/core_ext/exception.rb +8 -0
  35. data/lib/active_support/core_ext/file.rb +6 -6
  36. data/lib/active_support/core_ext/hash/conversions.rb +26 -8
  37. data/lib/active_support/core_ext/hash/indifferent_access.rb +35 -0
  38. data/lib/active_support/core_ext/hash/reverse_merge.rb +4 -1
  39. data/lib/active_support/core_ext/integer/even_odd.rb +10 -5
  40. data/lib/active_support/core_ext/integer/inflections.rb +0 -1
  41. data/lib/active_support/core_ext/kernel/daemonizing.rb +2 -10
  42. data/lib/active_support/core_ext/kernel/reporting.rb +8 -0
  43. data/lib/active_support/core_ext/module/attr_internal.rb +4 -3
  44. data/lib/active_support/core_ext/module/attribute_accessors.rb +11 -1
  45. data/lib/active_support/core_ext/module/delegation.rb +5 -3
  46. data/lib/active_support/core_ext/module/inclusion.rb +19 -0
  47. data/lib/active_support/core_ext/module/introspection.rb +50 -16
  48. data/lib/active_support/core_ext/module/loading.rb +10 -0
  49. data/lib/active_support/core_ext/numeric.rb +3 -1
  50. data/lib/active_support/core_ext/numeric/conversions.rb +19 -0
  51. data/lib/active_support/core_ext/object/instance_variables.rb +52 -0
  52. data/lib/active_support/core_ext/object/misc.rb +1 -1
  53. data/lib/active_support/core_ext/process.rb +1 -0
  54. data/lib/active_support/core_ext/process/daemon.rb +25 -0
  55. data/lib/active_support/core_ext/range/conversions.rb +5 -1
  56. data/lib/active_support/core_ext/range/include_range.rb +8 -0
  57. data/lib/active_support/core_ext/range/overlaps.rb +3 -0
  58. data/lib/active_support/core_ext/string.rb +5 -10
  59. data/lib/active_support/core_ext/string/access.rb +72 -48
  60. data/lib/active_support/core_ext/string/conversions.rb +4 -4
  61. data/lib/active_support/core_ext/string/filters.rb +26 -0
  62. data/lib/active_support/core_ext/string/inflections.rb +56 -64
  63. data/lib/active_support/core_ext/string/iterators.rb +4 -0
  64. data/lib/active_support/core_ext/string/starts_ends_with.rb +12 -4
  65. data/lib/active_support/core_ext/string/unicode.rb +14 -7
  66. data/lib/active_support/core_ext/symbol.rb +1 -1
  67. data/lib/active_support/core_ext/time.rb +2 -0
  68. data/lib/active_support/core_ext/time/calculations.rb +75 -23
  69. data/lib/active_support/core_ext/time/conversions.rb +22 -35
  70. data/lib/active_support/core_ext/time/zones.rb +86 -0
  71. data/lib/active_support/dependencies.rb +92 -80
  72. data/lib/active_support/deprecation.rb +2 -16
  73. data/lib/active_support/duration.rb +4 -4
  74. data/lib/active_support/gzip.rb +25 -0
  75. data/lib/active_support/inflector.rb +92 -69
  76. data/lib/active_support/json.rb +17 -25
  77. data/lib/active_support/json/decoding.rb +1 -1
  78. data/lib/active_support/json/encoders/date.rb +11 -2
  79. data/lib/active_support/json/encoders/date_time.rb +11 -2
  80. data/lib/active_support/json/encoders/enumerable.rb +2 -2
  81. data/lib/active_support/json/encoders/hash.rb +3 -6
  82. data/lib/active_support/json/encoders/object.rb +1 -1
  83. data/lib/active_support/json/encoders/string.rb +8 -2
  84. data/lib/active_support/json/encoders/time.rb +11 -2
  85. data/lib/active_support/json/encoding.rb +0 -1
  86. data/lib/active_support/multibyte/chars.rb +8 -6
  87. data/lib/active_support/multibyte/handlers/utf8_handler.rb +11 -11
  88. data/lib/active_support/ordered_hash.rb +43 -0
  89. data/lib/active_support/ordered_options.rb +0 -38
  90. data/lib/active_support/test_case.rb +10 -2
  91. data/lib/active_support/testing/default.rb +3 -6
  92. data/lib/active_support/testing/setup_and_teardown.rb +93 -0
  93. data/lib/active_support/time_with_zone.rb +283 -0
  94. data/lib/active_support/values/time_zone.rb +336 -123
  95. data/lib/active_support/vendor.rb +12 -0
  96. data/lib/active_support/vendor/memcache-client-1.5.0/memcache.rb +849 -0
  97. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo.rb +33 -0
  98. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/data_timezone.rb +47 -0
  99. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/data_timezone_info.rb +226 -0
  100. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Algiers.rb +55 -0
  101. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Cairo.rb +219 -0
  102. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Casablanca.rb +38 -0
  103. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Harare.rb +18 -0
  104. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Johannesburg.rb +25 -0
  105. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Monrovia.rb +22 -0
  106. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Africa/Nairobi.rb +23 -0
  107. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Argentina/Buenos_Aires.rb +166 -0
  108. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Argentina/San_Juan.rb +170 -0
  109. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Bogota.rb +23 -0
  110. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Caracas.rb +23 -0
  111. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Chicago.rb +283 -0
  112. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Chihuahua.rb +136 -0
  113. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Denver.rb +204 -0
  114. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Godthab.rb +161 -0
  115. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Guatemala.rb +27 -0
  116. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Halifax.rb +274 -0
  117. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Indiana/Indianapolis.rb +149 -0
  118. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Juneau.rb +194 -0
  119. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/La_Paz.rb +22 -0
  120. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Lima.rb +35 -0
  121. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Los_Angeles.rb +232 -0
  122. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Mazatlan.rb +139 -0
  123. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Mexico_City.rb +144 -0
  124. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Monterrey.rb +131 -0
  125. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/New_York.rb +282 -0
  126. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Phoenix.rb +30 -0
  127. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Regina.rb +74 -0
  128. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Santiago.rb +205 -0
  129. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/St_Johns.rb +288 -0
  130. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/America/Tijuana.rb +196 -0
  131. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Almaty.rb +67 -0
  132. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Baghdad.rb +73 -0
  133. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Baku.rb +161 -0
  134. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Bangkok.rb +20 -0
  135. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Chongqing.rb +33 -0
  136. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Dhaka.rb +27 -0
  137. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Hong_Kong.rb +87 -0
  138. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Irkutsk.rb +165 -0
  139. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Jakarta.rb +30 -0
  140. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Jerusalem.rb +163 -0
  141. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Kabul.rb +20 -0
  142. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Kamchatka.rb +163 -0
  143. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Karachi.rb +28 -0
  144. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Katmandu.rb +20 -0
  145. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Kolkata.rb +25 -0
  146. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Krasnoyarsk.rb +163 -0
  147. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Kuala_Lumpur.rb +31 -0
  148. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Kuwait.rb +18 -0
  149. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Magadan.rb +163 -0
  150. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Muscat.rb +18 -0
  151. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Novosibirsk.rb +164 -0
  152. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Rangoon.rb +24 -0
  153. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Riyadh.rb +18 -0
  154. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Seoul.rb +34 -0
  155. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Shanghai.rb +35 -0
  156. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Singapore.rb +33 -0
  157. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Taipei.rb +59 -0
  158. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Tashkent.rb +47 -0
  159. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Tbilisi.rb +78 -0
  160. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Tehran.rb +121 -0
  161. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Tokyo.rb +30 -0
  162. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Ulaanbaatar.rb +65 -0
  163. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Urumqi.rb +33 -0
  164. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Vladivostok.rb +164 -0
  165. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Yakutsk.rb +163 -0
  166. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Yekaterinburg.rb +165 -0
  167. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Asia/Yerevan.rb +165 -0
  168. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Atlantic/Azores.rb +270 -0
  169. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Atlantic/Cape_Verde.rb +23 -0
  170. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Atlantic/South_Georgia.rb +18 -0
  171. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Adelaide.rb +187 -0
  172. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Brisbane.rb +35 -0
  173. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Darwin.rb +29 -0
  174. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Hobart.rb +193 -0
  175. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Melbourne.rb +185 -0
  176. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Perth.rb +37 -0
  177. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Australia/Sydney.rb +185 -0
  178. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Etc/UTC.rb +16 -0
  179. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Amsterdam.rb +228 -0
  180. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Athens.rb +185 -0
  181. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Belgrade.rb +163 -0
  182. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Berlin.rb +188 -0
  183. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Bratislava.rb +13 -0
  184. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Brussels.rb +232 -0
  185. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Bucharest.rb +181 -0
  186. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Budapest.rb +197 -0
  187. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Copenhagen.rb +179 -0
  188. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Dublin.rb +276 -0
  189. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Helsinki.rb +163 -0
  190. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Istanbul.rb +218 -0
  191. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Kiev.rb +168 -0
  192. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Lisbon.rb +268 -0
  193. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Ljubljana.rb +13 -0
  194. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/London.rb +288 -0
  195. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Madrid.rb +211 -0
  196. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Minsk.rb +170 -0
  197. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Moscow.rb +181 -0
  198. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Paris.rb +232 -0
  199. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Prague.rb +187 -0
  200. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Riga.rb +176 -0
  201. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Rome.rb +215 -0
  202. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Sarajevo.rb +13 -0
  203. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Skopje.rb +13 -0
  204. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Sofia.rb +173 -0
  205. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Stockholm.rb +165 -0
  206. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Tallinn.rb +172 -0
  207. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Vienna.rb +183 -0
  208. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Vilnius.rb +170 -0
  209. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Warsaw.rb +212 -0
  210. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Europe/Zagreb.rb +13 -0
  211. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Auckland.rb +202 -0
  212. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Fiji.rb +23 -0
  213. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Guam.rb +22 -0
  214. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Honolulu.rb +28 -0
  215. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Majuro.rb +20 -0
  216. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Midway.rb +25 -0
  217. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Noumea.rb +25 -0
  218. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Pago_Pago.rb +26 -0
  219. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Port_Moresby.rb +20 -0
  220. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/definitions/Pacific/Tongatapu.rb +27 -0
  221. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/info_timezone.rb +52 -0
  222. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/linked_timezone.rb +51 -0
  223. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/linked_timezone_info.rb +44 -0
  224. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/offset_rationals.rb +95 -0
  225. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/time_or_datetime.rb +292 -0
  226. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone.rb +508 -0
  227. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_definition.rb +56 -0
  228. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_info.rb +40 -0
  229. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_offset_info.rb +94 -0
  230. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_period.rb +198 -0
  231. data/lib/active_support/vendor/tzinfo-0.3.8/tzinfo/timezone_transition_info.rb +138 -0
  232. data/lib/active_support/version.rb +2 -2
  233. data/lib/active_support/whiny_nil.rb +30 -10
  234. metadata +175 -5
  235. data/lib/active_support/core_ext/rexml.rb +0 -38
  236. data/lib/active_support/testing.rb +0 -1
@@ -3,9 +3,8 @@ module ActiveSupport #:nodoc:
3
3
  module Array #:nodoc:
4
4
  # Makes it easier to access parts of an array.
5
5
  module Access
6
- # Returns the remaining of the array from the +position+.
6
+ # Returns the tail of the array from +position+.
7
7
  #
8
- # Examples:
9
8
  # %w( a b c d ).from(0) # => %w( a b c d )
10
9
  # %w( a b c d ).from(2) # => %w( c d )
11
10
  # %w( a b c d ).from(10) # => nil
@@ -13,9 +12,8 @@ module ActiveSupport #:nodoc:
13
12
  self[position..-1]
14
13
  end
15
14
 
16
- # Returns the beginning of the array up to the +position+.
15
+ # Returns the beginning of the array up to +position+.
17
16
  #
18
- # Examples:
19
17
  # %w( a b c d ).to(0) # => %w( a )
20
18
  # %w( a b c d ).to(2) # => %w( a b c )
21
19
  # %w( a b c d ).to(10) # => %w( a b c d )
@@ -24,16 +24,16 @@ module ActiveSupport #:nodoc:
24
24
  end
25
25
  end
26
26
 
27
- # Calls to_param on all its elements and joins the result with slashes. This is used by url_for in Action Pack.
27
+ # Calls <tt>to_param</tt> on all its elements and joins the result with
28
+ # slashes. This is used by <tt>url_for</tt> in Action Pack.
28
29
  def to_param
29
30
  map(&:to_param).join '/'
30
31
  end
31
32
 
32
- # Converts an array into a string suitable for use as a URL query string, using the given <tt>key</tt> as the
33
- # param name.
33
+ # Converts an array into a string suitable for use as a URL query string,
34
+ # using the given +key+ as the param name.
34
35
  #
35
- # ==== Example:
36
- # ['Rails', 'coding'].to_query('hobbies') => "hobbies%5B%5D=Rails&hobbies%5B%5D=coding"
36
+ # ['Rails', 'coding'].to_query('hobbies') # => "hobbies%5B%5D=Rails&hobbies%5B%5D=coding"
37
37
  def to_query(key)
38
38
  collect { |value| value.to_query("#{key}[]") } * '&'
39
39
  end
@@ -45,6 +45,15 @@ module ActiveSupport #:nodoc:
45
45
  end
46
46
  end
47
47
 
48
+ # Converts a collection of elements into a formatted string by calling
49
+ # <tt>to_s</tt> on all elements and joining them:
50
+ #
51
+ # Blog.find(:all).to_formatted_s # => "First PostSecond PostThird Post"
52
+ #
53
+ # Adding in the <tt>:db</tt> argument as the format yields a prettier
54
+ # output:
55
+ #
56
+ # Blog.find(:all).to_formatted_s(:db) # => "First Post,Second Post,Third Post"
48
57
  def to_formatted_s(format = :default)
49
58
  case format
50
59
  when :db
@@ -58,6 +67,81 @@ module ActiveSupport #:nodoc:
58
67
  end
59
68
  end
60
69
 
70
+ # Returns a string that represents this array in XML by sending +to_xml+
71
+ # to each element. Active Record collections delegate their representation
72
+ # in XML to this method.
73
+ #
74
+ # All elements are expected to respond to +to_xml+, if any of them does
75
+ # not an exception is raised.
76
+ #
77
+ # The root node reflects the class name of the first element in plural
78
+ # if all elements belong to the same type and that's not Hash:
79
+ #
80
+ # customer.projects.to_xml
81
+ #
82
+ # <?xml version="1.0" encoding="UTF-8"?>
83
+ # <projects type="array">
84
+ # <project>
85
+ # <amount type="decimal">20000.0</amount>
86
+ # <customer-id type="integer">1567</customer-id>
87
+ # <deal-date type="date">2008-04-09</deal-date>
88
+ # ...
89
+ # </project>
90
+ # <project>
91
+ # <amount type="decimal">57230.0</amount>
92
+ # <customer-id type="integer">1567</customer-id>
93
+ # <deal-date type="date">2008-04-15</deal-date>
94
+ # ...
95
+ # </project>
96
+ # </projects>
97
+ #
98
+ # Otherwise the root element is "records":
99
+ #
100
+ # [{:foo => 1, :bar => 2}, {:baz => 3}].to_xml
101
+ #
102
+ # <?xml version="1.0" encoding="UTF-8"?>
103
+ # <records type="array">
104
+ # <record>
105
+ # <bar type="integer">2</bar>
106
+ # <foo type="integer">1</foo>
107
+ # </record>
108
+ # <record>
109
+ # <baz type="integer">3</baz>
110
+ # </record>
111
+ # </records>
112
+ #
113
+ # If the collection is empty the root element is "nil-classes" by default:
114
+ #
115
+ # [].to_xml
116
+ #
117
+ # <?xml version="1.0" encoding="UTF-8"?>
118
+ # <nil-classes type="array"/>
119
+ #
120
+ # To ensure a meaningful root element use the <tt>:root</tt> option:
121
+ #
122
+ # customer_with_no_projects.projects.to_xml(:root => "projects")
123
+ #
124
+ # <?xml version="1.0" encoding="UTF-8"?>
125
+ # <projects type="array"/>
126
+ #
127
+ # By default root children have as node name the one of the root
128
+ # singularized. You can change it with the <tt>:children</tt> option.
129
+ #
130
+ # The +options+ hash is passed downwards:
131
+ #
132
+ # Message.all.to_xml(:skip_types => true)
133
+ #
134
+ # <?xml version="1.0" encoding="UTF-8"?>
135
+ # <messages>
136
+ # <message>
137
+ # <created-at>2008-03-07T09:58:18+01:00</created-at>
138
+ # <id>1</id>
139
+ # <name>1</name>
140
+ # <updated-at>2008-03-07T09:58:18+01:00</updated-at>
141
+ # <user-id>1</user-id>
142
+ # </message>
143
+ # </messages>
144
+ #
61
145
  def to_xml(options = {})
62
146
  raise "Not all elements respond to to_xml" unless all? { |e| e.respond_to? :to_xml }
63
147
 
@@ -2,7 +2,8 @@ module ActiveSupport #:nodoc:
2
2
  module CoreExtensions #:nodoc:
3
3
  module Array #:nodoc:
4
4
  module ExtractOptions
5
- # Extract options from a set of arguments. Removes and returns the last element in the array if it's a hash, otherwise returns a blank hash.
5
+ # Extracts options from a set of arguments. Removes and returns the last
6
+ # element in the array if it's a hash, otherwise returns a blank hash.
6
7
  #
7
8
  # def options(*args)
8
9
  # args.extract_options!
@@ -4,11 +4,8 @@ module ActiveSupport #:nodoc:
4
4
  module CoreExtensions #:nodoc:
5
5
  module Array #:nodoc:
6
6
  module Grouping
7
- # Iterate over an array in groups of a certain size, padding any remaining
8
- # slots with specified value (<tt>nil</tt> by default) unless it is
9
- # <tt>false</tt>.
10
- #
11
- # E.g.
7
+ # Iterates over the array in groups of size +number+, padding any remaining
8
+ # slots with +fill_with+ unless it is +false+.
12
9
  #
13
10
  # %w(1 2 3 4 5 6 7).in_groups_of(3) {|g| p g}
14
11
  # ["1", "2", "3"]
@@ -42,11 +39,9 @@ module ActiveSupport #:nodoc:
42
39
  end
43
40
  end
44
41
 
45
- # Divide the array into one or more subarrays based on a delimiting +value+
42
+ # Divides the array into one or more subarrays based on a delimiting +value+
46
43
  # or the result of an optional block.
47
44
  #
48
- # ex.
49
- #
50
45
  # [1, 2, 3, 4, 5].split(3) # => [[1, 2], [4, 5]]
51
46
  # (1..10).to_a.split { |i| i % 3 == 0 } # => [[1, 2], [4, 5], [7, 8], [10]]
52
47
  def split(value = nil, &block)
@@ -2,7 +2,7 @@ module ActiveSupport #:nodoc:
2
2
  module CoreExtensions #:nodoc:
3
3
  module Array #:nodoc:
4
4
  module RandomAccess
5
- # Return a random element from the array.
5
+ # Returns a random element from the array.
6
6
  def rand
7
7
  self[Kernel.rand(length)]
8
8
  end
@@ -0,0 +1,4 @@
1
+ require 'active_support/base64'
2
+ require 'active_support/core_ext/base64/encoding'
3
+
4
+ ActiveSupport::Base64.extend ActiveSupport::CoreExtensions::Base64::Encoding
@@ -0,0 +1,13 @@
1
+ module ActiveSupport #:nodoc:
2
+ module CoreExtensions #:nodoc:
3
+ module Base64 #:nodoc:
4
+ module Encoding
5
+ # Encodes the value as base64 without the newline breaks. This makes the base64 encoding readily usable as URL parameters
6
+ # or memcache keys without further processing.
7
+ def encode64s(value)
8
+ encode64(value).gsub(/\n/, '')
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ require 'benchmark'
2
+
3
+ class << Benchmark
4
+ remove_method :realtime
5
+
6
+ def realtime
7
+ r0 = Time.now
8
+ yield
9
+ r1 = Time.now
10
+ r1.to_f - r0.to_f
11
+ end
12
+ end
@@ -1,2 +1,6 @@
1
1
  require 'bigdecimal'
2
2
  require 'active_support/core_ext/bigdecimal/conversions'
3
+
4
+ class BigDecimal#:nodoc:
5
+ include ActiveSupport::CoreExtensions::BigDecimal::Conversions
6
+ end
@@ -1,6 +1,41 @@
1
- class BigDecimal #:nodoc:
2
- alias :_original_to_s :to_s
3
- def to_s(format="F")
4
- _original_to_s(format)
1
+ require 'yaml'
2
+
3
+ module ActiveSupport #:nodoc:
4
+ module CoreExtensions #:nodoc:
5
+ module BigDecimal #:nodoc:
6
+ module Conversions
7
+ def self.included(base) #:nodoc:
8
+ base.instance_eval do
9
+ alias_method :_original_to_s, :to_s
10
+ alias_method :to_s, :to_formatted_s
11
+ end
12
+ end
13
+
14
+ def to_formatted_s(format="F")
15
+ _original_to_s(format)
16
+ end
17
+
18
+ yaml_as "tag:yaml.org,2002:float"
19
+ def to_yaml( opts = {} )
20
+ YAML::quick_emit( nil, opts ) do |out|
21
+ # This emits the number without any scientific notation.
22
+ # I prefer it to using self.to_f.to_s, which would lose precision.
23
+ #
24
+ # Note that YAML allows that when reconsituting floats
25
+ # to native types, some precision may get lost.
26
+ # There is no full precision real YAML tag that I am aware of.
27
+ str = self.to_s
28
+ if str == "Infinity"
29
+ str = ".Inf"
30
+ elsif str == "-Infinity"
31
+ str = "-.Inf"
32
+ elsif str == "NaN"
33
+ str = ".NaN"
34
+ end
35
+ out.scalar( "tag:yaml.org,2002:float", str, :plain )
36
+ end
37
+ end
38
+ end
39
+ end
5
40
  end
6
41
  end
@@ -1,10 +1,13 @@
1
1
  class Object
2
- # An object is blank if it's nil, empty, or a whitespace string.
3
- # For example, "", " ", nil, [], and {} are blank.
2
+ # An object is blank if it's false, empty, or a whitespace string.
3
+ # For example, "", " ", +nil+, [], and {} are blank.
4
4
  #
5
5
  # This simplifies
6
+ #
6
7
  # if !address.nil? && !address.empty?
8
+ #
7
9
  # to
10
+ #
8
11
  # if !address.blank?
9
12
  def blank?
10
13
  respond_to?(:empty?) ? empty? : !self
@@ -1,6 +1,12 @@
1
1
  # Extends the class object with class and instance accessors for class attributes,
2
2
  # just like the native attr* accessors for instance attributes.
3
- class Class # :nodoc:
3
+ #
4
+ # class Person
5
+ # cattr_accessor :hair_colors
6
+ # end
7
+ #
8
+ # Person.hair_colors = [:brown, :black, :blonde, :red]
9
+ class Class
4
10
  def cattr_reader(*syms)
5
11
  syms.flatten.each do |sym|
6
12
  next if sym.is_a?(Hash)
@@ -19,6 +19,12 @@ class Class
19
19
  def #{name}
20
20
  self.class.#{name}
21
21
  end
22
+ def self.#{name}?
23
+ !!#{name}
24
+ end
25
+ def #{name}?
26
+ !!#{name}
27
+ end
22
28
  EOS
23
29
  end
24
30
  end
@@ -37,4 +43,4 @@ class Class
37
43
  superclass_delegating_reader(*names)
38
44
  superclass_delegating_writer(*names)
39
45
  end
40
- end
46
+ end
@@ -128,7 +128,7 @@ class Class # :nodoc:
128
128
  new_inheritable_attributes = EMPTY_INHERITABLE_ATTRIBUTES
129
129
  else
130
130
  new_inheritable_attributes = inheritable_attributes.inject({}) do |memo, (key, value)|
131
- memo.update(key => (value.dup rescue value))
131
+ memo.update(key => value.duplicable? ? value.dup : value)
132
132
  end
133
133
  end
134
134
 
@@ -1,12 +1,38 @@
1
1
  class Class #:nodoc:
2
+
3
+ # Unassociates the class with its subclasses and removes the subclasses
4
+ # themselves.
5
+ #
6
+ # Integer.remove_subclasses # => [Bignum, Fixnum]
7
+ # Fixnum # => NameError: uninitialized constant Fixnum
2
8
  def remove_subclasses
3
9
  Object.remove_subclasses_of(self)
4
10
  end
5
11
 
12
+ # Returns an array with the names of the subclasses of +self+ as strings.
13
+ #
14
+ # Integer.subclasses # => ["Bignum", "Fixnum"]
6
15
  def subclasses
7
16
  Object.subclasses_of(self).map { |o| o.to_s }
8
17
  end
9
18
 
19
+ # Removes the classes in +klasses+ from their parent module.
20
+ #
21
+ # Ordinary classes belong to some module via a constant. This method computes
22
+ # that constant name from the class name and removes it from the module it
23
+ # belongs to.
24
+ #
25
+ # Object.remove_class(Integer) # => [Integer]
26
+ # Integer # => NameError: uninitialized constant Integer
27
+ #
28
+ # Take into account that in general the class object could be still stored
29
+ # somewhere else.
30
+ #
31
+ # i = Integer # => Integer
32
+ # Object.remove_class(Integer) # => [Integer]
33
+ # Integer # => NameError: uninitialized constant Integer
34
+ # i.subclasses # => ["Bignum", "Fixnum"]
35
+ # Fixnum.superclass # => Integer
10
36
  def remove_class(*klasses)
11
37
  klasses.flatten.each do |klass|
12
38
  # Skip this class if there is nothing bound to this name
@@ -16,13 +16,20 @@ module ActiveSupport #:nodoc:
16
16
  end
17
17
 
18
18
  module ClassMethods
19
+ # Returns a new Date representing the date 1 day ago (i.e. yesterday's date).
19
20
  def yesterday
20
21
  ::Date.today.yesterday
21
22
  end
22
23
 
24
+ # Returns a new Date representing the date 1 day after today (i.e. tomorrow's date).
23
25
  def tomorrow
24
26
  ::Date.today.tomorrow
25
27
  end
28
+
29
+ # Returns Time.zone.today when config.time_zone is set, otherwise just returns Date.today.
30
+ def current
31
+ ::Time.zone_default ? ::Time.zone.today : ::Date.today
32
+ end
26
33
  end
27
34
 
28
35
  # Converts Date to a Time (or DateTime if necessary) with the time portion set to the beginning of the day (0:00)
@@ -68,7 +75,7 @@ module ActiveSupport #:nodoc:
68
75
  end
69
76
 
70
77
  # Provides precise Date calculations for years, months, and days. The +options+ parameter takes a hash with
71
- # any of these keys: :years, :months, :weeks, :days.
78
+ # any of these keys: <tt>:years</tt>, <tt>:months</tt>, <tt>:weeks</tt>, <tt>:days</tt>.
72
79
  def advance(options)
73
80
  d = self
74
81
  d = d >> options.delete(:years) * 12 if options[:years]
@@ -141,6 +148,14 @@ module ActiveSupport #:nodoc:
141
148
  alias :monday :beginning_of_week
142
149
  alias :at_beginning_of_week :beginning_of_week
143
150
 
151
+ # Returns a new Date/DateTime representing the end of this week (Sunday, DateTime objects will have time set to 23:59:59)
152
+ def end_of_week
153
+ days_to_sunday = self.wday!=0 ? 7-self.wday : 0
154
+ result = self + days_to_sunday.days
155
+ self.acts_like?(:time) ? result.end_of_day : result
156
+ end
157
+ alias :at_end_of_week :end_of_week
158
+
144
159
  # Returns a new Date/DateTime representing the start of the given day in next week (default is Monday).
145
160
  def next_week(day = :monday)
146
161
  days_into_week = { :monday => 0, :tuesday => 1, :wednesday => 2, :thursday => 3, :friday => 4, :saturday => 5, :sunday => 6}
@@ -167,12 +182,24 @@ module ActiveSupport #:nodoc:
167
182
  end
168
183
  alias :at_beginning_of_quarter :beginning_of_quarter
169
184
 
185
+ # Returns a new Date/DateTime representing the end of the quarter (last day of march, june, september, december; DateTime objects will have time set to 23:59:59)
186
+ def end_of_quarter
187
+ change(:month => [3, 6, 9, 12].detect { |m| m >= self.month }).end_of_month
188
+ end
189
+ alias :at_end_of_quarter :end_of_quarter
190
+
170
191
  # Returns a new Date/DateTime representing the start of the year (1st of january; DateTime objects will have time set to 0:00)
171
192
  def beginning_of_year
172
193
  self.acts_like?(:time) ? change(:month => 1, :day => 1, :hour => 0, :min => 0, :sec => 0) : change(:month => 1, :day => 1)
173
194
  end
174
195
  alias :at_beginning_of_year :beginning_of_year
175
196
 
197
+ # Returns a new Time representing the end of the year (31st of december; DateTime objects will have time set to 23:59:59)
198
+ def end_of_year
199
+ self.acts_like?(:time) ? change(:month => 12,:day => 31,:hour => 23, :min => 59, :sec => 59) : change(:month => 12, :day => 31)
200
+ end
201
+ alias :at_end_of_year :end_of_year
202
+
176
203
  # Convenience method which returns a new Date/DateTime representing the time 1 day ago
177
204
  def yesterday
178
205
  self - 1
@@ -7,6 +7,7 @@ module ActiveSupport #:nodoc:
7
7
  :short => "%e %b",
8
8
  :long => "%B %e, %Y",
9
9
  :db => "%Y-%m-%d",
10
+ :number => "%Y%m%d",
10
11
  :long_ordinal => lambda { |date| date.strftime("%B #{date.day.ordinalize}, %Y") }, # => "April 25th, 2007"
11
12
  :rfc822 => "%e %b %Y"
12
13
  }