activesupport 3.0.pre → 3.0.0.rc

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 (351) hide show
  1. data/CHANGELOG +121 -1
  2. data/README.rdoc +33 -0
  3. data/lib/active_support.rb +42 -4
  4. data/lib/active_support/backtrace_cleaner.rb +31 -9
  5. data/lib/active_support/benchmarkable.rb +1 -0
  6. data/lib/active_support/buffered_logger.rb +5 -2
  7. data/lib/active_support/builder.rb +6 -0
  8. data/lib/active_support/cache.rb +454 -84
  9. data/lib/active_support/cache/compressed_mem_cache_store.rb +6 -13
  10. data/lib/active_support/cache/file_store.rb +140 -41
  11. data/lib/active_support/cache/mem_cache_store.rb +121 -76
  12. data/lib/active_support/cache/memory_store.rb +127 -27
  13. data/lib/active_support/cache/strategy/local_cache.rb +111 -58
  14. data/lib/active_support/cache/synchronized_memory_store.rb +2 -38
  15. data/lib/active_support/callbacks.rb +105 -76
  16. data/lib/active_support/configurable.rb +19 -18
  17. data/lib/active_support/core_ext/array.rb +1 -0
  18. data/lib/active_support/core_ext/array/access.rb +1 -1
  19. data/lib/active_support/core_ext/array/conversions.rb +29 -54
  20. data/lib/active_support/core_ext/array/extract_options.rb +16 -1
  21. data/lib/active_support/core_ext/array/grouping.rb +1 -1
  22. data/lib/active_support/core_ext/array/random_access.rb +26 -5
  23. data/lib/active_support/core_ext/array/uniq_by.rb +17 -0
  24. data/lib/active_support/core_ext/array/wrap.rb +13 -9
  25. data/lib/active_support/core_ext/benchmark.rb +0 -12
  26. data/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +2 -0
  27. data/lib/active_support/core_ext/class.rb +2 -1
  28. data/lib/active_support/core_ext/class/attribute.rb +67 -0
  29. data/lib/active_support/core_ext/class/attribute_accessors.rb +33 -27
  30. data/lib/active_support/core_ext/class/delegating_attributes.rb +35 -41
  31. data/lib/active_support/core_ext/class/inheritable_attributes.rb +23 -14
  32. data/lib/active_support/core_ext/class/subclasses.rb +50 -0
  33. data/lib/active_support/core_ext/date/calculations.rb +35 -12
  34. data/lib/active_support/core_ext/date/conversions.rb +5 -5
  35. data/lib/active_support/core_ext/date/zones.rb +14 -0
  36. data/lib/active_support/core_ext/date_time/calculations.rb +3 -1
  37. data/lib/active_support/core_ext/date_time/conversions.rb +24 -5
  38. data/lib/active_support/core_ext/date_time/zones.rb +4 -0
  39. data/lib/active_support/core_ext/enumerable.rb +5 -9
  40. data/lib/active_support/core_ext/exception.rb +0 -47
  41. data/lib/active_support/core_ext/file.rb +1 -0
  42. data/lib/active_support/core_ext/file/atomic.rb +3 -2
  43. data/lib/active_support/core_ext/file/path.rb +5 -0
  44. data/lib/active_support/core_ext/float/rounding.rb +3 -2
  45. data/lib/active_support/core_ext/hash/conversions.rb +65 -145
  46. data/lib/active_support/core_ext/hash/deep_merge.rb +6 -7
  47. data/lib/active_support/core_ext/hash/except.rb +8 -1
  48. data/lib/active_support/core_ext/hash/indifferent_access.rb +5 -0
  49. data/lib/active_support/core_ext/hash/keys.rb +10 -11
  50. data/lib/active_support/core_ext/hash/slice.rb +6 -0
  51. data/lib/active_support/core_ext/integer.rb +1 -1
  52. data/lib/active_support/core_ext/integer/multiple.rb +6 -0
  53. data/lib/active_support/core_ext/kernel.rb +1 -1
  54. data/lib/active_support/core_ext/kernel/debugger.rb +3 -2
  55. data/lib/active_support/core_ext/kernel/reporting.rb +2 -1
  56. data/lib/active_support/core_ext/kernel/requires.rb +2 -2
  57. data/lib/active_support/core_ext/kernel/singleton_class.rb +13 -0
  58. data/lib/active_support/core_ext/load_error.rb +17 -30
  59. data/lib/active_support/core_ext/logger.rb +2 -40
  60. data/lib/active_support/core_ext/module.rb +5 -3
  61. data/lib/active_support/core_ext/module/aliasing.rb +1 -1
  62. data/lib/active_support/core_ext/module/anonymous.rb +24 -0
  63. data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +1 -1
  64. data/lib/active_support/core_ext/module/attr_internal.rb +2 -2
  65. data/lib/active_support/core_ext/module/attribute_accessors.rb +20 -22
  66. data/lib/active_support/core_ext/module/delegation.rb +21 -10
  67. data/lib/active_support/core_ext/module/introspection.rb +8 -8
  68. data/lib/active_support/core_ext/module/method_names.rb +14 -0
  69. data/lib/active_support/core_ext/module/reachable.rb +10 -0
  70. data/lib/active_support/core_ext/module/remove_method.rb +11 -0
  71. data/lib/active_support/core_ext/module/synchronization.rb +2 -1
  72. data/lib/active_support/core_ext/name_error.rb +3 -1
  73. data/lib/active_support/core_ext/object.rb +5 -3
  74. data/lib/active_support/core_ext/object/blank.rb +20 -2
  75. data/lib/active_support/core_ext/object/conversions.rb +2 -16
  76. data/lib/active_support/core_ext/object/duplicable.rb +23 -1
  77. data/lib/active_support/core_ext/object/instance_variables.rb +0 -7
  78. data/lib/active_support/core_ext/object/to_json.rb +19 -0
  79. data/lib/active_support/core_ext/object/to_param.rb +49 -0
  80. data/lib/active_support/core_ext/object/to_query.rb +27 -0
  81. data/lib/active_support/core_ext/object/with_options.rb +2 -0
  82. data/lib/active_support/core_ext/proc.rb +4 -4
  83. data/lib/active_support/core_ext/range/overlaps.rb +1 -1
  84. data/lib/active_support/core_ext/regexp.rb +0 -22
  85. data/lib/active_support/core_ext/rexml.rb +4 -1
  86. data/lib/active_support/core_ext/string.rb +3 -2
  87. data/lib/active_support/core_ext/string/access.rb +4 -2
  88. data/lib/active_support/core_ext/string/conversions.rb +28 -1
  89. data/lib/active_support/core_ext/string/encoding.rb +11 -0
  90. data/lib/active_support/core_ext/string/exclude.rb +6 -0
  91. data/lib/active_support/core_ext/string/filters.rb +29 -0
  92. data/lib/active_support/core_ext/string/inflections.rb +12 -12
  93. data/lib/active_support/core_ext/string/interpolation.rb +2 -92
  94. data/lib/active_support/core_ext/string/multibyte.rb +16 -19
  95. data/lib/active_support/core_ext/string/output_safety.rb +101 -35
  96. data/lib/active_support/core_ext/string/starts_ends_with.rb +0 -14
  97. data/lib/active_support/core_ext/string/xchar.rb +1 -1
  98. data/lib/active_support/core_ext/time/calculations.rb +14 -7
  99. data/lib/active_support/core_ext/time/conversions.rb +1 -0
  100. data/lib/active_support/core_ext/time/marshal.rb +56 -0
  101. data/lib/active_support/core_ext/time/zones.rb +2 -5
  102. data/lib/active_support/core_ext/uri.rb +10 -4
  103. data/lib/active_support/dependencies.rb +200 -197
  104. data/lib/active_support/dependencies/autoload.rb +50 -0
  105. data/lib/active_support/deprecation/behaviors.rb +13 -9
  106. data/lib/active_support/deprecation/method_wrappers.rb +10 -9
  107. data/lib/active_support/deprecation/proxy_wrappers.rb +7 -0
  108. data/lib/active_support/deprecation/reporting.rb +5 -3
  109. data/lib/active_support/descendants_tracker.rb +43 -0
  110. data/lib/active_support/duration.rb +8 -4
  111. data/lib/active_support/file_update_checker.rb +36 -0
  112. data/lib/active_support/hash_with_indifferent_access.rb +9 -1
  113. data/lib/active_support/i18n.rb +9 -0
  114. data/lib/active_support/i18n_railtie.rb +81 -0
  115. data/lib/active_support/inflections.rb +1 -1
  116. data/lib/active_support/inflector.rb +4 -407
  117. data/lib/active_support/inflector/inflections.rb +211 -0
  118. data/lib/active_support/inflector/methods.rb +151 -0
  119. data/lib/active_support/inflector/transliterate.rb +97 -0
  120. data/lib/active_support/json/backends/jsongem.rb +12 -9
  121. data/lib/active_support/json/backends/yajl.rb +40 -0
  122. data/lib/active_support/json/backends/yaml.rb +1 -1
  123. data/lib/active_support/json/decoding.rb +17 -2
  124. data/lib/active_support/json/encoding.rb +48 -31
  125. data/lib/active_support/json/variable.rb +2 -4
  126. data/lib/active_support/lazy_load_hooks.rb +27 -0
  127. data/lib/active_support/locale/en.yml +5 -2
  128. data/lib/active_support/log_subscriber.rb +123 -0
  129. data/lib/active_support/log_subscriber/test_helper.rb +99 -0
  130. data/lib/active_support/memoizable.rb +1 -1
  131. data/lib/active_support/message_encryptor.rb +1 -0
  132. data/lib/active_support/message_verifier.rb +2 -1
  133. data/lib/active_support/multibyte.rb +8 -23
  134. data/lib/active_support/multibyte/chars.rb +213 -446
  135. data/lib/active_support/multibyte/unicode.rb +392 -0
  136. data/lib/active_support/multibyte/utils.rb +6 -7
  137. data/lib/active_support/notifications.rb +29 -122
  138. data/lib/active_support/notifications/fanout.rb +61 -0
  139. data/lib/active_support/notifications/instrumenter.rb +54 -0
  140. data/lib/active_support/ordered_hash.rb +59 -14
  141. data/lib/active_support/ordered_options.rb +6 -0
  142. data/lib/active_support/railtie.rb +60 -0
  143. data/lib/active_support/rescuable.rb +7 -4
  144. data/lib/active_support/ruby/shim.rb +4 -6
  145. data/lib/active_support/test_case.rb +2 -7
  146. data/lib/active_support/testing/assertions.rb +15 -0
  147. data/lib/active_support/testing/declarative.rb +1 -1
  148. data/lib/active_support/testing/isolation.rb +64 -17
  149. data/lib/active_support/testing/performance.rb +306 -335
  150. data/lib/active_support/testing/setup_and_teardown.rb +51 -29
  151. data/lib/active_support/time.rb +24 -3
  152. data/lib/active_support/time_with_zone.rb +10 -14
  153. data/lib/active_support/values/time_zone.rb +192 -234
  154. data/lib/active_support/values/unicode_tables.dat +0 -0
  155. data/lib/active_support/version.rb +3 -2
  156. data/lib/active_support/whiny_nil.rb +9 -7
  157. data/lib/active_support/xml_mini.rb +130 -1
  158. data/lib/active_support/xml_mini/jdom.rb +2 -0
  159. data/lib/active_support/xml_mini/libxml.rb +23 -86
  160. data/lib/active_support/xml_mini/libxmlsax.rb +85 -0
  161. data/lib/active_support/xml_mini/nokogiri.rb +27 -24
  162. data/lib/active_support/xml_mini/nokogirisax.rb +83 -0
  163. data/lib/active_support/xml_mini/rexml.rb +8 -2
  164. metadata +62 -195
  165. data/README +0 -43
  166. data/lib/active_support/autoload.rb +0 -28
  167. data/lib/active_support/core_ext/boolean.rb +0 -1
  168. data/lib/active_support/core_ext/boolean/conversions.rb +0 -11
  169. data/lib/active_support/core_ext/class/removal.rb +0 -53
  170. data/lib/active_support/core_ext/date.rb +0 -7
  171. data/lib/active_support/core_ext/date_time.rb +0 -5
  172. data/lib/active_support/core_ext/integer/even_odd.rb +0 -16
  173. data/lib/active_support/core_ext/kernel/daemonizing.rb +0 -7
  174. data/lib/active_support/core_ext/module/inclusion.rb +0 -30
  175. data/lib/active_support/core_ext/module/loading.rb +0 -23
  176. data/lib/active_support/core_ext/nil.rb +0 -1
  177. data/lib/active_support/core_ext/nil/conversions.rb +0 -5
  178. data/lib/active_support/core_ext/object/extending.rb +0 -80
  179. data/lib/active_support/core_ext/object/metaclass.rb +0 -13
  180. data/lib/active_support/core_ext/object/misc.rb +0 -3
  181. data/lib/active_support/core_ext/object/returning.rb +0 -42
  182. data/lib/active_support/core_ext/object/tap.rb +0 -16
  183. data/lib/active_support/core_ext/string/bytesize.rb +0 -5
  184. data/lib/active_support/core_ext/string/iterators.rb +0 -13
  185. data/lib/active_support/core_ext/symbol.rb +0 -1
  186. data/lib/active_support/core_ext/symbol/to_proc.rb +0 -14
  187. data/lib/active_support/core_ext/time.rb +0 -10
  188. data/lib/active_support/core_ext/time/marshal_with_utc_flag.rb +0 -22
  189. data/lib/active_support/deprecated_callbacks.rb +0 -283
  190. data/lib/active_support/multibyte/unicode_database.rb +0 -71
  191. data/lib/active_support/vendor.rb +0 -16
  192. data/lib/active_support/vendor/builder-2.1.2/lib/blankslate.rb +0 -113
  193. data/lib/active_support/vendor/builder-2.1.2/lib/builder.rb +0 -13
  194. data/lib/active_support/vendor/builder-2.1.2/lib/builder/blankslate.rb +0 -20
  195. data/lib/active_support/vendor/builder-2.1.2/lib/builder/css.rb +0 -250
  196. data/lib/active_support/vendor/builder-2.1.2/lib/builder/xchar.rb +0 -115
  197. data/lib/active_support/vendor/builder-2.1.2/lib/builder/xmlbase.rb +0 -139
  198. data/lib/active_support/vendor/builder-2.1.2/lib/builder/xmlevents.rb +0 -63
  199. data/lib/active_support/vendor/builder-2.1.2/lib/builder/xmlmarkup.rb +0 -328
  200. data/lib/active_support/vendor/i18n-0.1.3/MIT-LICENSE +0 -20
  201. data/lib/active_support/vendor/i18n-0.1.3/README.textile +0 -20
  202. data/lib/active_support/vendor/i18n-0.1.3/Rakefile +0 -5
  203. data/lib/active_support/vendor/i18n-0.1.3/i18n.gemspec +0 -27
  204. data/lib/active_support/vendor/i18n-0.1.3/lib/i18n.rb +0 -204
  205. data/lib/active_support/vendor/i18n-0.1.3/lib/i18n/backend/simple.rb +0 -215
  206. data/lib/active_support/vendor/i18n-0.1.3/lib/i18n/exceptions.rb +0 -53
  207. data/lib/active_support/vendor/i18n-0.1.3/test/all.rb +0 -5
  208. data/lib/active_support/vendor/i18n-0.1.3/test/i18n_exceptions_test.rb +0 -99
  209. data/lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb +0 -124
  210. data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.rb +0 -1
  211. data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.yml +0 -3
  212. data/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb +0 -567
  213. data/lib/active_support/vendor/memcache-client-1.7.5/lib/memcache.rb +0 -1133
  214. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo.rb +0 -33
  215. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/data_timezone.rb +0 -47
  216. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/data_timezone_info.rb +0 -228
  217. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Algiers.rb +0 -55
  218. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Cairo.rb +0 -219
  219. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Casablanca.rb +0 -42
  220. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Harare.rb +0 -18
  221. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Johannesburg.rb +0 -25
  222. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Monrovia.rb +0 -22
  223. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Africa/Nairobi.rb +0 -23
  224. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Argentina/Buenos_Aires.rb +0 -166
  225. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Argentina/San_Juan.rb +0 -86
  226. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Bogota.rb +0 -23
  227. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Caracas.rb +0 -23
  228. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Chicago.rb +0 -283
  229. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Chihuahua.rb +0 -136
  230. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Denver.rb +0 -204
  231. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Godthab.rb +0 -161
  232. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Guatemala.rb +0 -27
  233. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Halifax.rb +0 -274
  234. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Indiana/Indianapolis.rb +0 -149
  235. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Juneau.rb +0 -194
  236. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/La_Paz.rb +0 -22
  237. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Lima.rb +0 -35
  238. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Los_Angeles.rb +0 -232
  239. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Mazatlan.rb +0 -139
  240. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Mexico_City.rb +0 -144
  241. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Monterrey.rb +0 -131
  242. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/New_York.rb +0 -282
  243. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Phoenix.rb +0 -30
  244. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Regina.rb +0 -74
  245. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Santiago.rb +0 -205
  246. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Sao_Paulo.rb +0 -171
  247. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/St_Johns.rb +0 -288
  248. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/America/Tijuana.rb +0 -196
  249. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Almaty.rb +0 -67
  250. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Baghdad.rb +0 -73
  251. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Baku.rb +0 -161
  252. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Bangkok.rb +0 -20
  253. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Chongqing.rb +0 -33
  254. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Colombo.rb +0 -30
  255. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Dhaka.rb +0 -27
  256. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Hong_Kong.rb +0 -87
  257. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Irkutsk.rb +0 -165
  258. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Jakarta.rb +0 -30
  259. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Jerusalem.rb +0 -163
  260. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kabul.rb +0 -20
  261. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kamchatka.rb +0 -163
  262. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Karachi.rb +0 -32
  263. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kathmandu.rb +0 -20
  264. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kolkata.rb +0 -25
  265. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Krasnoyarsk.rb +0 -163
  266. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kuala_Lumpur.rb +0 -31
  267. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Kuwait.rb +0 -18
  268. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Magadan.rb +0 -163
  269. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Muscat.rb +0 -18
  270. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Novosibirsk.rb +0 -164
  271. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Rangoon.rb +0 -24
  272. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Riyadh.rb +0 -18
  273. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Seoul.rb +0 -34
  274. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Shanghai.rb +0 -35
  275. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Singapore.rb +0 -33
  276. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Taipei.rb +0 -59
  277. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Tashkent.rb +0 -47
  278. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Tbilisi.rb +0 -78
  279. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Tehran.rb +0 -121
  280. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Tokyo.rb +0 -30
  281. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Ulaanbaatar.rb +0 -65
  282. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Urumqi.rb +0 -33
  283. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Vladivostok.rb +0 -164
  284. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Yakutsk.rb +0 -163
  285. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Yekaterinburg.rb +0 -165
  286. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Asia/Yerevan.rb +0 -165
  287. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Atlantic/Azores.rb +0 -270
  288. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Atlantic/Cape_Verde.rb +0 -23
  289. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Atlantic/South_Georgia.rb +0 -18
  290. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Adelaide.rb +0 -187
  291. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Brisbane.rb +0 -35
  292. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Darwin.rb +0 -29
  293. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Hobart.rb +0 -193
  294. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Melbourne.rb +0 -185
  295. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Perth.rb +0 -37
  296. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Australia/Sydney.rb +0 -185
  297. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Etc/UTC.rb +0 -16
  298. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Amsterdam.rb +0 -228
  299. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Athens.rb +0 -185
  300. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Belgrade.rb +0 -163
  301. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Berlin.rb +0 -188
  302. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Bratislava.rb +0 -13
  303. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Brussels.rb +0 -232
  304. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Bucharest.rb +0 -181
  305. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Budapest.rb +0 -197
  306. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Copenhagen.rb +0 -179
  307. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Dublin.rb +0 -276
  308. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Helsinki.rb +0 -163
  309. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Istanbul.rb +0 -218
  310. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Kiev.rb +0 -168
  311. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Lisbon.rb +0 -268
  312. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Ljubljana.rb +0 -13
  313. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/London.rb +0 -288
  314. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Madrid.rb +0 -211
  315. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Minsk.rb +0 -170
  316. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Moscow.rb +0 -181
  317. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Paris.rb +0 -232
  318. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Prague.rb +0 -187
  319. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Riga.rb +0 -176
  320. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Rome.rb +0 -215
  321. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Sarajevo.rb +0 -13
  322. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Skopje.rb +0 -13
  323. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Sofia.rb +0 -173
  324. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Stockholm.rb +0 -165
  325. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Tallinn.rb +0 -172
  326. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Vienna.rb +0 -183
  327. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Vilnius.rb +0 -170
  328. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Warsaw.rb +0 -212
  329. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Europe/Zagreb.rb +0 -13
  330. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Auckland.rb +0 -202
  331. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Fiji.rb +0 -23
  332. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Guam.rb +0 -22
  333. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Honolulu.rb +0 -28
  334. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Majuro.rb +0 -20
  335. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Midway.rb +0 -25
  336. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Noumea.rb +0 -25
  337. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Pago_Pago.rb +0 -26
  338. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Port_Moresby.rb +0 -20
  339. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/definitions/Pacific/Tongatapu.rb +0 -27
  340. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/info_timezone.rb +0 -52
  341. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/linked_timezone.rb +0 -51
  342. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/linked_timezone_info.rb +0 -44
  343. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/offset_rationals.rb +0 -98
  344. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/ruby_core_support.rb +0 -56
  345. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/time_or_datetime.rb +0 -292
  346. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone.rb +0 -508
  347. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone_definition.rb +0 -56
  348. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone_info.rb +0 -40
  349. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone_offset_info.rb +0 -94
  350. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone_period.rb +0 -198
  351. data/lib/active_support/vendor/tzinfo-0.3.13/lib/tzinfo/timezone_transition_info.rb +0 -129
@@ -0,0 +1,50 @@
1
+ require "active_support/inflector/methods"
2
+ require "active_support/lazy_load_hooks"
3
+
4
+ module ActiveSupport
5
+ module Autoload
6
+ @@autoloads = {}
7
+ @@under_path = nil
8
+ @@at_path = nil
9
+ @@eager_autoload = false
10
+
11
+ def autoload(const_name, path = @@at_path)
12
+ full = [self.name, @@under_path, const_name.to_s, path].compact.join("::")
13
+ location = path || Inflector.underscore(full)
14
+
15
+ if @@eager_autoload
16
+ @@autoloads[const_name] = location
17
+ end
18
+ super const_name, location
19
+ end
20
+
21
+ def autoload_under(path)
22
+ @@under_path, old_path = path, @@under_path
23
+ yield
24
+ ensure
25
+ @@under_path = old_path
26
+ end
27
+
28
+ def autoload_at(path)
29
+ @@at_path, old_path = path, @@at_path
30
+ yield
31
+ ensure
32
+ @@at_path = old_path
33
+ end
34
+
35
+ def eager_autoload
36
+ old_eager, @@eager_autoload = @@eager_autoload, true
37
+ yield
38
+ ensure
39
+ @@eager_autoload = old_eager
40
+ end
41
+
42
+ def self.eager_autoload!
43
+ @@autoloads.values.each { |file| require file }
44
+ end
45
+
46
+ def autoloads
47
+ @@autoloads
48
+ end
49
+ end
50
+ end
@@ -1,28 +1,28 @@
1
+ require "active_support/notifications"
2
+ require "active_support/core_ext/array/wrap"
3
+
1
4
  module ActiveSupport
2
5
  module Deprecation
3
6
  class << self
4
- # Behavior is a block that takes a message argument.
5
- attr_writer :behavior
6
-
7
7
  # Whether to print a backtrace along with the warning.
8
8
  attr_accessor :debug
9
9
 
10
10
  def behavior
11
- @behavior ||= default_behavior
11
+ @behavior ||= [DEFAULT_BEHAVIORS[:stderr]]
12
12
  end
13
13
 
14
- def default_behavior
15
- Deprecation::DEFAULT_BEHAVIORS[defined?(Rails) ? Rails.env.to_s : 'test']
14
+ def behavior=(behavior)
15
+ @behavior = Array.wrap(behavior).map { |b| DEFAULT_BEHAVIORS[b] || b }
16
16
  end
17
17
  end
18
18
 
19
- # Default warning behaviors per Rails.env. Ignored in production.
19
+ # Default warning behaviors per Rails.env.
20
20
  DEFAULT_BEHAVIORS = {
21
- 'test' => Proc.new { |message, callstack|
21
+ :stderr => Proc.new { |message, callstack|
22
22
  $stderr.puts(message)
23
23
  $stderr.puts callstack.join("\n ") if debug
24
24
  },
25
- 'development' => Proc.new { |message, callstack|
25
+ :log => Proc.new { |message, callstack|
26
26
  logger =
27
27
  if defined?(Rails) && Rails.logger
28
28
  Rails.logger
@@ -32,6 +32,10 @@ module ActiveSupport
32
32
  end
33
33
  logger.warn message
34
34
  logger.debug callstack.join("\n ") if debug
35
+ },
36
+ :notify => Proc.new { |message, callstack|
37
+ ActiveSupport::Notifications.instrument("deprecation.rails",
38
+ :message => message, :callstack => callstack)
35
39
  }
36
40
  }
37
41
  end
@@ -1,5 +1,6 @@
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'
3
4
 
4
5
  module ActiveSupport
5
6
  class << Deprecation
@@ -11,15 +12,15 @@ module ActiveSupport
11
12
  method_names.each do |method_name|
12
13
  target_module.alias_method_chain(method_name, :deprecation) do |target, punctuation|
13
14
  target_module.module_eval(<<-end_eval, __FILE__, __LINE__ + 1)
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
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
23
24
  end_eval
24
25
  end
25
26
  end
@@ -3,6 +3,13 @@ require 'active_support/inflector'
3
3
  module ActiveSupport
4
4
  module Deprecation
5
5
  class DeprecationProxy #:nodoc:
6
+ def self.new(*args, &block)
7
+ object = args.first
8
+
9
+ return object unless object
10
+ super
11
+ end
12
+
6
13
  instance_methods.each { |m| undef_method m unless m =~ /^__|^object_id$/ }
7
14
 
8
15
  # Don't give a deprecation warning on inspect since test/unit and error
@@ -4,8 +4,9 @@ module ActiveSupport
4
4
  attr_accessor :silenced
5
5
 
6
6
  def warn(message = nil, callstack = caller)
7
- if behavior && !silenced
8
- behavior.call(deprecation_message(callstack, message), callstack)
7
+ return if silenced
8
+ deprecation_message(callstack, message).tap do |m|
9
+ behavior.each { |b| b.call(m, callstack) }
9
10
  end
10
11
  end
11
12
 
@@ -29,7 +30,8 @@ module ActiveSupport
29
30
  private
30
31
  def deprecation_message(callstack, message = nil)
31
32
  message ||= "You are using deprecated behavior which will be removed from the next major or minor release."
32
- "DEPRECATION WARNING: #{message}. #{deprecation_caller_message(callstack)}"
33
+ message += '.' unless message =~ /\.$/
34
+ "DEPRECATION WARNING: #{message} #{deprecation_caller_message(callstack)}"
33
35
  end
34
36
 
35
37
  def deprecation_caller_message(callstack)
@@ -0,0 +1,43 @@
1
+ require 'active_support/dependencies'
2
+
3
+ module ActiveSupport
4
+ # This module provides an internal implementation to track descendants
5
+ # which is faster than iterating through ObjectSpace.
6
+ module DescendantsTracker
7
+ @@direct_descendants = Hash.new { |h, k| h[k] = [] }
8
+
9
+ def self.direct_descendants(klass)
10
+ @@direct_descendants[klass]
11
+ end
12
+
13
+ def self.descendants(klass)
14
+ @@direct_descendants[klass].inject([]) do |descendants, _klass|
15
+ descendants << _klass
16
+ descendants.concat _klass.descendants
17
+ end
18
+ end
19
+
20
+ def self.clear
21
+ @@direct_descendants.each do |klass, descendants|
22
+ if ActiveSupport::Dependencies.autoloaded?(klass)
23
+ @@direct_descendants.delete(klass)
24
+ else
25
+ descendants.reject! { |v| ActiveSupport::Dependencies.autoloaded?(v) }
26
+ end
27
+ end
28
+ end
29
+
30
+ def inherited(base)
31
+ self.direct_descendants << base
32
+ super
33
+ end
34
+
35
+ def direct_descendants
36
+ DescendantsTracker.direct_descendants(self)
37
+ end
38
+
39
+ def descendants
40
+ DescendantsTracker.descendants(self)
41
+ end
42
+ end
43
+ end
@@ -1,10 +1,11 @@
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'
3
4
 
4
5
  module ActiveSupport
5
6
  # Provides accurate date and time measurements using Date#advance and
6
- # Time#advance, respectively. It mainly supports the methods on Numeric,
7
- # such as in this example:
7
+ # Time#advance, respectively. It mainly supports the methods on Numeric.
8
+ # Example:
8
9
  #
9
10
  # 1.month.ago # equivalent to Time.now.advance(:months => -1)
10
11
  class Duration < BasicObject
@@ -35,8 +36,9 @@ module ActiveSupport
35
36
  end
36
37
 
37
38
  def is_a?(klass) #:nodoc:
38
- klass == Duration || super
39
+ Duration == klass || value.is_a?(klass)
39
40
  end
41
+ alias :kind_of? :is_a?
40
42
 
41
43
  # Returns true if <tt>other</tt> is also a Duration instance with the
42
44
  # same <tt>value</tt>, or if <tt>other == value</tt>.
@@ -49,7 +51,9 @@ module ActiveSupport
49
51
  end
50
52
 
51
53
  def self.===(other) #:nodoc:
52
- other.is_a?(Duration) rescue super
54
+ other.is_a?(Duration)
55
+ rescue ::NoMethodError
56
+ false
53
57
  end
54
58
 
55
59
  # Calculates a new Time or Date that is as far in the future
@@ -0,0 +1,36 @@
1
+ module ActiveSupport
2
+ # This class is responsible to track files and invoke the given block
3
+ # whenever one of these files are changed. For example, this class
4
+ # is used by Rails to reload the I18n framework whenever they are
5
+ # changed upon a new request.
6
+ #
7
+ # i18n_reloader = ActiveSupport::FileUpdateChecker.new(paths) do
8
+ # I18n.reload!
9
+ # end
10
+ #
11
+ # ActionDispatch::Callbacks.to_prepare do
12
+ # i18n_reloader.execute_if_updated
13
+ # end
14
+ #
15
+ class FileUpdateChecker
16
+ attr_reader :paths, :last_update_at
17
+
18
+ def initialize(paths, calculate=false, &block)
19
+ @paths = paths
20
+ @block = block
21
+ @last_update_at = calculate ? updated_at : nil
22
+ end
23
+
24
+ def updated_at
25
+ paths.map { |path| File.stat(path).mtime }.max
26
+ end
27
+
28
+ def execute_if_updated
29
+ current_update_at = self.updated_at
30
+ if @last_update_at != current_update_at
31
+ @last_update_at = current_update_at
32
+ @block.call
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,9 +1,15 @@
1
+ require 'active_support/core_ext/hash/keys'
2
+
1
3
  # This class has dubious semantics and we only have it so that
2
4
  # people can write params[:key] instead of params['key']
3
5
  # and they get the same value for both keys.
4
6
 
5
7
  module ActiveSupport
6
8
  class HashWithIndifferentAccess < Hash
9
+ def extractable_options?
10
+ true
11
+ end
12
+
7
13
  def initialize(constructor = {})
8
14
  if constructor.is_a?(Hash)
9
15
  super()
@@ -108,7 +114,9 @@ module ActiveSupport
108
114
  end
109
115
 
110
116
  def stringify_keys!; self end
111
- def symbolize_keys!; self end
117
+ def stringify_keys; dup end
118
+ undef :symbolize_keys!
119
+ def symbolize_keys; to_hash.symbolize_keys end
112
120
  def to_options!; self end
113
121
 
114
122
  # Convert to a Hash with String keys.
@@ -0,0 +1,9 @@
1
+ begin
2
+ require 'i18n'
3
+ rescue LoadError => e
4
+ $stderr.puts "You don't have i18n installed in your application. Please add it to your Gemfile and run bundle install"
5
+ raise e
6
+ end
7
+
8
+ I18n.load_path << "#{File.dirname(__FILE__)}/locale/en.yml"
9
+ ActiveSupport.run_load_hooks(:i18n)
@@ -0,0 +1,81 @@
1
+ require "active_support"
2
+ require "rails"
3
+ require "active_support/file_update_checker"
4
+ require "active_support/core_ext/array/wrap"
5
+
6
+ module I18n
7
+ class Railtie < Rails::Railtie
8
+ config.i18n = ActiveSupport::OrderedOptions.new
9
+ config.i18n.railties_load_path = []
10
+ config.i18n.load_path = []
11
+ config.i18n.fallbacks = ActiveSupport::OrderedOptions.new
12
+
13
+ def self.reloader
14
+ @reloader ||= ActiveSupport::FileUpdateChecker.new([]){ I18n.reload! }
15
+ end
16
+
17
+ # Add I18n::Railtie.reloader to ActionDispatch callbacks. Since, at this
18
+ # point, no path was added to the reloader, I18n.reload! is not triggered
19
+ # on to_prepare callbacks. This will only happen on the config.after_initialize
20
+ # callback below.
21
+ initializer "i18n.callbacks" do
22
+ ActionDispatch::Callbacks.to_prepare do
23
+ I18n::Railtie.reloader.execute_if_updated
24
+ end
25
+ end
26
+
27
+ # Set the i18n configuration only after initialization since a lot of
28
+ # configuration is still usually done in application initializers.
29
+ config.after_initialize do |app|
30
+ fallbacks = app.config.i18n.delete(:fallbacks)
31
+
32
+ app.config.i18n.each do |setting, value|
33
+ case setting
34
+ when :railties_load_path
35
+ app.config.i18n.load_path.unshift(*value)
36
+ when :load_path
37
+ I18n.load_path += value
38
+ else
39
+ I18n.send("#{setting}=", value)
40
+ end
41
+ end
42
+
43
+ init_fallbacks(fallbacks) if fallbacks && validate_fallbacks(fallbacks)
44
+
45
+ reloader.paths.concat I18n.load_path
46
+ reloader.execute_if_updated
47
+ end
48
+
49
+ protected
50
+
51
+ def self.include_fallbacks_module
52
+ I18n.backend.class.send(:include, I18n::Backend::Fallbacks)
53
+ end
54
+
55
+ def self.init_fallbacks(fallbacks)
56
+ include_fallbacks_module
57
+
58
+ args = case fallbacks
59
+ when ActiveSupport::OrderedOptions
60
+ [*(fallbacks[:defaults] || []) << fallbacks[:map]].compact
61
+ when Hash, Array
62
+ Array.wrap(fallbacks)
63
+ else # TrueClass
64
+ []
65
+ end
66
+
67
+ I18n.fallbacks = I18n::Locale::Fallbacks.new(*args)
68
+ end
69
+
70
+ def self.validate_fallbacks(fallbacks)
71
+ case fallbacks
72
+ when ActiveSupport::OrderedOptions
73
+ !fallbacks.empty?
74
+ when TrueClass, Array, Hash
75
+ true
76
+ else
77
+ raise "Unexpected fallback type #{fallbacks.inspect}"
78
+ end
79
+ end
80
+ end
81
+ end
@@ -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))
54
+ inflect.uncountable(%w(equipment information rice money species series fish sheep jeans))
55
55
  end
56
56
  end
@@ -1,410 +1,7 @@
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
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
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'
5
+
409
6
  require 'active_support/inflections'
410
7
  require 'active_support/core_ext/string/inflections'