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
@@ -1,10 +1,12 @@
1
1
  require 'date'
2
2
  require 'active_support/core_ext/time/behavior'
3
+ require 'active_support/core_ext/time/zones'
3
4
  require 'active_support/core_ext/date_time/calculations'
4
5
  require 'active_support/core_ext/date_time/conversions'
5
6
 
6
7
  class DateTime
7
8
  include ActiveSupport::CoreExtensions::Time::Behavior
9
+ include ActiveSupport::CoreExtensions::Time::Zones
8
10
  include ActiveSupport::CoreExtensions::DateTime::Calculations
9
11
  include ActiveSupport::CoreExtensions::DateTime::Conversions
10
12
  end
@@ -7,6 +7,11 @@ module ActiveSupport #:nodoc:
7
7
  module Calculations
8
8
  def self.included(base) #:nodoc:
9
9
  base.extend ClassMethods
10
+
11
+ base.class_eval do
12
+ alias_method :compare_without_coercion, :<=>
13
+ alias_method :<=>, :compare_with_coercion
14
+ end
10
15
  end
11
16
 
12
17
  module ClassMethods
@@ -37,8 +42,10 @@ module ActiveSupport #:nodoc:
37
42
  )
38
43
  end
39
44
 
40
- # Uses Date to provide precise Time calculations for years, months, and days. The +options+ parameter takes a hash with
41
- # any of these keys: :years, :months, :weeks, :days, :hours, :minutes, :seconds.
45
+ # Uses Date to provide precise Time calculations for years, months, and days.
46
+ # The +options+ parameter takes a hash with any of these keys: <tt>:years</tt>,
47
+ # <tt>:months</tt>, <tt>:weeks</tt>, <tt>:days</tt>, <tt>:hours</tt>,
48
+ # <tt>:minutes</tt>, <tt>:seconds</tt>.
42
49
  def advance(options)
43
50
  d = to_date.advance(options)
44
51
  datetime_advanced_by_date = change(:year => d.year, :month => d.month, :day => d.day)
@@ -71,6 +78,34 @@ module ActiveSupport #:nodoc:
71
78
  def end_of_day
72
79
  change(:hour => 23, :min => 59, :sec => 59)
73
80
  end
81
+
82
+ # Adjusts DateTime to UTC by adding its offset value; offset is set to 0
83
+ #
84
+ # Example:
85
+ #
86
+ # DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-6, 24)) # => Mon, 21 Feb 2005 10:11:12 -0600
87
+ # DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-6, 24)).utc # => Mon, 21 Feb 2005 16:11:12 +0000
88
+ def utc
89
+ new_offset(0)
90
+ end
91
+ alias_method :getutc, :utc
92
+
93
+ # Returns true if offset == 0
94
+ def utc?
95
+ offset == 0
96
+ end
97
+
98
+ # Returns the offset value in seconds
99
+ def utc_offset
100
+ (offset * 86400).to_i
101
+ end
102
+
103
+ # Layers additional behavior on DateTime#<=> so that Time and ActiveSupport::TimeWithZone instances can be compared with a DateTime
104
+ def compare_with_coercion(other)
105
+ other = other.comparable_time if other.respond_to?(:comparable_time)
106
+ other = other.to_datetime unless other.acts_like?(:date)
107
+ compare_without_coercion(other)
108
+ end
74
109
  end
75
110
  end
76
111
  end
@@ -3,16 +3,21 @@ module ActiveSupport #:nodoc:
3
3
  module DateTime #:nodoc:
4
4
  # Converting datetimes to formatted strings, dates, and times.
5
5
  module Conversions
6
- def self.included(base) #:nodoc:
6
+ def self.append_features(base) #:nodoc:
7
7
  base.class_eval do
8
- alias_method :to_datetime_default_s, :to_s
9
- alias_method :to_s, :to_formatted_s
10
8
  alias_method :default_inspect, :inspect
11
- alias_method :inspect, :readable_inspect
9
+ alias_method :to_default_s, :to_s unless (instance_methods(false) & [:to_s, 'to_s']).empty?
12
10
 
13
11
  # Ruby 1.9 has DateTime#to_time which internally relies on Time. We define our own #to_time which allows
14
12
  # DateTimes outside the range of what can be created with Time.
15
- remove_method :to_time if base.instance_methods.include?(:to_time)
13
+ remove_method :to_time if instance_methods.include?(:to_time)
14
+ end
15
+
16
+ super
17
+
18
+ base.class_eval do
19
+ alias_method :to_s, :to_formatted_s
20
+ alias_method :inspect, :readable_inspect
16
21
  end
17
22
  end
18
23
 
@@ -41,17 +46,19 @@ module ActiveSupport #:nodoc:
41
46
  # Time::DATE_FORMATS[:month_and_year] = "%B %Y"
42
47
  # Time::DATE_FORMATS[:short_ordinal] = lambda { |time| time.strftime("%B #{time.day.ordinalize}") }
43
48
  def to_formatted_s(format = :default)
44
- if formatter = ::Time::DATE_FORMATS[format]
45
- if formatter.respond_to?(:call)
46
- formatter.call(self).to_s
47
- else
48
- strftime(formatter)
49
- end
50
- else
51
- to_datetime_default_s
52
- end
49
+ return to_default_s unless formatter = ::Time::DATE_FORMATS[format]
50
+ formatter.respond_to?(:call) ? formatter.call(self).to_s : strftime(formatter)
53
51
  end
54
52
 
53
+ # Returns the +utc_offset+ as an +HH:MM formatted string. Examples:
54
+ #
55
+ # datetime = DateTime.civil(2000, 1, 1, 0, 0, 0, Rational(-6, 24))
56
+ # datetime.formatted_offset # => "-06:00"
57
+ # datetime.formatted_offset(false) # => "-0600"
58
+ def formatted_offset(colon = true, alternate_utc_string = nil)
59
+ utc? && alternate_utc_string || utc_offset.to_utc_offset_s(colon)
60
+ end
61
+
55
62
  # Overrides the default inspect method with a human readable one, e.g., "Mon, 21 Feb 2005 14:30:00 +0000"
56
63
  def readable_inspect
57
64
  to_s(:rfc822)
@@ -77,6 +84,12 @@ module ActiveSupport #:nodoc:
77
84
  def xmlschema
78
85
  strftime("%Y-%m-%dT%H:%M:%S%Z")
79
86
  end if RUBY_VERSION < '1.9'
87
+
88
+ # Converts self to a floating-point number of seconds since the Unix epoch
89
+ def to_f
90
+ days_since_unix_epoch = self - ::DateTime.civil(1970)
91
+ (days_since_unix_epoch * 86_400).to_f
92
+ end
80
93
  end
81
94
  end
82
95
  end
@@ -1,11 +1,14 @@
1
1
  module Enumerable
2
+ # Ruby 1.8.7 introduces group_by, but the result isn't ordered. Override it.
3
+ remove_method(:group_by) if [].respond_to?(:group_by) && RUBY_VERSION < '1.9'
4
+
2
5
  # Collect an enumerable into sets, grouped by the result of a block. Useful,
3
6
  # for example, for grouping records by date.
4
7
  #
5
- # e.g.
8
+ # Example:
6
9
  #
7
10
  # latest_transcripts.group_by(&:day).each do |day, transcripts|
8
- # p "#{day} -> #{transcripts.map(&:class) * ', '}"
11
+ # p "#{day} -> #{transcripts.map(&:class).join(', ')}"
9
12
  # end
10
13
  # "2006-03-01 -> Transcript"
11
14
  # "2006-02-28 -> Transcript"
@@ -19,22 +22,26 @@ module Enumerable
19
22
  (grouped[yield(element)] ||= []) << element
20
23
  grouped
21
24
  end
22
- end if RUBY_VERSION < '1.9'
25
+ end unless [].respond_to?(:group_by)
23
26
 
24
27
  # Calculates a sum from the elements. Examples:
25
28
  #
26
29
  # payments.sum { |p| p.price * p.tax_rate }
27
30
  # payments.sum(&:price)
28
31
  #
29
- # This is instead of payments.inject { |sum, p| sum + p.price }
32
+ # The latter is a shortcut for:
33
+ #
34
+ # payments.inject { |sum, p| sum + p.price }
35
+ #
36
+ # It can also calculate the sum without the use of a block.
30
37
  #
31
- # Also calculates sums without the use of a block:
32
- # [5, 15, 10].sum # => 30
38
+ # [5, 15, 10].sum # => 30
39
+ # ["foo", "bar"].sum # => "foobar"
40
+ # [[1, 2], [3, 1, 5]].sum => [1, 2, 3, 1, 5]
33
41
  #
34
- # The default identity (sum of an empty list) is zero.
35
- # However, you can override this default:
42
+ # The default sum of an empty list is zero. You can override this default:
36
43
  #
37
- # [].sum(Payment.new(0)) { |i| i.amount } # => Payment.new(0)
44
+ # [].sum(Payment.new(0)) { |i| i.amount } # => Payment.new(0)
38
45
  #
39
46
  def sum(identity = 0, &block)
40
47
  return identity unless size > 0
@@ -1,3 +1,11 @@
1
+ module ActiveSupport
2
+ if RUBY_VERSION >= '1.9'
3
+ FrozenObjectError = RuntimeError
4
+ else
5
+ FrozenObjectError = TypeError
6
+ end
7
+ end
8
+
1
9
  class Exception # :nodoc:
2
10
  def clean_message
3
11
  Pathname.clean_within message
@@ -3,16 +3,16 @@ require 'tempfile'
3
3
  # Write to a file atomically. Useful for situations where you don't
4
4
  # want other processes or threads to see half-written files.
5
5
  #
6
- # File.atomic_write("important.file") do |file|
7
- # file.write("hello")
8
- # end
6
+ # File.atomic_write("important.file") do |file|
7
+ # file.write("hello")
8
+ # end
9
9
  #
10
10
  # If your temp directory is not on the same filesystem as the file you're
11
11
  # trying to write, you can provide a different temporary directory.
12
12
  #
13
- # File.atomic_write("/data/something.imporant", "/data/tmp") do |f|
14
- # file.write("hello")
15
- # end
13
+ # File.atomic_write("/data/something.important", "/data/tmp") do |f|
14
+ # file.write("hello")
15
+ # end
16
16
  def File.atomic_write(file_name, temp_dir = Dir.tmpdir)
17
17
  temp_file = Tempfile.new(File.basename(file_name), temp_dir)
18
18
  yield temp_file
@@ -24,10 +24,25 @@ class XmlSimple
24
24
  end
25
25
  end
26
26
 
27
+ # This module exists to decorate files deserialized using Hash.from_xml with
28
+ # the <tt>original_filename</tt> and <tt>content_type</tt> methods.
29
+ module FileLike #:nodoc:
30
+ attr_writer :original_filename, :content_type
31
+
32
+ def original_filename
33
+ @original_filename || 'untitled'
34
+ end
35
+
36
+ def content_type
37
+ @content_type || 'application/octet-stream'
38
+ end
39
+ end
40
+
27
41
  module ActiveSupport #:nodoc:
28
42
  module CoreExtensions #:nodoc:
29
43
  module Hash #:nodoc:
30
44
  module Conversions
45
+
31
46
  XML_TYPE_NAMES = {
32
47
  "Symbol" => "symbol",
33
48
  "Fixnum" => "integer",
@@ -55,19 +70,19 @@ module ActiveSupport #:nodoc:
55
70
  XML_PARSING = {
56
71
  "symbol" => Proc.new { |symbol| symbol.to_sym },
57
72
  "date" => Proc.new { |date| ::Date.parse(date) },
58
- "datetime" => Proc.new { |time| ::Time.parse(time).utc },
73
+ "datetime" => Proc.new { |time| ::Time.parse(time).utc rescue ::DateTime.parse(time).utc },
59
74
  "integer" => Proc.new { |integer| integer.to_i },
60
75
  "float" => Proc.new { |float| float.to_f },
61
76
  "decimal" => Proc.new { |number| BigDecimal(number) },
62
77
  "boolean" => Proc.new { |boolean| %w(1 true).include?(boolean.strip) },
63
78
  "string" => Proc.new { |string| string.to_s },
64
79
  "yaml" => Proc.new { |yaml| YAML::load(yaml) rescue yaml },
65
- "base64Binary" => Proc.new { |bin| Base64.decode64(bin) },
66
- # FIXME: Get rid of eval and institute a proper decorator here
80
+ "base64Binary" => Proc.new { |bin| ActiveSupport::Base64.decode64(bin) },
67
81
  "file" => Proc.new do |file, entity|
68
- f = StringIO.new(Base64.decode64(file))
69
- eval "def f.original_filename() '#{entity["name"]}' || 'untitled' end"
70
- eval "def f.content_type() '#{entity["content_type"]}' || 'application/octet-stream' end"
82
+ f = StringIO.new(ActiveSupport::Base64.decode64(file))
83
+ f.extend(FileLike)
84
+ f.original_filename = entity['name']
85
+ f.content_type = entity['content_type']
71
86
  f
72
87
  end
73
88
  }
@@ -94,6 +109,8 @@ module ActiveSupport #:nodoc:
94
109
  value.to_query(namespace ? "#{namespace}[#{key}]" : key)
95
110
  end.sort * '&'
96
111
  end
112
+
113
+ alias_method :to_param, :to_query
97
114
 
98
115
  def to_xml(options = {})
99
116
  options[:indent] ||= 2
@@ -194,8 +211,9 @@ module ActiveSupport #:nodoc:
194
211
  elsif value.blank? || value['nil'] == 'true'
195
212
  nil
196
213
  # If the type is the only element which makes it then
197
- # this still makes the value nil
198
- elsif value['type'] && value.size == 1
214
+ # this still makes the value nil, except if type is
215
+ # a XML node(where type['value'] is a Hash)
216
+ elsif value['type'] && value.size == 1 && !value['type'].is_a?(::Hash)
199
217
  nil
200
218
  else
201
219
  xml_value = value.inject({}) do |h,(k,v)|
@@ -1,5 +1,6 @@
1
1
  # This class has dubious semantics and we only have it so that
2
2
  # people can write params[:key] instead of params['key']
3
+ # and they get the same value for both keys.
3
4
 
4
5
  class HashWithIndifferentAccess < Hash
5
6
  def initialize(constructor = {})
@@ -22,10 +23,25 @@ class HashWithIndifferentAccess < Hash
22
23
  alias_method :regular_writer, :[]= unless method_defined?(:regular_writer)
23
24
  alias_method :regular_update, :update unless method_defined?(:regular_update)
24
25
 
26
+ # Assigns a new value to the hash:
27
+ #
28
+ # hash = HashWithIndifferentAccess.new
29
+ # hash[:key] = "value"
30
+ #
25
31
  def []=(key, value)
26
32
  regular_writer(convert_key(key), convert_value(value))
27
33
  end
28
34
 
35
+ # Updates the instantized hash with values from the second:
36
+ #
37
+ # hash_1 = HashWithIndifferentAccess.new
38
+ # hash_1[:key] = "value"
39
+ #
40
+ # hash_2 = HashWithIndifferentAccess.new
41
+ # hash_2[:key] = "New Value!"
42
+ #
43
+ # hash_1.update(hash_2) # => {"key"=>"New Value!"}
44
+ #
29
45
  def update(other_hash)
30
46
  other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) }
31
47
  self
@@ -33,6 +49,13 @@ class HashWithIndifferentAccess < Hash
33
49
 
34
50
  alias_method :merge!, :update
35
51
 
52
+ # Checks the hash for a key matching the argument passed in:
53
+ #
54
+ # hash = HashWithIndifferentAccess.new
55
+ # hash["key"] = "value"
56
+ # hash.key? :key # => true
57
+ # hash.key? "key" # => true
58
+ #
36
59
  def key?(key)
37
60
  super(convert_key(key))
38
61
  end
@@ -41,22 +64,34 @@ class HashWithIndifferentAccess < Hash
41
64
  alias_method :has_key?, :key?
42
65
  alias_method :member?, :key?
43
66
 
67
+ # Fetches the value for the specified key, same as doing hash[key]
44
68
  def fetch(key, *extras)
45
69
  super(convert_key(key), *extras)
46
70
  end
47
71
 
72
+ # Returns an array of the values at the specified indices:
73
+ #
74
+ # hash = HashWithIndifferentAccess.new
75
+ # hash[:a] = "x"
76
+ # hash[:b] = "y"
77
+ # hash.values_at("a", "b") # => ["x", "y"]
78
+ #
48
79
  def values_at(*indices)
49
80
  indices.collect {|key| self[convert_key(key)]}
50
81
  end
51
82
 
83
+ # Returns an exact copy of the hash.
52
84
  def dup
53
85
  HashWithIndifferentAccess.new(self)
54
86
  end
55
87
 
88
+ # Merges the instantized and the specified hashes together, giving precedence to the values from the second hash
89
+ # Does not overwrite the existing hash.
56
90
  def merge(hash)
57
91
  self.dup.update(hash)
58
92
  end
59
93
 
94
+ # Removes a specified key from the hash.
60
95
  def delete(key)
61
96
  super(convert_key(key))
62
97
  end
@@ -8,12 +8,15 @@ module ActiveSupport #:nodoc:
8
8
  # options.reverse_merge! :size => 25, :velocity => 10
9
9
  # end
10
10
  #
11
- # The default :size and :velocity is only set if the +options+ passed in doesn't already have those keys set.
11
+ # The default <tt>:size</tt> and <tt>:velocity</tt> is only set if the +options+ passed in doesn't already have those keys set.
12
12
  module ReverseMerge
13
+ # Performs the opposite of merge, with the keys and values from the first hash taking precedence over the second.
13
14
  def reverse_merge(other_hash)
14
15
  other_hash.merge(self)
15
16
  end
16
17
 
18
+ # Performs the opposite of merge, with the keys and values from the first hash taking precedence over the second.
19
+ # Modifies the receiver in place.
17
20
  def reverse_merge!(other_hash)
18
21
  replace(reverse_merge(other_hash))
19
22
  end
@@ -1,11 +1,16 @@
1
1
  module ActiveSupport #:nodoc:
2
2
  module CoreExtensions #:nodoc:
3
3
  module Integer #:nodoc:
4
- # For checking if a fixnum is even or odd.
5
- # * 1.even? # => false
6
- # * 1.odd? # => true
7
- # * 2.even? # => true
8
- # * 2.odd? # => false
4
+ # For checking if a fixnum is even or odd.
5
+ #
6
+ # 2.even? # => true
7
+ # 2.odd? # => false
8
+ # 1.even? # => false
9
+ # 1.odd? # => true
10
+ # 0.even? # => true
11
+ # 0.odd? # => false
12
+ # -1.even? # => false
13
+ # -1.odd? # => true
9
14
  module EvenOdd
10
15
  def multiple_of?(number)
11
16
  self % number == 0
@@ -7,7 +7,6 @@ module ActiveSupport #:nodoc:
7
7
  # Ordinalize turns a number into an ordinal string used to denote the
8
8
  # position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
9
9
  #
10
- # Examples
11
10
  # 1.ordinalize # => "1st"
12
11
  # 2.ordinalize # => "2nd"
13
12
  # 1002.ordinalize # => "1002nd"
@@ -2,14 +2,6 @@ module Kernel
2
2
  # Turns the current script into a daemon process that detaches from the console.
3
3
  # It can be shut down with a TERM signal.
4
4
  def daemonize
5
- exit if fork # Parent exits, child continues.
6
- Process.setsid # Become session leader.
7
- exit if fork # Zap session leader. See [1].
8
- Dir.chdir "/" # Release old working directory.
9
- File.umask 0000 # Ensure sensible umask. Adjust as needed.
10
- STDIN.reopen "/dev/null" # Free file descriptors and
11
- STDOUT.reopen "/dev/null", "a" # point them somewhere sensible.
12
- STDERR.reopen STDOUT # STDOUT/ERR should better go to a logfile.
13
- trap("TERM") { exit }
5
+ Process.daemon
14
6
  end
15
- end
7
+ end