activesupport 3.0.0.beta4 → 3.0.pre

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

Potentially problematic release.


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

Files changed (333) hide show
  1. data/CHANGELOG +1 -100
  2. data/lib/active_support.rb +4 -38
  3. data/lib/active_support/autoload.rb +28 -0
  4. data/lib/active_support/backtrace_cleaner.rb +9 -31
  5. data/lib/active_support/benchmarkable.rb +0 -1
  6. data/lib/active_support/buffered_logger.rb +1 -0
  7. data/lib/active_support/cache.rb +81 -436
  8. data/lib/active_support/cache/compressed_mem_cache_store.rb +13 -6
  9. data/lib/active_support/cache/file_store.rb +41 -139
  10. data/lib/active_support/cache/mem_cache_store.rb +75 -120
  11. data/lib/active_support/cache/memory_store.rb +27 -127
  12. data/lib/active_support/cache/strategy/local_cache.rb +58 -111
  13. data/lib/active_support/cache/synchronized_memory_store.rb +38 -2
  14. data/lib/active_support/callbacks.rb +48 -87
  15. data/lib/active_support/configurable.rb +18 -19
  16. data/lib/active_support/core_ext/array.rb +0 -1
  17. data/lib/active_support/core_ext/array/access.rb +1 -1
  18. data/lib/active_support/core_ext/array/conversions.rb +54 -29
  19. data/lib/active_support/core_ext/array/extract_options.rb +1 -16
  20. data/lib/active_support/core_ext/array/random_access.rb +5 -19
  21. data/lib/active_support/core_ext/array/wrap.rb +9 -13
  22. data/lib/active_support/core_ext/benchmark.rb +12 -0
  23. data/lib/active_support/core_ext/boolean.rb +1 -0
  24. data/lib/active_support/core_ext/boolean/conversions.rb +11 -0
  25. data/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +0 -2
  26. data/lib/active_support/core_ext/class.rb +1 -1
  27. data/lib/active_support/core_ext/class/attribute_accessors.rb +27 -33
  28. data/lib/active_support/core_ext/class/delegating_attributes.rb +41 -35
  29. data/lib/active_support/core_ext/class/inheritable_attributes.rb +13 -22
  30. data/lib/active_support/core_ext/class/removal.rb +53 -0
  31. data/lib/active_support/core_ext/date.rb +7 -0
  32. data/lib/active_support/core_ext/date/calculations.rb +8 -30
  33. data/lib/active_support/core_ext/date/conversions.rb +2 -2
  34. data/lib/active_support/core_ext/date_time.rb +5 -0
  35. data/lib/active_support/core_ext/date_time/calculations.rb +1 -2
  36. data/lib/active_support/core_ext/date_time/conversions.rb +5 -23
  37. data/lib/active_support/core_ext/enumerable.rb +9 -5
  38. data/lib/active_support/core_ext/exception.rb +47 -0
  39. data/lib/active_support/core_ext/file.rb +0 -1
  40. data/lib/active_support/core_ext/file/atomic.rb +2 -3
  41. data/lib/active_support/core_ext/float/rounding.rb +2 -3
  42. data/lib/active_support/core_ext/hash/conversions.rb +145 -65
  43. data/lib/active_support/core_ext/hash/deep_merge.rb +7 -6
  44. data/lib/active_support/core_ext/hash/except.rb +0 -8
  45. data/lib/active_support/core_ext/hash/indifferent_access.rb +0 -5
  46. data/lib/active_support/core_ext/hash/keys.rb +11 -10
  47. data/lib/active_support/core_ext/hash/slice.rb +0 -6
  48. data/lib/active_support/core_ext/integer.rb +1 -1
  49. data/lib/active_support/core_ext/integer/even_odd.rb +16 -0
  50. data/lib/active_support/core_ext/kernel.rb +1 -1
  51. data/lib/active_support/core_ext/kernel/daemonizing.rb +7 -0
  52. data/lib/active_support/core_ext/kernel/debugger.rb +2 -3
  53. data/lib/active_support/core_ext/kernel/reporting.rb +1 -2
  54. data/lib/active_support/core_ext/load_error.rb +30 -17
  55. data/lib/active_support/core_ext/logger.rb +1 -1
  56. data/lib/active_support/core_ext/module.rb +3 -5
  57. data/lib/active_support/core_ext/module/aliasing.rb +1 -1
  58. data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +1 -1
  59. data/lib/active_support/core_ext/module/attr_internal.rb +2 -2
  60. data/lib/active_support/core_ext/module/attribute_accessors.rb +21 -25
  61. data/lib/active_support/core_ext/module/delegation.rb +10 -21
  62. data/lib/active_support/core_ext/module/inclusion.rb +30 -0
  63. data/lib/active_support/core_ext/module/introspection.rb +8 -8
  64. data/lib/active_support/core_ext/module/loading.rb +23 -0
  65. data/lib/active_support/core_ext/module/synchronization.rb +1 -2
  66. data/lib/active_support/core_ext/name_error.rb +1 -3
  67. data/lib/active_support/core_ext/nil.rb +1 -0
  68. data/lib/active_support/core_ext/nil/conversions.rb +5 -0
  69. data/lib/active_support/core_ext/object.rb +2 -6
  70. data/lib/active_support/core_ext/object/blank.rb +2 -20
  71. data/lib/active_support/core_ext/object/conversions.rb +16 -2
  72. data/lib/active_support/core_ext/object/duplicable.rb +1 -23
  73. data/lib/active_support/core_ext/object/extending.rb +77 -8
  74. data/lib/active_support/core_ext/object/instance_variables.rb +7 -0
  75. data/lib/active_support/core_ext/object/metaclass.rb +13 -0
  76. data/lib/active_support/core_ext/object/misc.rb +1 -0
  77. data/lib/active_support/core_ext/object/tap.rb +16 -0
  78. data/lib/active_support/core_ext/object/with_options.rb +0 -2
  79. data/lib/active_support/core_ext/proc.rb +4 -4
  80. data/lib/active_support/core_ext/regexp.rb +22 -0
  81. data/lib/active_support/core_ext/rexml.rb +1 -4
  82. data/lib/active_support/core_ext/string.rb +2 -3
  83. data/lib/active_support/core_ext/string/access.rb +2 -4
  84. data/lib/active_support/core_ext/string/bytesize.rb +5 -0
  85. data/lib/active_support/core_ext/string/conversions.rb +1 -36
  86. data/lib/active_support/core_ext/string/filters.rb +0 -29
  87. data/lib/active_support/core_ext/string/inflections.rb +12 -1
  88. data/lib/active_support/core_ext/string/interpolation.rb +92 -2
  89. data/lib/active_support/core_ext/string/iterators.rb +13 -0
  90. data/lib/active_support/core_ext/string/multibyte.rb +19 -16
  91. data/lib/active_support/core_ext/string/output_safety.rb +35 -101
  92. data/lib/active_support/core_ext/string/starts_ends_with.rb +14 -0
  93. data/lib/active_support/core_ext/string/xchar.rb +1 -1
  94. data/lib/active_support/core_ext/symbol.rb +1 -0
  95. data/lib/active_support/core_ext/symbol/to_proc.rb +14 -0
  96. data/lib/active_support/core_ext/time.rb +10 -0
  97. data/lib/active_support/core_ext/time/calculations.rb +7 -9
  98. data/lib/active_support/core_ext/time/conversions.rb +0 -1
  99. data/lib/active_support/core_ext/time/marshal_with_utc_flag.rb +22 -0
  100. data/lib/active_support/core_ext/uri.rb +4 -10
  101. data/lib/active_support/dependencies.rb +192 -179
  102. data/lib/active_support/deprecated_callbacks.rb +283 -0
  103. data/lib/active_support/deprecation/behaviors.rb +1 -1
  104. data/lib/active_support/deprecation/method_wrappers.rb +9 -10
  105. data/lib/active_support/deprecation/reporting.rb +1 -2
  106. data/lib/active_support/duration.rb +2 -6
  107. data/lib/active_support/hash_with_indifferent_access.rb +1 -9
  108. data/lib/active_support/inflections.rb +1 -1
  109. data/lib/active_support/inflector.rb +407 -4
  110. data/lib/active_support/json/backends/jsongem.rb +9 -12
  111. data/lib/active_support/json/decoding.rb +1 -16
  112. data/lib/active_support/json/encoding.rb +12 -42
  113. data/lib/active_support/locale/en.yml +1 -4
  114. data/lib/active_support/memoizable.rb +1 -1
  115. data/lib/active_support/message_encryptor.rb +0 -1
  116. data/lib/active_support/message_verifier.rb +5 -6
  117. data/lib/active_support/multibyte.rb +22 -7
  118. data/lib/active_support/multibyte/chars.rb +392 -164
  119. data/lib/active_support/multibyte/unicode_database.rb +71 -0
  120. data/lib/active_support/multibyte/utils.rb +7 -6
  121. data/lib/active_support/notifications.rb +113 -23
  122. data/lib/active_support/ordered_hash.rb +11 -35
  123. data/lib/active_support/ordered_options.rb +0 -6
  124. data/lib/active_support/rescuable.rb +4 -7
  125. data/lib/active_support/ruby/shim.rb +6 -4
  126. data/lib/active_support/test_case.rb +7 -2
  127. data/lib/active_support/testing/assertions.rb +0 -15
  128. data/lib/active_support/testing/declarative.rb +1 -1
  129. data/lib/active_support/testing/isolation.rb +19 -63
  130. data/lib/active_support/testing/performance.rb +337 -342
  131. data/lib/active_support/testing/setup_and_teardown.rb +29 -51
  132. data/lib/active_support/time.rb +3 -23
  133. data/lib/active_support/time_with_zone.rb +10 -5
  134. data/lib/active_support/values/time_zone.rb +84 -40
  135. data/lib/active_support/values/unicode_tables.dat +0 -0
  136. data/lib/active_support/vendor.rb +16 -0
  137. data/lib/active_support/vendor/builder-2.1.2/lib/blankslate.rb +113 -0
  138. data/lib/active_support/vendor/builder-2.1.2/lib/builder.rb +13 -0
  139. data/lib/active_support/vendor/builder-2.1.2/lib/builder/blankslate.rb +20 -0
  140. data/lib/active_support/vendor/builder-2.1.2/lib/builder/css.rb +250 -0
  141. data/lib/active_support/vendor/builder-2.1.2/lib/builder/xchar.rb +115 -0
  142. data/lib/active_support/vendor/builder-2.1.2/lib/builder/xmlbase.rb +139 -0
  143. data/lib/active_support/vendor/builder-2.1.2/lib/builder/xmlevents.rb +63 -0
  144. data/lib/active_support/vendor/builder-2.1.2/lib/builder/xmlmarkup.rb +328 -0
  145. data/lib/active_support/vendor/i18n-0.1.3/MIT-LICENSE +20 -0
  146. data/lib/active_support/vendor/i18n-0.1.3/README.textile +20 -0
  147. data/lib/active_support/vendor/i18n-0.1.3/Rakefile +5 -0
  148. data/lib/active_support/vendor/i18n-0.1.3/i18n.gemspec +27 -0
  149. data/lib/active_support/vendor/i18n-0.1.3/lib/i18n.rb +204 -0
  150. data/lib/active_support/vendor/i18n-0.1.3/lib/i18n/backend/simple.rb +215 -0
  151. data/lib/active_support/vendor/i18n-0.1.3/lib/i18n/exceptions.rb +53 -0
  152. data/lib/active_support/vendor/i18n-0.1.3/test/all.rb +5 -0
  153. data/lib/active_support/vendor/i18n-0.1.3/test/i18n_exceptions_test.rb +99 -0
  154. data/lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb +124 -0
  155. data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.rb +1 -0
  156. data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.yml +3 -0
  157. data/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb +567 -0
  158. data/lib/active_support/vendor/memcache-client-1.7.5/lib/memcache.rb +1133 -0
  159. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo.rb +33 -0
  160. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/data_timezone.rb +47 -0
  161. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/data_timezone_info.rb +228 -0
  162. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Algiers.rb +55 -0
  163. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Cairo.rb +219 -0
  164. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Casablanca.rb +42 -0
  165. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Harare.rb +18 -0
  166. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Johannesburg.rb +25 -0
  167. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Monrovia.rb +22 -0
  168. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Nairobi.rb +23 -0
  169. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Argentina/Buenos_Aires.rb +166 -0
  170. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Argentina/San_Juan.rb +86 -0
  171. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Bogota.rb +23 -0
  172. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Caracas.rb +23 -0
  173. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Chicago.rb +283 -0
  174. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Chihuahua.rb +136 -0
  175. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Denver.rb +204 -0
  176. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Godthab.rb +161 -0
  177. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Guatemala.rb +27 -0
  178. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Halifax.rb +274 -0
  179. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Indiana/Indianapolis.rb +149 -0
  180. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Juneau.rb +194 -0
  181. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/La_Paz.rb +22 -0
  182. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Lima.rb +35 -0
  183. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Los_Angeles.rb +232 -0
  184. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Mazatlan.rb +139 -0
  185. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Mexico_City.rb +144 -0
  186. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Monterrey.rb +131 -0
  187. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/New_York.rb +282 -0
  188. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Phoenix.rb +30 -0
  189. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Regina.rb +74 -0
  190. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Santiago.rb +205 -0
  191. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Sao_Paulo.rb +171 -0
  192. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/St_Johns.rb +288 -0
  193. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Tijuana.rb +196 -0
  194. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Almaty.rb +67 -0
  195. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Baghdad.rb +73 -0
  196. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Baku.rb +161 -0
  197. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Bangkok.rb +20 -0
  198. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Chongqing.rb +33 -0
  199. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Colombo.rb +30 -0
  200. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Dhaka.rb +27 -0
  201. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Hong_Kong.rb +87 -0
  202. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Irkutsk.rb +165 -0
  203. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Jakarta.rb +30 -0
  204. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Jerusalem.rb +163 -0
  205. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kabul.rb +20 -0
  206. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kamchatka.rb +163 -0
  207. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Karachi.rb +32 -0
  208. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kathmandu.rb +20 -0
  209. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kolkata.rb +25 -0
  210. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Krasnoyarsk.rb +163 -0
  211. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kuala_Lumpur.rb +31 -0
  212. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kuwait.rb +18 -0
  213. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Magadan.rb +163 -0
  214. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Muscat.rb +18 -0
  215. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Novosibirsk.rb +164 -0
  216. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Rangoon.rb +24 -0
  217. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Riyadh.rb +18 -0
  218. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Seoul.rb +34 -0
  219. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Shanghai.rb +35 -0
  220. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Singapore.rb +33 -0
  221. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Taipei.rb +59 -0
  222. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Tashkent.rb +47 -0
  223. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Tbilisi.rb +78 -0
  224. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Tehran.rb +121 -0
  225. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Tokyo.rb +30 -0
  226. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Ulaanbaatar.rb +65 -0
  227. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Urumqi.rb +33 -0
  228. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Vladivostok.rb +164 -0
  229. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Yakutsk.rb +163 -0
  230. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Yekaterinburg.rb +165 -0
  231. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Yerevan.rb +165 -0
  232. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Atlantic/Azores.rb +270 -0
  233. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Atlantic/Cape_Verde.rb +23 -0
  234. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Atlantic/South_Georgia.rb +18 -0
  235. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Adelaide.rb +187 -0
  236. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Brisbane.rb +35 -0
  237. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Darwin.rb +29 -0
  238. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Hobart.rb +193 -0
  239. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Melbourne.rb +185 -0
  240. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Perth.rb +37 -0
  241. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Sydney.rb +185 -0
  242. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Etc/UTC.rb +16 -0
  243. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Amsterdam.rb +228 -0
  244. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Athens.rb +185 -0
  245. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Belgrade.rb +163 -0
  246. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Berlin.rb +188 -0
  247. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Bratislava.rb +13 -0
  248. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Brussels.rb +232 -0
  249. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Bucharest.rb +181 -0
  250. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Budapest.rb +197 -0
  251. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Copenhagen.rb +179 -0
  252. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Dublin.rb +276 -0
  253. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Helsinki.rb +163 -0
  254. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Istanbul.rb +218 -0
  255. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Kiev.rb +168 -0
  256. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Lisbon.rb +268 -0
  257. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Ljubljana.rb +13 -0
  258. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/London.rb +288 -0
  259. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Madrid.rb +211 -0
  260. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Minsk.rb +170 -0
  261. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Moscow.rb +181 -0
  262. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Paris.rb +232 -0
  263. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Prague.rb +187 -0
  264. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Riga.rb +176 -0
  265. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Rome.rb +215 -0
  266. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Sarajevo.rb +13 -0
  267. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Skopje.rb +13 -0
  268. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Sofia.rb +173 -0
  269. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Stockholm.rb +165 -0
  270. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Tallinn.rb +172 -0
  271. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Vienna.rb +183 -0
  272. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Vilnius.rb +170 -0
  273. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Warsaw.rb +212 -0
  274. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Zagreb.rb +13 -0
  275. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Auckland.rb +202 -0
  276. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Fiji.rb +23 -0
  277. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Guam.rb +22 -0
  278. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Honolulu.rb +28 -0
  279. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Majuro.rb +20 -0
  280. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Midway.rb +25 -0
  281. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Noumea.rb +25 -0
  282. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Pago_Pago.rb +26 -0
  283. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Port_Moresby.rb +20 -0
  284. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Tongatapu.rb +27 -0
  285. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/info_timezone.rb +52 -0
  286. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/linked_timezone.rb +51 -0
  287. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/linked_timezone_info.rb +44 -0
  288. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/offset_rationals.rb +98 -0
  289. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/ruby_core_support.rb +56 -0
  290. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/time_or_datetime.rb +292 -0
  291. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone.rb +508 -0
  292. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone_definition.rb +56 -0
  293. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone_info.rb +40 -0
  294. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone_offset_info.rb +94 -0
  295. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone_period.rb +198 -0
  296. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone_transition_info.rb +129 -0
  297. data/lib/active_support/version.rb +2 -3
  298. data/lib/active_support/whiny_nil.rb +7 -9
  299. data/lib/active_support/xml_mini.rb +1 -126
  300. data/lib/active_support/xml_mini/jdom.rb +0 -2
  301. data/lib/active_support/xml_mini/libxml.rb +86 -24
  302. data/lib/active_support/xml_mini/nokogiri.rb +24 -27
  303. data/lib/active_support/xml_mini/rexml.rb +1 -7
  304. metadata +191 -49
  305. data/lib/active_support/builder.rb +0 -6
  306. data/lib/active_support/core_ext/array/uniq_by.rb +0 -17
  307. data/lib/active_support/core_ext/class/attribute.rb +0 -67
  308. data/lib/active_support/core_ext/class/subclasses.rb +0 -55
  309. data/lib/active_support/core_ext/file/path.rb +0 -5
  310. data/lib/active_support/core_ext/integer/multiple.rb +0 -6
  311. data/lib/active_support/core_ext/kernel/singleton_class.rb +0 -13
  312. data/lib/active_support/core_ext/module/anonymous.rb +0 -24
  313. data/lib/active_support/core_ext/module/method_names.rb +0 -14
  314. data/lib/active_support/core_ext/module/reachable.rb +0 -10
  315. data/lib/active_support/core_ext/module/remove_method.rb +0 -6
  316. data/lib/active_support/core_ext/object/to_param.rb +0 -49
  317. data/lib/active_support/core_ext/object/to_query.rb +0 -27
  318. data/lib/active_support/core_ext/string/encoding.rb +0 -11
  319. data/lib/active_support/core_ext/string/exclude.rb +0 -6
  320. data/lib/active_support/core_ext/time/marshal.rb +0 -56
  321. data/lib/active_support/dependencies/autoload.rb +0 -50
  322. data/lib/active_support/i18n.rb +0 -8
  323. data/lib/active_support/inflector/inflections.rb +0 -211
  324. data/lib/active_support/inflector/methods.rb +0 -141
  325. data/lib/active_support/inflector/transliterate.rb +0 -97
  326. data/lib/active_support/json/backends/yajl.rb +0 -40
  327. data/lib/active_support/lazy_load_hooks.rb +0 -27
  328. data/lib/active_support/multibyte/unicode.rb +0 -393
  329. data/lib/active_support/notifications/fanout.rb +0 -93
  330. data/lib/active_support/notifications/instrumenter.rb +0 -56
  331. data/lib/active_support/railtie.rb +0 -100
  332. data/lib/active_support/xml_mini/libxmlsax.rb +0 -85
  333. data/lib/active_support/xml_mini/nokogirisax.rb +0 -83
@@ -0,0 +1,283 @@
1
+ require 'active_support/core_ext/array/extract_options'
2
+
3
+ module ActiveSupport
4
+ # Callbacks are hooks into the lifecycle of an object that allow you to trigger logic
5
+ # before or after an alteration of the object state.
6
+ #
7
+ # Mixing in this module allows you to define callbacks in your class.
8
+ #
9
+ # Example:
10
+ # class Storage
11
+ # include ActiveSupport::DeprecatedCallbacks
12
+ #
13
+ # define_callbacks :before_save, :after_save
14
+ # end
15
+ #
16
+ # class ConfigStorage < Storage
17
+ # before_save :saving_message
18
+ # def saving_message
19
+ # puts "saving..."
20
+ # end
21
+ #
22
+ # after_save do |object|
23
+ # puts "saved"
24
+ # end
25
+ #
26
+ # def save
27
+ # run_callbacks(:before_save)
28
+ # puts "- save"
29
+ # run_callbacks(:after_save)
30
+ # end
31
+ # end
32
+ #
33
+ # config = ConfigStorage.new
34
+ # config.save
35
+ #
36
+ # Output:
37
+ # saving...
38
+ # - save
39
+ # saved
40
+ #
41
+ # Callbacks from parent classes are inherited.
42
+ #
43
+ # Example:
44
+ # class Storage
45
+ # include ActiveSupport::DeprecatedCallbacks
46
+ #
47
+ # define_callbacks :before_save, :after_save
48
+ #
49
+ # before_save :prepare
50
+ # def prepare
51
+ # puts "preparing save"
52
+ # end
53
+ # end
54
+ #
55
+ # class ConfigStorage < Storage
56
+ # before_save :saving_message
57
+ # def saving_message
58
+ # puts "saving..."
59
+ # end
60
+ #
61
+ # after_save do |object|
62
+ # puts "saved"
63
+ # end
64
+ #
65
+ # def save
66
+ # run_callbacks(:before_save)
67
+ # puts "- save"
68
+ # run_callbacks(:after_save)
69
+ # end
70
+ # end
71
+ #
72
+ # config = ConfigStorage.new
73
+ # config.save
74
+ #
75
+ # Output:
76
+ # preparing save
77
+ # saving...
78
+ # - save
79
+ # saved
80
+ module DeprecatedCallbacks
81
+ class CallbackChain < Array
82
+ def self.build(kind, *methods, &block)
83
+ methods, options = extract_options(*methods, &block)
84
+ methods.map! { |method| Callback.new(kind, method, options) }
85
+ new(methods)
86
+ end
87
+
88
+ def run(object, options = {}, &terminator)
89
+ enumerator = options[:enumerator] || :each
90
+
91
+ unless block_given?
92
+ send(enumerator) { |callback| callback.call(object) }
93
+ else
94
+ send(enumerator) do |callback|
95
+ result = callback.call(object)
96
+ break result if terminator.call(result, object)
97
+ end
98
+ end
99
+ end
100
+
101
+ # TODO: Decompose into more Array like behavior
102
+ def replace_or_append!(chain)
103
+ if index = index(chain)
104
+ self[index] = chain
105
+ else
106
+ self << chain
107
+ end
108
+ self
109
+ end
110
+
111
+ def find(callback, &block)
112
+ select { |c| c == callback && (!block_given? || yield(c)) }.first
113
+ end
114
+
115
+ def delete(callback)
116
+ super(callback.is_a?(Callback) ? callback : find(callback))
117
+ end
118
+
119
+ private
120
+ def self.extract_options(*methods, &block)
121
+ methods.flatten!
122
+ options = methods.extract_options!
123
+ methods << block if block_given?
124
+ return methods, options
125
+ end
126
+
127
+ def extract_options(*methods, &block)
128
+ self.class.extract_options(*methods, &block)
129
+ end
130
+ end
131
+
132
+ class Callback
133
+ attr_reader :kind, :method, :identifier, :options
134
+
135
+ def initialize(kind, method, options = {})
136
+ @kind = kind
137
+ @method = method
138
+ @identifier = options[:identifier]
139
+ @options = options
140
+ end
141
+
142
+ def ==(other)
143
+ case other
144
+ when Callback
145
+ (self.identifier && self.identifier == other.identifier) || self.method == other.method
146
+ else
147
+ (self.identifier && self.identifier == other) || self.method == other
148
+ end
149
+ end
150
+
151
+ def eql?(other)
152
+ self == other
153
+ end
154
+
155
+ def dup
156
+ self.class.new(@kind, @method, @options.dup)
157
+ end
158
+
159
+ def hash
160
+ if @identifier
161
+ @identifier.hash
162
+ else
163
+ @method.hash
164
+ end
165
+ end
166
+
167
+ def call(*args, &block)
168
+ evaluate_method(method, *args, &block) if should_run_callback?(*args)
169
+ rescue LocalJumpError
170
+ raise ArgumentError,
171
+ "Cannot yield from a Proc type filter. The Proc must take two " +
172
+ "arguments and execute #call on the second argument."
173
+ end
174
+
175
+ private
176
+ def evaluate_method(method, *args, &block)
177
+ case method
178
+ when Symbol
179
+ object = args.shift
180
+ object.send(method, *args, &block)
181
+ when String
182
+ eval(method, args.first.instance_eval { binding })
183
+ when Proc, Method
184
+ method.call(*args, &block)
185
+ else
186
+ if method.respond_to?(kind)
187
+ method.send(kind, *args, &block)
188
+ else
189
+ raise ArgumentError,
190
+ "Callbacks must be a symbol denoting the method to call, a string to be evaluated, " +
191
+ "a block to be invoked, or an object responding to the callback method."
192
+ end
193
+ end
194
+ end
195
+
196
+ def should_run_callback?(*args)
197
+ [options[:if]].flatten.compact.all? { |a| evaluate_method(a, *args) } &&
198
+ ![options[:unless]].flatten.compact.any? { |a| evaluate_method(a, *args) }
199
+ end
200
+ end
201
+
202
+ def self.included(base)
203
+ base.extend ClassMethods
204
+ end
205
+
206
+ module ClassMethods
207
+ def define_callbacks(*callbacks)
208
+ ActiveSupport::Deprecation.warn('ActiveSupport::DeprecatedCallbacks has been deprecated in favor of ActiveSupport::Callbacks', caller)
209
+
210
+ callbacks.each do |callback|
211
+ class_eval <<-"end_eval", __FILE__, __LINE__ + 1
212
+ def self.#{callback}(*methods, &block) # def self.before_save(*methods, &block)
213
+ callbacks = CallbackChain.build(:#{callback}, *methods, &block) # callbacks = CallbackChain.build(:before_save, *methods, &block)
214
+ @#{callback}_callbacks ||= CallbackChain.new # @before_save_callbacks ||= CallbackChain.new
215
+ @#{callback}_callbacks.concat callbacks # @before_save_callbacks.concat callbacks
216
+ end # end
217
+ #
218
+ def self.#{callback}_callback_chain # def self.before_save_callback_chain
219
+ @#{callback}_callbacks ||= CallbackChain.new # @before_save_callbacks ||= CallbackChain.new
220
+ #
221
+ if superclass.respond_to?(:#{callback}_callback_chain) # if superclass.respond_to?(:before_save_callback_chain)
222
+ CallbackChain.new( # CallbackChain.new(
223
+ superclass.#{callback}_callback_chain + # superclass.before_save_callback_chain +
224
+ @#{callback}_callbacks # @before_save_callbacks
225
+ ) # )
226
+ else # else
227
+ @#{callback}_callbacks # @before_save_callbacks
228
+ end # end
229
+ end # end
230
+ end_eval
231
+ end
232
+ end
233
+ end
234
+
235
+ # Runs all the callbacks defined for the given options.
236
+ #
237
+ # If a block is given it will be called after each callback receiving as arguments:
238
+ #
239
+ # * the result from the callback
240
+ # * the object which has the callback
241
+ #
242
+ # If the result from the block evaluates to +true+, the callback chain is stopped.
243
+ #
244
+ # Example:
245
+ # class Storage
246
+ # include ActiveSupport::DeprecatedCallbacks
247
+ #
248
+ # define_callbacks :before_save, :after_save
249
+ # end
250
+ #
251
+ # class ConfigStorage < Storage
252
+ # before_save :pass
253
+ # before_save :pass
254
+ # before_save :stop
255
+ # before_save :pass
256
+ #
257
+ # def pass
258
+ # puts "pass"
259
+ # end
260
+ #
261
+ # def stop
262
+ # puts "stop"
263
+ # return false
264
+ # end
265
+ #
266
+ # def save
267
+ # result = run_callbacks(:before_save) { |result, object| result == false }
268
+ # puts "- save" if result
269
+ # end
270
+ # end
271
+ #
272
+ # config = ConfigStorage.new
273
+ # config.save
274
+ #
275
+ # Output:
276
+ # pass
277
+ # pass
278
+ # stop
279
+ def run_callbacks(kind, options = {}, &block)
280
+ self.class.send("#{kind}_callback_chain").run(self, options, &block)
281
+ end
282
+ end
283
+ end
@@ -12,7 +12,7 @@ module ActiveSupport
12
12
  end
13
13
 
14
14
  def default_behavior
15
- Deprecation::DEFAULT_BEHAVIORS[defined?(Rails.env) ? Rails.env.to_s : 'test']
15
+ Deprecation::DEFAULT_BEHAVIORS[defined?(Rails) ? Rails.env.to_s : 'test']
16
16
  end
17
17
  end
18
18
 
@@ -1,6 +1,5 @@
1
1
  require 'active_support/core_ext/module/deprecation'
2
2
  require 'active_support/core_ext/module/aliasing'
3
- require 'active_support/core_ext/array/extract_options'
4
3
 
5
4
  module ActiveSupport
6
5
  class << Deprecation
@@ -12,15 +11,15 @@ module ActiveSupport
12
11
  method_names.each do |method_name|
13
12
  target_module.alias_method_chain(method_name, :deprecation) do |target, punctuation|
14
13
  target_module.module_eval(<<-end_eval, __FILE__, __LINE__ + 1)
15
- def #{target}_with_deprecation#{punctuation}(*args, &block)
16
- ::ActiveSupport::Deprecation.warn(
17
- ::ActiveSupport::Deprecation.deprecated_method_warning(
18
- :#{method_name},
19
- #{options[method_name].inspect}),
20
- caller
21
- )
22
- send(:#{target}_without_deprecation#{punctuation}, *args, &block)
23
- end
14
+ def #{target}_with_deprecation#{punctuation}(*args, &block) # def generate_secret_with_deprecation(*args, &block)
15
+ ::ActiveSupport::Deprecation.warn( # ::ActiveSupport::Deprecation.warn(
16
+ ::ActiveSupport::Deprecation.deprecated_method_warning( # ::ActiveSupport::Deprecation.deprecated_method_warning(
17
+ :#{method_name}, # :generate_secret,
18
+ #{options[method_name].inspect}), # "You should use ActiveSupport::SecureRandom.hex(64)"),
19
+ caller # caller
20
+ ) # )
21
+ send(:#{target}_without_deprecation#{punctuation}, *args, &block) # send(:generate_secret_without_deprecation, *args, &block)
22
+ end # end
24
23
  end_eval
25
24
  end
26
25
  end
@@ -29,8 +29,7 @@ module ActiveSupport
29
29
  private
30
30
  def deprecation_message(callstack, message = nil)
31
31
  message ||= "You are using deprecated behavior which will be removed from the next major or minor release."
32
- message += '.' unless message =~ /\.$/
33
- "DEPRECATION WARNING: #{message} #{deprecation_caller_message(callstack)}"
32
+ "DEPRECATION WARNING: #{message}. #{deprecation_caller_message(callstack)}"
34
33
  end
35
34
 
36
35
  def deprecation_caller_message(callstack)
@@ -1,6 +1,5 @@
1
1
  require 'active_support/basic_object'
2
2
  require 'active_support/core_ext/array/conversions'
3
- require 'active_support/core_ext/object/acts_like'
4
3
 
5
4
  module ActiveSupport
6
5
  # Provides accurate date and time measurements using Date#advance and
@@ -36,9 +35,8 @@ module ActiveSupport
36
35
  end
37
36
 
38
37
  def is_a?(klass) #:nodoc:
39
- Duration == klass || value.is_a?(klass)
38
+ klass == Duration || super
40
39
  end
41
- alias :kind_of? :is_a?
42
40
 
43
41
  # Returns true if <tt>other</tt> is also a Duration instance with the
44
42
  # same <tt>value</tt>, or if <tt>other == value</tt>.
@@ -51,9 +49,7 @@ module ActiveSupport
51
49
  end
52
50
 
53
51
  def self.===(other) #:nodoc:
54
- other.is_a?(Duration)
55
- rescue ::NoMethodError
56
- false
52
+ other.is_a?(Duration) rescue super
57
53
  end
58
54
 
59
55
  # Calculates a new Time or Date that is as far in the future
@@ -1,15 +1,9 @@
1
- require 'active_support/core_ext/hash/keys'
2
-
3
1
  # This class has dubious semantics and we only have it so that
4
2
  # people can write params[:key] instead of params['key']
5
3
  # and they get the same value for both keys.
6
4
 
7
5
  module ActiveSupport
8
6
  class HashWithIndifferentAccess < Hash
9
- def extractable_options?
10
- true
11
- end
12
-
13
7
  def initialize(constructor = {})
14
8
  if constructor.is_a?(Hash)
15
9
  super()
@@ -114,9 +108,7 @@ module ActiveSupport
114
108
  end
115
109
 
116
110
  def stringify_keys!; self end
117
- def stringify_keys; dup end
118
- undef :symbolize_keys!
119
- def symbolize_keys; to_hash.symbolize_keys end
111
+ def symbolize_keys!; self end
120
112
  def to_options!; self end
121
113
 
122
114
  # Convert to a Hash with String keys.
@@ -51,6 +51,6 @@ module ActiveSupport
51
51
  inflect.irregular('move', 'moves')
52
52
  inflect.irregular('cow', 'kine')
53
53
 
54
- inflect.uncountable(%w(equipment information rice money species series fish sheep jeans))
54
+ inflect.uncountable(%w(equipment information rice money species series fish sheep))
55
55
  end
56
56
  end
@@ -1,7 +1,410 @@
1
- # in case active_support/inflector is required without the rest of active_support
2
- require 'active_support/inflector/inflections'
3
- require 'active_support/inflector/transliterate'
4
- require 'active_support/inflector/methods'
1
+ # encoding: utf-8
2
+ require 'iconv'
3
+ require 'active_support/core_ext/object/blank'
4
+ require 'active_support/core_ext/string/access'
5
+ require 'active_support/core_ext/string/multibyte'
6
+
7
+ module ActiveSupport
8
+ # The Inflector transforms words from singular to plural, class names to table names, modularized class names to ones without,
9
+ # and class names to foreign keys. The default inflections for pluralization, singularization, and uncountable words are kept
10
+ # in inflections.rb.
11
+ #
12
+ # The Rails core team has stated patches for the inflections library will not be accepted
13
+ # in order to avoid breaking legacy applications which may be relying on errant inflections.
14
+ # If you discover an incorrect inflection and require it for your application, you'll need
15
+ # to correct it yourself (explained below).
16
+ module Inflector
17
+ extend self
18
+
19
+ # A singleton instance of this class is yielded by Inflector.inflections, which can then be used to specify additional
20
+ # inflection rules. Examples:
21
+ #
22
+ # ActiveSupport::Inflector.inflections do |inflect|
23
+ # inflect.plural /^(ox)$/i, '\1\2en'
24
+ # inflect.singular /^(ox)en/i, '\1'
25
+ #
26
+ # inflect.irregular 'octopus', 'octopi'
27
+ #
28
+ # inflect.uncountable "equipment"
29
+ # end
30
+ #
31
+ # New rules are added at the top. So in the example above, the irregular rule for octopus will now be the first of the
32
+ # pluralization and singularization rules that is runs. This guarantees that your rules run before any of the rules that may
33
+ # already have been loaded.
34
+ class Inflections
35
+ def self.instance
36
+ @__instance__ ||= new
37
+ end
38
+
39
+ attr_reader :plurals, :singulars, :uncountables, :humans
40
+
41
+ def initialize
42
+ @plurals, @singulars, @uncountables, @humans = [], [], [], []
43
+ end
44
+
45
+ # Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression.
46
+ # The replacement should always be a string that may include references to the matched data from the rule.
47
+ def plural(rule, replacement)
48
+ @uncountables.delete(rule) if rule.is_a?(String)
49
+ @uncountables.delete(replacement)
50
+ @plurals.insert(0, [rule, replacement])
51
+ end
52
+
53
+ # Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression.
54
+ # The replacement should always be a string that may include references to the matched data from the rule.
55
+ def singular(rule, replacement)
56
+ @uncountables.delete(rule) if rule.is_a?(String)
57
+ @uncountables.delete(replacement)
58
+ @singulars.insert(0, [rule, replacement])
59
+ end
60
+
61
+ # Specifies a new irregular that applies to both pluralization and singularization at the same time. This can only be used
62
+ # for strings, not regular expressions. You simply pass the irregular in singular and plural form.
63
+ #
64
+ # Examples:
65
+ # irregular 'octopus', 'octopi'
66
+ # irregular 'person', 'people'
67
+ def irregular(singular, plural)
68
+ @uncountables.delete(singular)
69
+ @uncountables.delete(plural)
70
+ if singular[0,1].upcase == plural[0,1].upcase
71
+ plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1])
72
+ plural(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + plural[1..-1])
73
+ singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1])
74
+ else
75
+ plural(Regexp.new("#{singular[0,1].upcase}(?i)#{singular[1..-1]}$"), plural[0,1].upcase + plural[1..-1])
76
+ plural(Regexp.new("#{singular[0,1].downcase}(?i)#{singular[1..-1]}$"), plural[0,1].downcase + plural[1..-1])
77
+ plural(Regexp.new("#{plural[0,1].upcase}(?i)#{plural[1..-1]}$"), plural[0,1].upcase + plural[1..-1])
78
+ plural(Regexp.new("#{plural[0,1].downcase}(?i)#{plural[1..-1]}$"), plural[0,1].downcase + plural[1..-1])
79
+ singular(Regexp.new("#{plural[0,1].upcase}(?i)#{plural[1..-1]}$"), singular[0,1].upcase + singular[1..-1])
80
+ singular(Regexp.new("#{plural[0,1].downcase}(?i)#{plural[1..-1]}$"), singular[0,1].downcase + singular[1..-1])
81
+ end
82
+ end
83
+
84
+ # Add uncountable words that shouldn't be attempted inflected.
85
+ #
86
+ # Examples:
87
+ # uncountable "money"
88
+ # uncountable "money", "information"
89
+ # uncountable %w( money information rice )
90
+ def uncountable(*words)
91
+ (@uncountables << words).flatten!
92
+ end
93
+
94
+ # Specifies a humanized form of a string by a regular expression rule or by a string mapping.
95
+ # When using a regular expression based replacement, the normal humanize formatting is called after the replacement.
96
+ # When a string is used, the human form should be specified as desired (example: 'The name', not 'the_name')
97
+ #
98
+ # Examples:
99
+ # human /_cnt$/i, '\1_count'
100
+ # human "legacy_col_person_name", "Name"
101
+ def human(rule, replacement)
102
+ @humans.insert(0, [rule, replacement])
103
+ end
104
+
105
+ # Clears the loaded inflections within a given scope (default is <tt>:all</tt>).
106
+ # Give the scope as a symbol of the inflection type, the options are: <tt>:plurals</tt>,
107
+ # <tt>:singulars</tt>, <tt>:uncountables</tt>, <tt>:humans</tt>.
108
+ #
109
+ # Examples:
110
+ # clear :all
111
+ # clear :plurals
112
+ def clear(scope = :all)
113
+ case scope
114
+ when :all
115
+ @plurals, @singulars, @uncountables = [], [], []
116
+ else
117
+ instance_variable_set "@#{scope}", []
118
+ end
119
+ end
120
+ end
121
+
122
+ # Yields a singleton instance of Inflector::Inflections so you can specify additional
123
+ # inflector rules.
124
+ #
125
+ # Example:
126
+ # ActiveSupport::Inflector.inflections do |inflect|
127
+ # inflect.uncountable "rails"
128
+ # end
129
+ def inflections
130
+ if block_given?
131
+ yield Inflections.instance
132
+ else
133
+ Inflections.instance
134
+ end
135
+ end
136
+
137
+ # Returns the plural form of the word in the string.
138
+ #
139
+ # Examples:
140
+ # "post".pluralize # => "posts"
141
+ # "octopus".pluralize # => "octopi"
142
+ # "sheep".pluralize # => "sheep"
143
+ # "words".pluralize # => "words"
144
+ # "CamelOctopus".pluralize # => "CamelOctopi"
145
+ def pluralize(word)
146
+ result = word.to_s.dup
147
+
148
+ if word.empty? || inflections.uncountables.include?(result.downcase)
149
+ result
150
+ else
151
+ inflections.plurals.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
152
+ result
153
+ end
154
+ end
155
+
156
+ # The reverse of +pluralize+, returns the singular form of a word in a string.
157
+ #
158
+ # Examples:
159
+ # "posts".singularize # => "post"
160
+ # "octopi".singularize # => "octopus"
161
+ # "sheep".singularize # => "sheep"
162
+ # "word".singularize # => "word"
163
+ # "CamelOctopi".singularize # => "CamelOctopus"
164
+ def singularize(word)
165
+ result = word.to_s.dup
166
+
167
+ if inflections.uncountables.include?(result.downcase)
168
+ result
169
+ else
170
+ inflections.singulars.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
171
+ result
172
+ end
173
+ end
174
+
175
+ # By default, +camelize+ converts strings to UpperCamelCase. If the argument to +camelize+
176
+ # is set to <tt>:lower</tt> then +camelize+ produces lowerCamelCase.
177
+ #
178
+ # +camelize+ will also convert '/' to '::' which is useful for converting paths to namespaces.
179
+ #
180
+ # Examples:
181
+ # "active_record".camelize # => "ActiveRecord"
182
+ # "active_record".camelize(:lower) # => "activeRecord"
183
+ # "active_record/errors".camelize # => "ActiveRecord::Errors"
184
+ # "active_record/errors".camelize(:lower) # => "activeRecord::Errors"
185
+ def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
186
+ if first_letter_in_uppercase
187
+ lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
188
+ else
189
+ lower_case_and_underscored_word.to_s.first.downcase + camelize(lower_case_and_underscored_word)[1..-1]
190
+ end
191
+ end
192
+
193
+ # Capitalizes all the words and replaces some characters in the string to create
194
+ # a nicer looking title. +titleize+ is meant for creating pretty output. It is not
195
+ # used in the Rails internals.
196
+ #
197
+ # +titleize+ is also aliased as as +titlecase+.
198
+ #
199
+ # Examples:
200
+ # "man from the boondocks".titleize # => "Man From The Boondocks"
201
+ # "x-men: the last stand".titleize # => "X Men: The Last Stand"
202
+ def titleize(word)
203
+ humanize(underscore(word)).gsub(/\b('?[a-z])/) { $1.capitalize }
204
+ end
5
205
 
206
+ # The reverse of +camelize+. Makes an underscored, lowercase form from the expression in the string.
207
+ #
208
+ # Changes '::' to '/' to convert namespaces to paths.
209
+ #
210
+ # Examples:
211
+ # "ActiveRecord".underscore # => "active_record"
212
+ # "ActiveRecord::Errors".underscore # => active_record/errors
213
+ def underscore(camel_cased_word)
214
+ camel_cased_word.to_s.gsub(/::/, '/').
215
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
216
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
217
+ tr("-", "_").
218
+ downcase
219
+ end
220
+
221
+ # Replaces underscores with dashes in the string.
222
+ #
223
+ # Example:
224
+ # "puni_puni" # => "puni-puni"
225
+ def dasherize(underscored_word)
226
+ underscored_word.gsub(/_/, '-')
227
+ end
228
+
229
+ # Capitalizes the first word and turns underscores into spaces and strips a
230
+ # trailing "_id", if any. Like +titleize+, this is meant for creating pretty output.
231
+ #
232
+ # Examples:
233
+ # "employee_salary" # => "Employee salary"
234
+ # "author_id" # => "Author"
235
+ def humanize(lower_case_and_underscored_word)
236
+ result = lower_case_and_underscored_word.to_s.dup
237
+
238
+ inflections.humans.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
239
+ result.gsub(/_id$/, "").gsub(/_/, " ").capitalize
240
+ end
241
+
242
+ # Removes the module part from the expression in the string.
243
+ #
244
+ # Examples:
245
+ # "ActiveRecord::CoreExtensions::String::Inflections".demodulize # => "Inflections"
246
+ # "Inflections".demodulize # => "Inflections"
247
+ def demodulize(class_name_in_module)
248
+ class_name_in_module.to_s.gsub(/^.*::/, '')
249
+ end
250
+
251
+ # Replaces special characters in a string so that it may be used as part of a 'pretty' URL.
252
+ #
253
+ # ==== Examples
254
+ #
255
+ # class Person
256
+ # def to_param
257
+ # "#{id}-#{name.parameterize}"
258
+ # end
259
+ # end
260
+ #
261
+ # @person = Person.find(1)
262
+ # # => #<Person id: 1, name: "Donald E. Knuth">
263
+ #
264
+ # <%= link_to(@person.name, person_path(@person)) %>
265
+ # # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a>
266
+ def parameterize(string, sep = '-')
267
+ # replace accented chars with their ascii equivalents
268
+ parameterized_string = transliterate(string)
269
+ # Turn unwanted chars into the separator
270
+ parameterized_string.gsub!(/[^a-z0-9\-_\+]+/i, sep)
271
+ unless sep.blank?
272
+ re_sep = Regexp.escape(sep)
273
+ # No more than one of the separator in a row.
274
+ parameterized_string.gsub!(/#{re_sep}{2,}/, sep)
275
+ # Remove leading/trailing separator.
276
+ parameterized_string.gsub!(/^#{re_sep}|#{re_sep}$/i, '')
277
+ end
278
+ parameterized_string.downcase
279
+ end
280
+
281
+
282
+ # Replaces accented characters with their ascii equivalents.
283
+ def transliterate(string)
284
+ Iconv.iconv('ascii//ignore//translit', 'utf-8', string).to_s
285
+ end
286
+
287
+ if RUBY_VERSION >= '1.9'
288
+ undef_method :transliterate
289
+ def transliterate(string)
290
+ warn "Ruby 1.9 doesn't support Unicode normalization yet"
291
+ string.dup
292
+ end
293
+
294
+ # The iconv transliteration code doesn't function correctly
295
+ # on some platforms, but it's very fast where it does function.
296
+ elsif "foo" != (Inflector.transliterate("föö") rescue nil)
297
+ undef_method :transliterate
298
+ def transliterate(string)
299
+ string.mb_chars.normalize(:kd). # Decompose accented characters
300
+ gsub(/[^\x00-\x7F]+/, '') # Remove anything non-ASCII entirely (e.g. diacritics).
301
+ end
302
+ end
303
+
304
+ # Create the name of a table like Rails does for models to table names. This method
305
+ # uses the +pluralize+ method on the last word in the string.
306
+ #
307
+ # Examples
308
+ # "RawScaledScorer".tableize # => "raw_scaled_scorers"
309
+ # "egg_and_ham".tableize # => "egg_and_hams"
310
+ # "fancyCategory".tableize # => "fancy_categories"
311
+ def tableize(class_name)
312
+ pluralize(underscore(class_name))
313
+ end
314
+
315
+ # Create a class name from a plural table name like Rails does for table names to models.
316
+ # Note that this returns a string and not a Class. (To convert to an actual class
317
+ # follow +classify+ with +constantize+.)
318
+ #
319
+ # Examples:
320
+ # "egg_and_hams".classify # => "EggAndHam"
321
+ # "posts".classify # => "Post"
322
+ #
323
+ # Singular names are not handled correctly:
324
+ # "business".classify # => "Busines"
325
+ def classify(table_name)
326
+ # strip out any leading schema name
327
+ camelize(singularize(table_name.to_s.sub(/.*\./, '')))
328
+ end
329
+
330
+ # Creates a foreign key name from a class name.
331
+ # +separate_class_name_and_id_with_underscore+ sets whether
332
+ # the method should put '_' between the name and 'id'.
333
+ #
334
+ # Examples:
335
+ # "Message".foreign_key # => "message_id"
336
+ # "Message".foreign_key(false) # => "messageid"
337
+ # "Admin::Post".foreign_key # => "post_id"
338
+ def foreign_key(class_name, separate_class_name_and_id_with_underscore = true)
339
+ underscore(demodulize(class_name)) + (separate_class_name_and_id_with_underscore ? "_id" : "id")
340
+ end
341
+
342
+ # Ruby 1.9 introduces an inherit argument for Module#const_get and
343
+ # #const_defined? and changes their default behavior.
344
+ if Module.method(:const_get).arity == 1
345
+ # Tries to find a constant with the name specified in the argument string:
346
+ #
347
+ # "Module".constantize # => Module
348
+ # "Test::Unit".constantize # => Test::Unit
349
+ #
350
+ # The name is assumed to be the one of a top-level constant, no matter whether
351
+ # it starts with "::" or not. No lexical context is taken into account:
352
+ #
353
+ # C = 'outside'
354
+ # module M
355
+ # C = 'inside'
356
+ # C # => 'inside'
357
+ # "C".constantize # => 'outside', same as ::C
358
+ # end
359
+ #
360
+ # NameError is raised when the name is not in CamelCase or the constant is
361
+ # unknown.
362
+ def constantize(camel_cased_word)
363
+ names = camel_cased_word.split('::')
364
+ names.shift if names.empty? || names.first.empty?
365
+
366
+ constant = Object
367
+ names.each do |name|
368
+ constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
369
+ end
370
+ constant
371
+ end
372
+ else
373
+ def constantize(camel_cased_word) #:nodoc:
374
+ names = camel_cased_word.split('::')
375
+ names.shift if names.empty? || names.first.empty?
376
+
377
+ constant = Object
378
+ names.each do |name|
379
+ constant = constant.const_get(name, false) || constant.const_missing(name)
380
+ end
381
+ constant
382
+ end
383
+ end
384
+
385
+ # Turns a number into an ordinal string used to denote the position in an
386
+ # ordered sequence such as 1st, 2nd, 3rd, 4th.
387
+ #
388
+ # Examples:
389
+ # ordinalize(1) # => "1st"
390
+ # ordinalize(2) # => "2nd"
391
+ # ordinalize(1002) # => "1002nd"
392
+ # ordinalize(1003) # => "1003rd"
393
+ def ordinalize(number)
394
+ if (11..13).include?(number.to_i % 100)
395
+ "#{number}th"
396
+ else
397
+ case number.to_i % 10
398
+ when 1; "#{number}st"
399
+ when 2; "#{number}nd"
400
+ when 3; "#{number}rd"
401
+ else "#{number}th"
402
+ end
403
+ end
404
+ end
405
+ end
406
+ end
407
+
408
+ # in case active_support/inflector is required without the rest of active_support
6
409
  require 'active_support/inflections'
7
410
  require 'active_support/core_ext/string/inflections'