activesupport 2.3.5 → 3.0.0.beta3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (391) hide show
  1. data/CHANGELOG +66 -9
  2. data/lib/active_support/all.rb +2 -7
  3. data/lib/active_support/backtrace_cleaner.rb +31 -9
  4. data/lib/active_support/base64.rb +9 -0
  5. data/lib/active_support/basic_object.rb +7 -10
  6. data/lib/active_support/benchmarkable.rb +60 -0
  7. data/lib/active_support/buffered_logger.rb +14 -9
  8. data/lib/active_support/cache/compressed_mem_cache_store.rb +2 -0
  9. data/lib/active_support/cache/file_store.rb +35 -17
  10. data/lib/active_support/cache/mem_cache_store.rb +32 -23
  11. data/lib/active_support/cache/memory_store.rb +17 -10
  12. data/lib/active_support/cache/strategy/local_cache.rb +9 -1
  13. data/lib/active_support/cache.rb +75 -55
  14. data/lib/active_support/callbacks.rb +490 -169
  15. data/lib/active_support/concern.rb +29 -0
  16. data/lib/active_support/configurable.rb +35 -0
  17. data/lib/active_support/core_ext/array/access.rb +39 -46
  18. data/lib/active_support/core_ext/array/conversions.rb +145 -182
  19. data/lib/active_support/core_ext/array/extract_options.rb +26 -17
  20. data/lib/active_support/core_ext/array/grouping.rb +87 -93
  21. data/lib/active_support/core_ext/array/random_access.rb +4 -10
  22. data/lib/active_support/core_ext/array/uniq_by.rb +17 -0
  23. data/lib/active_support/core_ext/array/wrap.rb +22 -0
  24. data/lib/active_support/core_ext/array.rb +2 -10
  25. data/lib/active_support/core_ext/big_decimal/conversions.rb +27 -0
  26. data/lib/active_support/core_ext/big_decimal.rb +1 -0
  27. data/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +16 -20
  28. data/lib/active_support/core_ext/cgi.rb +0 -4
  29. data/lib/active_support/core_ext/class/attribute.rb +70 -0
  30. data/lib/active_support/core_ext/class/attribute_accessors.rb +40 -31
  31. data/lib/active_support/core_ext/class/delegating_attributes.rb +37 -40
  32. data/lib/active_support/core_ext/class/inheritable_attributes.rb +100 -11
  33. data/lib/active_support/core_ext/class/subclasses.rb +55 -0
  34. data/lib/active_support/core_ext/class.rb +1 -1
  35. data/lib/active_support/core_ext/date/acts_like.rb +8 -0
  36. data/lib/active_support/core_ext/date/calculations.rb +218 -228
  37. data/lib/active_support/core_ext/date/conversions.rb +87 -96
  38. data/lib/active_support/core_ext/date/freeze.rb +31 -0
  39. data/lib/active_support/core_ext/date_time/acts_like.rb +13 -0
  40. data/lib/active_support/core_ext/date_time/calculations.rb +97 -110
  41. data/lib/active_support/core_ext/date_time/conversions.rb +85 -85
  42. data/lib/active_support/core_ext/date_time/zones.rb +17 -0
  43. data/lib/active_support/core_ext/enumerable.rb +18 -13
  44. data/lib/active_support/core_ext/exception.rb +1 -43
  45. data/lib/active_support/core_ext/file/atomic.rb +35 -40
  46. data/lib/active_support/core_ext/file/path.rb +5 -0
  47. data/lib/active_support/core_ext/file.rb +0 -4
  48. data/lib/active_support/core_ext/float/rounding.rb +15 -20
  49. data/lib/active_support/core_ext/float.rb +0 -6
  50. data/lib/active_support/core_ext/hash/conversions.rb +255 -229
  51. data/lib/active_support/core_ext/hash/deep_merge.rb +12 -19
  52. data/lib/active_support/core_ext/hash/diff.rb +11 -17
  53. data/lib/active_support/core_ext/hash/except.rb +21 -22
  54. data/lib/active_support/core_ext/hash/indifferent_access.rb +8 -137
  55. data/lib/active_support/core_ext/hash/keys.rb +38 -45
  56. data/lib/active_support/core_ext/hash/reverse_merge.rb +25 -32
  57. data/lib/active_support/core_ext/hash/slice.rb +35 -37
  58. data/lib/active_support/core_ext/hash.rb +8 -14
  59. data/lib/active_support/core_ext/integer/inflections.rb +10 -16
  60. data/lib/active_support/core_ext/integer/multiple.rb +6 -0
  61. data/lib/active_support/core_ext/integer/time.rb +36 -42
  62. data/lib/active_support/core_ext/integer.rb +1 -7
  63. data/lib/active_support/core_ext/kernel/debugger.rb +1 -1
  64. data/lib/active_support/core_ext/kernel/reporting.rb +9 -7
  65. data/lib/active_support/core_ext/kernel/requires.rb +3 -1
  66. data/lib/active_support/core_ext/kernel/singleton_class.rb +13 -0
  67. data/lib/active_support/core_ext/kernel.rb +1 -1
  68. data/lib/active_support/core_ext/load_error.rb +16 -32
  69. data/lib/active_support/core_ext/logger.rb +3 -2
  70. data/lib/active_support/core_ext/module/aliasing.rb +64 -68
  71. data/lib/active_support/core_ext/module/anonymous.rb +24 -0
  72. data/lib/active_support/core_ext/module/attr_accessor_with_default.rb +1 -1
  73. data/lib/active_support/core_ext/module/attr_internal.rb +4 -4
  74. data/lib/active_support/core_ext/module/attribute_accessors.rb +48 -42
  75. data/lib/active_support/core_ext/module/delegation.rb +22 -11
  76. data/lib/active_support/core_ext/module/deprecation.rb +9 -0
  77. data/lib/active_support/core_ext/module/introspection.rb +77 -79
  78. data/lib/active_support/core_ext/module/method_names.rb +14 -0
  79. data/lib/active_support/core_ext/module/reachable.rb +10 -0
  80. data/lib/active_support/core_ext/module/remove_method.rb +6 -0
  81. data/lib/active_support/core_ext/module/synchronization.rb +4 -1
  82. data/lib/active_support/core_ext/module.rb +7 -18
  83. data/lib/active_support/core_ext/name_error.rb +3 -4
  84. data/lib/active_support/core_ext/numeric/bytes.rb +35 -41
  85. data/lib/active_support/core_ext/numeric/time.rb +70 -74
  86. data/lib/active_support/core_ext/numeric.rb +1 -8
  87. data/lib/active_support/core_ext/object/acts_like.rb +10 -0
  88. data/lib/active_support/core_ext/object/blank.rb +20 -2
  89. data/lib/active_support/core_ext/object/conversions.rb +4 -15
  90. data/lib/active_support/core_ext/object/duplicable.rb +65 -0
  91. data/lib/active_support/core_ext/object/extending.rb +8 -77
  92. data/lib/active_support/core_ext/object/instance_variables.rb +0 -7
  93. data/lib/active_support/core_ext/object/misc.rb +2 -90
  94. data/lib/active_support/core_ext/object/returning.rb +42 -0
  95. data/lib/active_support/core_ext/object/to_param.rb +49 -0
  96. data/lib/active_support/core_ext/object/to_query.rb +27 -0
  97. data/lib/active_support/core_ext/{try.rb → object/try.rb} +4 -4
  98. data/lib/active_support/core_ext/object/with_options.rb +24 -0
  99. data/lib/active_support/core_ext/object.rb +10 -2
  100. data/lib/active_support/core_ext/proc.rb +3 -1
  101. data/lib/active_support/core_ext/process/daemon.rb +17 -19
  102. data/lib/active_support/core_ext/range/blockless_step.rb +24 -27
  103. data/lib/active_support/core_ext/range/conversions.rb +17 -23
  104. data/lib/active_support/core_ext/range/include_range.rb +18 -27
  105. data/lib/active_support/core_ext/range/overlaps.rb +6 -13
  106. data/lib/active_support/core_ext/range.rb +2 -9
  107. data/lib/active_support/core_ext/regexp.rb +5 -0
  108. data/lib/active_support/core_ext/rexml.rb +12 -7
  109. data/lib/active_support/core_ext/string/access.rb +88 -95
  110. data/lib/active_support/core_ext/string/behavior.rb +6 -12
  111. data/lib/active_support/core_ext/string/conversions.rb +20 -21
  112. data/lib/active_support/core_ext/string/exclude.rb +6 -0
  113. data/lib/active_support/core_ext/string/filters.rb +17 -23
  114. data/lib/active_support/core_ext/string/inflections.rb +147 -154
  115. data/lib/active_support/core_ext/string/interpolation.rb +1 -0
  116. data/lib/active_support/core_ext/string/multibyte.rb +68 -74
  117. data/lib/active_support/core_ext/string/output_safety.rb +105 -44
  118. data/lib/active_support/core_ext/string/starts_ends_with.rb +3 -34
  119. data/lib/active_support/core_ext/string/xchar.rb +10 -3
  120. data/lib/active_support/core_ext/string.rb +6 -20
  121. data/lib/active_support/core_ext/time/acts_like.rb +8 -0
  122. data/lib/active_support/core_ext/time/calculations.rb +276 -299
  123. data/lib/active_support/core_ext/time/conversions.rb +79 -84
  124. data/lib/active_support/core_ext/time/marshal.rb +56 -0
  125. data/lib/active_support/core_ext/time/publicize_conversion_methods.rb +10 -0
  126. data/lib/active_support/core_ext/time/zones.rb +73 -81
  127. data/lib/active_support/core_ext/uri.rb +2 -1
  128. data/lib/active_support/core_ext.rb +2 -7
  129. data/lib/active_support/dependencies/autoload.rb +50 -0
  130. data/lib/active_support/dependencies.rb +168 -197
  131. data/lib/active_support/deprecation/behaviors.rb +38 -0
  132. data/lib/active_support/deprecation/method_wrappers.rb +29 -0
  133. data/lib/active_support/deprecation/proxy_wrappers.rb +74 -0
  134. data/lib/active_support/deprecation/reporting.rb +56 -0
  135. data/lib/active_support/deprecation.rb +9 -187
  136. data/lib/active_support/duration.rb +6 -2
  137. data/lib/active_support/hash_with_indifferent_access.rb +141 -0
  138. data/lib/active_support/i18n.rb +3 -0
  139. data/lib/active_support/inflections.rb +1 -1
  140. data/lib/active_support/inflector/inflections.rb +211 -0
  141. data/lib/active_support/inflector/methods.rb +141 -0
  142. data/lib/active_support/inflector/transliterate.rb +77 -0
  143. data/lib/active_support/inflector.rb +4 -403
  144. data/lib/active_support/json/backends/jsongem.rb +16 -10
  145. data/lib/active_support/json/backends/yajl.rb +40 -0
  146. data/lib/active_support/json/backends/yaml.rb +14 -8
  147. data/lib/active_support/json/decoding.rb +17 -1
  148. data/lib/active_support/json/encoding.rb +164 -35
  149. data/lib/active_support/json/variable.rb +4 -3
  150. data/lib/active_support/lazy_load_hooks.rb +17 -0
  151. data/lib/active_support/memoizable.rb +8 -5
  152. data/lib/active_support/message_encryptor.rb +1 -0
  153. data/lib/active_support/message_verifier.rb +12 -29
  154. data/lib/active_support/multibyte/chars.rb +88 -31
  155. data/lib/active_support/multibyte/unicode_database.rb +5 -5
  156. data/lib/active_support/multibyte/utils.rb +6 -7
  157. data/lib/active_support/multibyte.rb +11 -6
  158. data/lib/active_support/notifications/fanout.rb +83 -0
  159. data/lib/active_support/notifications/instrumenter.rb +50 -0
  160. data/lib/active_support/notifications.rb +81 -0
  161. data/lib/active_support/option_merger.rb +2 -0
  162. data/lib/active_support/ordered_hash.rb +28 -11
  163. data/lib/active_support/ordered_options.rb +9 -1
  164. data/lib/active_support/railtie.rb +64 -0
  165. data/lib/active_support/rescuable.rb +11 -6
  166. data/lib/active_support/ruby/shim.rb +21 -0
  167. data/lib/active_support/test_case.rb +10 -8
  168. data/lib/active_support/testing/assertions.rb +17 -0
  169. data/lib/active_support/testing/declarative.rb +31 -12
  170. data/lib/active_support/testing/deprecation.rb +8 -10
  171. data/lib/active_support/testing/isolation.rb +153 -0
  172. data/lib/active_support/testing/pending.rb +48 -0
  173. data/lib/active_support/testing/performance.rb +342 -339
  174. data/lib/active_support/testing/setup_and_teardown.rb +48 -31
  175. data/lib/active_support/time/autoload.rb +5 -0
  176. data/lib/active_support/time.rb +34 -0
  177. data/lib/active_support/time_with_zone.rb +18 -12
  178. data/lib/active_support/values/time_zone.rb +51 -68
  179. data/lib/active_support/version.rb +5 -4
  180. data/lib/active_support/whiny_nil.rb +5 -9
  181. data/lib/active_support/xml_mini/jdom.rb +13 -7
  182. data/lib/active_support/xml_mini/libxml.rb +38 -91
  183. data/lib/active_support/xml_mini/libxmlsax.rb +85 -0
  184. data/lib/active_support/xml_mini/nokogiri.rb +40 -31
  185. data/lib/active_support/xml_mini/nokogirisax.rb +83 -0
  186. data/lib/active_support/xml_mini/rexml.rb +30 -9
  187. data/lib/active_support/xml_mini.rb +2 -0
  188. data/lib/active_support.rb +46 -30
  189. metadata +136 -215
  190. data/lib/active_support/cache/drb_store.rb +0 -14
  191. data/lib/active_support/core_ext/array/wrapper.rb +0 -24
  192. data/lib/active_support/core_ext/base64/encoding.rb +0 -16
  193. data/lib/active_support/core_ext/base64.rb +0 -4
  194. data/lib/active_support/core_ext/bigdecimal/conversions.rb +0 -37
  195. data/lib/active_support/core_ext/bigdecimal.rb +0 -6
  196. data/lib/active_support/core_ext/blank.rb +0 -2
  197. data/lib/active_support/core_ext/class/removal.rb +0 -50
  198. data/lib/active_support/core_ext/date/behavior.rb +0 -42
  199. data/lib/active_support/core_ext/date.rb +0 -10
  200. data/lib/active_support/core_ext/date_time.rb +0 -12
  201. data/lib/active_support/core_ext/duplicable.rb +0 -43
  202. data/lib/active_support/core_ext/float/time.rb +0 -27
  203. data/lib/active_support/core_ext/integer/even_odd.rb +0 -29
  204. data/lib/active_support/core_ext/kernel/daemonizing.rb +0 -7
  205. data/lib/active_support/core_ext/module/inclusion.rb +0 -30
  206. data/lib/active_support/core_ext/module/loading.rb +0 -23
  207. data/lib/active_support/core_ext/module/model_naming.rb +0 -25
  208. data/lib/active_support/core_ext/numeric/conversions.rb +0 -19
  209. data/lib/active_support/core_ext/object/metaclass.rb +0 -13
  210. data/lib/active_support/core_ext/pathname/clean_within.rb +0 -14
  211. data/lib/active_support/core_ext/pathname.rb +0 -7
  212. data/lib/active_support/core_ext/string/bytesize.rb +0 -5
  213. data/lib/active_support/core_ext/string/iterators.rb +0 -23
  214. data/lib/active_support/core_ext/symbol.rb +0 -14
  215. data/lib/active_support/core_ext/time/behavior.rb +0 -13
  216. data/lib/active_support/core_ext/time.rb +0 -42
  217. data/lib/active_support/json/encoders/date.rb +0 -22
  218. data/lib/active_support/json/encoders/date_time.rb +0 -22
  219. data/lib/active_support/json/encoders/enumerable.rb +0 -17
  220. data/lib/active_support/json/encoders/false_class.rb +0 -7
  221. data/lib/active_support/json/encoders/hash.rb +0 -56
  222. data/lib/active_support/json/encoders/nil_class.rb +0 -7
  223. data/lib/active_support/json/encoders/numeric.rb +0 -21
  224. data/lib/active_support/json/encoders/object.rb +0 -10
  225. data/lib/active_support/json/encoders/regexp.rb +0 -9
  226. data/lib/active_support/json/encoders/string.rb +0 -9
  227. data/lib/active_support/json/encoders/symbol.rb +0 -5
  228. data/lib/active_support/json/encoders/time.rb +0 -22
  229. data/lib/active_support/json/encoders/true_class.rb +0 -7
  230. data/lib/active_support/vendor/builder-2.1.2/blankslate.rb +0 -113
  231. data/lib/active_support/vendor/builder-2.1.2/builder/blankslate.rb +0 -20
  232. data/lib/active_support/vendor/builder-2.1.2/builder/css.rb +0 -250
  233. data/lib/active_support/vendor/builder-2.1.2/builder/xchar.rb +0 -115
  234. data/lib/active_support/vendor/builder-2.1.2/builder/xmlbase.rb +0 -139
  235. data/lib/active_support/vendor/builder-2.1.2/builder/xmlevents.rb +0 -63
  236. data/lib/active_support/vendor/builder-2.1.2/builder/xmlmarkup.rb +0 -328
  237. data/lib/active_support/vendor/builder-2.1.2/builder.rb +0 -13
  238. data/lib/active_support/vendor/i18n-0.1.3/MIT-LICENSE +0 -20
  239. data/lib/active_support/vendor/i18n-0.1.3/README.textile +0 -20
  240. data/lib/active_support/vendor/i18n-0.1.3/Rakefile +0 -5
  241. data/lib/active_support/vendor/i18n-0.1.3/i18n.gemspec +0 -27
  242. data/lib/active_support/vendor/i18n-0.1.3/lib/i18n/backend/simple.rb +0 -214
  243. data/lib/active_support/vendor/i18n-0.1.3/lib/i18n/exceptions.rb +0 -53
  244. data/lib/active_support/vendor/i18n-0.1.3/lib/i18n.rb +0 -199
  245. data/lib/active_support/vendor/i18n-0.1.3/test/all.rb +0 -5
  246. data/lib/active_support/vendor/i18n-0.1.3/test/i18n_exceptions_test.rb +0 -99
  247. data/lib/active_support/vendor/i18n-0.1.3/test/i18n_test.rb +0 -124
  248. data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.rb +0 -1
  249. data/lib/active_support/vendor/i18n-0.1.3/test/locale/en.yml +0 -3
  250. data/lib/active_support/vendor/i18n-0.1.3/test/simple_backend_test.rb +0 -567
  251. data/lib/active_support/vendor/memcache-client-1.7.4/memcache.rb +0 -1107
  252. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone.rb +0 -47
  253. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/data_timezone_info.rb +0 -228
  254. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Algiers.rb +0 -55
  255. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Cairo.rb +0 -219
  256. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Casablanca.rb +0 -40
  257. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Harare.rb +0 -18
  258. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Johannesburg.rb +0 -25
  259. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Monrovia.rb +0 -22
  260. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Africa/Nairobi.rb +0 -23
  261. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Argentina/Buenos_Aires.rb +0 -166
  262. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Argentina/San_Juan.rb +0 -86
  263. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Bogota.rb +0 -23
  264. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Caracas.rb +0 -23
  265. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Chicago.rb +0 -283
  266. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Chihuahua.rb +0 -136
  267. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Denver.rb +0 -204
  268. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Godthab.rb +0 -161
  269. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Guatemala.rb +0 -27
  270. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Halifax.rb +0 -274
  271. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Indiana/Indianapolis.rb +0 -149
  272. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Juneau.rb +0 -194
  273. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/La_Paz.rb +0 -22
  274. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Lima.rb +0 -35
  275. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Los_Angeles.rb +0 -232
  276. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Mazatlan.rb +0 -139
  277. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Mexico_City.rb +0 -144
  278. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Monterrey.rb +0 -131
  279. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/New_York.rb +0 -282
  280. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Phoenix.rb +0 -30
  281. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Regina.rb +0 -74
  282. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Santiago.rb +0 -205
  283. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Sao_Paulo.rb +0 -171
  284. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/St_Johns.rb +0 -288
  285. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/America/Tijuana.rb +0 -196
  286. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Almaty.rb +0 -67
  287. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Baghdad.rb +0 -73
  288. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Baku.rb +0 -161
  289. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Bangkok.rb +0 -20
  290. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Chongqing.rb +0 -33
  291. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Colombo.rb +0 -30
  292. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Dhaka.rb +0 -27
  293. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Hong_Kong.rb +0 -87
  294. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Irkutsk.rb +0 -165
  295. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Jakarta.rb +0 -30
  296. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Jerusalem.rb +0 -163
  297. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kabul.rb +0 -20
  298. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kamchatka.rb +0 -163
  299. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Karachi.rb +0 -30
  300. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Katmandu.rb +0 -20
  301. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kolkata.rb +0 -25
  302. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Krasnoyarsk.rb +0 -163
  303. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kuala_Lumpur.rb +0 -31
  304. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Kuwait.rb +0 -18
  305. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Magadan.rb +0 -163
  306. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Muscat.rb +0 -18
  307. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Novosibirsk.rb +0 -164
  308. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Rangoon.rb +0 -24
  309. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Riyadh.rb +0 -18
  310. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Seoul.rb +0 -34
  311. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Shanghai.rb +0 -35
  312. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Singapore.rb +0 -33
  313. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Taipei.rb +0 -59
  314. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tashkent.rb +0 -47
  315. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tbilisi.rb +0 -78
  316. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tehran.rb +0 -121
  317. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Tokyo.rb +0 -30
  318. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Ulaanbaatar.rb +0 -65
  319. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Urumqi.rb +0 -33
  320. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Vladivostok.rb +0 -164
  321. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yakutsk.rb +0 -163
  322. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yekaterinburg.rb +0 -165
  323. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Asia/Yerevan.rb +0 -165
  324. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/Azores.rb +0 -270
  325. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/Cape_Verde.rb +0 -23
  326. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Atlantic/South_Georgia.rb +0 -18
  327. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Adelaide.rb +0 -187
  328. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Brisbane.rb +0 -35
  329. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Darwin.rb +0 -29
  330. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Hobart.rb +0 -193
  331. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Melbourne.rb +0 -185
  332. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Perth.rb +0 -37
  333. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Australia/Sydney.rb +0 -185
  334. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Etc/UTC.rb +0 -16
  335. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Amsterdam.rb +0 -228
  336. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Athens.rb +0 -185
  337. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Belgrade.rb +0 -163
  338. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Berlin.rb +0 -188
  339. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Bratislava.rb +0 -13
  340. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Brussels.rb +0 -232
  341. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Bucharest.rb +0 -181
  342. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Budapest.rb +0 -197
  343. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Copenhagen.rb +0 -179
  344. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Dublin.rb +0 -276
  345. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Helsinki.rb +0 -163
  346. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Istanbul.rb +0 -218
  347. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Kiev.rb +0 -168
  348. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Lisbon.rb +0 -268
  349. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Ljubljana.rb +0 -13
  350. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/London.rb +0 -288
  351. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Madrid.rb +0 -211
  352. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Minsk.rb +0 -170
  353. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Moscow.rb +0 -181
  354. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Paris.rb +0 -232
  355. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Prague.rb +0 -187
  356. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Riga.rb +0 -176
  357. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Rome.rb +0 -215
  358. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Sarajevo.rb +0 -13
  359. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Skopje.rb +0 -13
  360. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Sofia.rb +0 -173
  361. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Stockholm.rb +0 -165
  362. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Tallinn.rb +0 -172
  363. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Vienna.rb +0 -183
  364. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Vilnius.rb +0 -170
  365. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Warsaw.rb +0 -212
  366. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Europe/Zagreb.rb +0 -13
  367. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Auckland.rb +0 -202
  368. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Fiji.rb +0 -23
  369. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Guam.rb +0 -22
  370. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Honolulu.rb +0 -28
  371. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Majuro.rb +0 -20
  372. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Midway.rb +0 -25
  373. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Noumea.rb +0 -25
  374. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Pago_Pago.rb +0 -26
  375. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Port_Moresby.rb +0 -20
  376. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/definitions/Pacific/Tongatapu.rb +0 -27
  377. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/info_timezone.rb +0 -52
  378. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/linked_timezone.rb +0 -51
  379. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/linked_timezone_info.rb +0 -44
  380. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/offset_rationals.rb +0 -98
  381. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/ruby_core_support.rb +0 -56
  382. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/time_or_datetime.rb +0 -292
  383. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone.rb +0 -508
  384. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_definition.rb +0 -56
  385. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_info.rb +0 -40
  386. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_offset_info.rb +0 -94
  387. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_period.rb +0 -198
  388. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo/timezone_transition_info.rb +0 -129
  389. data/lib/active_support/vendor/tzinfo-0.3.12/tzinfo.rb +0 -33
  390. data/lib/active_support/vendor.rb +0 -28
  391. data/lib/activesupport.rb +0 -2
@@ -1,406 +1,7 @@
1
- # encoding: utf-8
2
- require 'singleton'
3
- require 'iconv'
4
-
5
- module ActiveSupport
6
- # The Inflector transforms words from singular to plural, class names to table names, modularized class names to ones without,
7
- # and class names to foreign keys. The default inflections for pluralization, singularization, and uncountable words are kept
8
- # in inflections.rb.
9
- #
10
- # The Rails core team has stated patches for the inflections library will not be accepted
11
- # in order to avoid breaking legacy applications which may be relying on errant inflections.
12
- # If you discover an incorrect inflection and require it for your application, you'll need
13
- # to correct it yourself (explained below).
14
- module Inflector
15
- extend self
16
-
17
- # A singleton instance of this class is yielded by Inflector.inflections, which can then be used to specify additional
18
- # inflection rules. Examples:
19
- #
20
- # ActiveSupport::Inflector.inflections do |inflect|
21
- # inflect.plural /^(ox)$/i, '\1\2en'
22
- # inflect.singular /^(ox)en/i, '\1'
23
- #
24
- # inflect.irregular 'octopus', 'octopi'
25
- #
26
- # inflect.uncountable "equipment"
27
- # end
28
- #
29
- # New rules are added at the top. So in the example above, the irregular rule for octopus will now be the first of the
30
- # pluralization and singularization rules that is runs. This guarantees that your rules run before any of the rules that may
31
- # already have been loaded.
32
- class Inflections
33
- include Singleton
34
-
35
- attr_reader :plurals, :singulars, :uncountables, :humans
36
-
37
- def initialize
38
- @plurals, @singulars, @uncountables, @humans = [], [], [], []
39
- end
40
-
41
- # Specifies a new pluralization rule and its replacement. The rule can either be a string or a regular expression.
42
- # The replacement should always be a string that may include references to the matched data from the rule.
43
- def plural(rule, replacement)
44
- @uncountables.delete(rule) if rule.is_a?(String)
45
- @uncountables.delete(replacement)
46
- @plurals.insert(0, [rule, replacement])
47
- end
48
-
49
- # Specifies a new singularization rule and its replacement. The rule can either be a string or a regular expression.
50
- # The replacement should always be a string that may include references to the matched data from the rule.
51
- def singular(rule, replacement)
52
- @uncountables.delete(rule) if rule.is_a?(String)
53
- @uncountables.delete(replacement)
54
- @singulars.insert(0, [rule, replacement])
55
- end
56
-
57
- # Specifies a new irregular that applies to both pluralization and singularization at the same time. This can only be used
58
- # for strings, not regular expressions. You simply pass the irregular in singular and plural form.
59
- #
60
- # Examples:
61
- # irregular 'octopus', 'octopi'
62
- # irregular 'person', 'people'
63
- def irregular(singular, plural)
64
- @uncountables.delete(singular)
65
- @uncountables.delete(plural)
66
- if singular[0,1].upcase == plural[0,1].upcase
67
- plural(Regexp.new("(#{singular[0,1]})#{singular[1..-1]}$", "i"), '\1' + plural[1..-1])
68
- singular(Regexp.new("(#{plural[0,1]})#{plural[1..-1]}$", "i"), '\1' + singular[1..-1])
69
- else
70
- plural(Regexp.new("#{singular[0,1].upcase}(?i)#{singular[1..-1]}$"), plural[0,1].upcase + plural[1..-1])
71
- plural(Regexp.new("#{singular[0,1].downcase}(?i)#{singular[1..-1]}$"), plural[0,1].downcase + plural[1..-1])
72
- singular(Regexp.new("#{plural[0,1].upcase}(?i)#{plural[1..-1]}$"), singular[0,1].upcase + singular[1..-1])
73
- singular(Regexp.new("#{plural[0,1].downcase}(?i)#{plural[1..-1]}$"), singular[0,1].downcase + singular[1..-1])
74
- end
75
- end
76
-
77
- # Add uncountable words that shouldn't be attempted inflected.
78
- #
79
- # Examples:
80
- # uncountable "money"
81
- # uncountable "money", "information"
82
- # uncountable %w( money information rice )
83
- def uncountable(*words)
84
- (@uncountables << words).flatten!
85
- end
86
-
87
- # Specifies a humanized form of a string by a regular expression rule or by a string mapping.
88
- # When using a regular expression based replacement, the normal humanize formatting is called after the replacement.
89
- # When a string is used, the human form should be specified as desired (example: 'The name', not 'the_name')
90
- #
91
- # Examples:
92
- # human /_cnt$/i, '\1_count'
93
- # human "legacy_col_person_name", "Name"
94
- def human(rule, replacement)
95
- @humans.insert(0, [rule, replacement])
96
- end
97
-
98
- # Clears the loaded inflections within a given scope (default is <tt>:all</tt>).
99
- # Give the scope as a symbol of the inflection type, the options are: <tt>:plurals</tt>,
100
- # <tt>:singulars</tt>, <tt>:uncountables</tt>, <tt>:humans</tt>.
101
- #
102
- # Examples:
103
- # clear :all
104
- # clear :plurals
105
- def clear(scope = :all)
106
- case scope
107
- when :all
108
- @plurals, @singulars, @uncountables = [], [], []
109
- else
110
- instance_variable_set "@#{scope}", []
111
- end
112
- end
113
- end
114
-
115
- # Yields a singleton instance of Inflector::Inflections so you can specify additional
116
- # inflector rules.
117
- #
118
- # Example:
119
- # ActiveSupport::Inflector.inflections do |inflect|
120
- # inflect.uncountable "rails"
121
- # end
122
- def inflections
123
- if block_given?
124
- yield Inflections.instance
125
- else
126
- Inflections.instance
127
- end
128
- end
129
-
130
- # Returns the plural form of the word in the string.
131
- #
132
- # Examples:
133
- # "post".pluralize # => "posts"
134
- # "octopus".pluralize # => "octopi"
135
- # "sheep".pluralize # => "sheep"
136
- # "words".pluralize # => "words"
137
- # "CamelOctopus".pluralize # => "CamelOctopi"
138
- def pluralize(word)
139
- result = word.to_s.dup
140
-
141
- if word.empty? || inflections.uncountables.include?(result.downcase)
142
- result
143
- else
144
- inflections.plurals.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
145
- result
146
- end
147
- end
148
-
149
- # The reverse of +pluralize+, returns the singular form of a word in a string.
150
- #
151
- # Examples:
152
- # "posts".singularize # => "post"
153
- # "octopi".singularize # => "octopus"
154
- # "sheep".singluarize # => "sheep"
155
- # "word".singularize # => "word"
156
- # "CamelOctopi".singularize # => "CamelOctopus"
157
- def singularize(word)
158
- result = word.to_s.dup
159
-
160
- if inflections.uncountables.include?(result.downcase)
161
- result
162
- else
163
- inflections.singulars.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
164
- result
165
- end
166
- end
167
-
168
- # By default, +camelize+ converts strings to UpperCamelCase. If the argument to +camelize+
169
- # is set to <tt>:lower</tt> then +camelize+ produces lowerCamelCase.
170
- #
171
- # +camelize+ will also convert '/' to '::' which is useful for converting paths to namespaces.
172
- #
173
- # Examples:
174
- # "active_record".camelize # => "ActiveRecord"
175
- # "active_record".camelize(:lower) # => "activeRecord"
176
- # "active_record/errors".camelize # => "ActiveRecord::Errors"
177
- # "active_record/errors".camelize(:lower) # => "activeRecord::Errors"
178
- def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
179
- if first_letter_in_uppercase
180
- lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
181
- else
182
- lower_case_and_underscored_word.first.downcase + camelize(lower_case_and_underscored_word)[1..-1]
183
- end
184
- end
185
-
186
- # Capitalizes all the words and replaces some characters in the string to create
187
- # a nicer looking title. +titleize+ is meant for creating pretty output. It is not
188
- # used in the Rails internals.
189
- #
190
- # +titleize+ is also aliased as as +titlecase+.
191
- #
192
- # Examples:
193
- # "man from the boondocks".titleize # => "Man From The Boondocks"
194
- # "x-men: the last stand".titleize # => "X Men: The Last Stand"
195
- def titleize(word)
196
- humanize(underscore(word)).gsub(/\b('?[a-z])/) { $1.capitalize }
197
- end
198
-
199
- # The reverse of +camelize+. Makes an underscored, lowercase form from the expression in the string.
200
- #
201
- # Changes '::' to '/' to convert namespaces to paths.
202
- #
203
- # Examples:
204
- # "ActiveRecord".underscore # => "active_record"
205
- # "ActiveRecord::Errors".underscore # => active_record/errors
206
- def underscore(camel_cased_word)
207
- camel_cased_word.to_s.gsub(/::/, '/').
208
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
209
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
210
- tr("-", "_").
211
- downcase
212
- end
213
-
214
- # Replaces underscores with dashes in the string.
215
- #
216
- # Example:
217
- # "puni_puni" # => "puni-puni"
218
- def dasherize(underscored_word)
219
- underscored_word.gsub(/_/, '-')
220
- end
221
-
222
- # Capitalizes the first word and turns underscores into spaces and strips a
223
- # trailing "_id", if any. Like +titleize+, this is meant for creating pretty output.
224
- #
225
- # Examples:
226
- # "employee_salary" # => "Employee salary"
227
- # "author_id" # => "Author"
228
- def humanize(lower_case_and_underscored_word)
229
- result = lower_case_and_underscored_word.to_s.dup
230
-
231
- inflections.humans.each { |(rule, replacement)| break if result.gsub!(rule, replacement) }
232
- result.gsub(/_id$/, "").gsub(/_/, " ").capitalize
233
- end
234
-
235
- # Removes the module part from the expression in the string.
236
- #
237
- # Examples:
238
- # "ActiveRecord::CoreExtensions::String::Inflections".demodulize # => "Inflections"
239
- # "Inflections".demodulize # => "Inflections"
240
- def demodulize(class_name_in_module)
241
- class_name_in_module.to_s.gsub(/^.*::/, '')
242
- end
243
-
244
- # Replaces special characters in a string so that it may be used as part of a 'pretty' URL.
245
- #
246
- # ==== Examples
247
- #
248
- # class Person
249
- # def to_param
250
- # "#{id}-#{name.parameterize}"
251
- # end
252
- # end
253
- #
254
- # @person = Person.find(1)
255
- # # => #<Person id: 1, name: "Donald E. Knuth">
256
- #
257
- # <%= link_to(@person.name, person_path(@person)) %>
258
- # # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a>
259
- def parameterize(string, sep = '-')
260
- # replace accented chars with ther ascii equivalents
261
- parameterized_string = transliterate(string)
262
- # Turn unwanted chars into the seperator
263
- parameterized_string.gsub!(/[^a-z0-9\-_\+]+/i, sep)
264
- unless sep.blank?
265
- re_sep = Regexp.escape(sep)
266
- # No more than one of the separator in a row.
267
- parameterized_string.gsub!(/#{re_sep}{2,}/, sep)
268
- # Remove leading/trailing separator.
269
- parameterized_string.gsub!(/^#{re_sep}|#{re_sep}$/i, '')
270
- end
271
- parameterized_string.downcase
272
- end
273
-
274
-
275
- # Replaces accented characters with their ascii equivalents.
276
- def transliterate(string)
277
- Iconv.iconv('ascii//ignore//translit', 'utf-8', string).to_s
278
- end
279
-
280
- if RUBY_VERSION >= '1.9'
281
- undef_method :transliterate
282
- def transliterate(string)
283
- warn "Ruby 1.9 doesn't support Unicode normalization yet"
284
- string.dup
285
- end
286
-
287
- # The iconv transliteration code doesn't function correctly
288
- # on some platforms, but it's very fast where it does function.
289
- elsif "foo" != (Inflector.transliterate("föö") rescue nil)
290
- undef_method :transliterate
291
- def transliterate(string)
292
- string.mb_chars.normalize(:kd). # Decompose accented characters
293
- gsub(/[^\x00-\x7F]+/, '') # Remove anything non-ASCII entirely (e.g. diacritics).
294
- end
295
- end
296
-
297
- # Create the name of a table like Rails does for models to table names. This method
298
- # uses the +pluralize+ method on the last word in the string.
299
- #
300
- # Examples
301
- # "RawScaledScorer".tableize # => "raw_scaled_scorers"
302
- # "egg_and_ham".tableize # => "egg_and_hams"
303
- # "fancyCategory".tableize # => "fancy_categories"
304
- def tableize(class_name)
305
- pluralize(underscore(class_name))
306
- end
307
-
308
- # Create a class name from a plural table name like Rails does for table names to models.
309
- # Note that this returns a string and not a Class. (To convert to an actual class
310
- # follow +classify+ with +constantize+.)
311
- #
312
- # Examples:
313
- # "egg_and_hams".classify # => "EggAndHam"
314
- # "posts".classify # => "Post"
315
- #
316
- # Singular names are not handled correctly:
317
- # "business".classify # => "Busines"
318
- def classify(table_name)
319
- # strip out any leading schema name
320
- camelize(singularize(table_name.to_s.sub(/.*\./, '')))
321
- end
322
-
323
- # Creates a foreign key name from a class name.
324
- # +separate_class_name_and_id_with_underscore+ sets whether
325
- # the method should put '_' between the name and 'id'.
326
- #
327
- # Examples:
328
- # "Message".foreign_key # => "message_id"
329
- # "Message".foreign_key(false) # => "messageid"
330
- # "Admin::Post".foreign_key # => "post_id"
331
- def foreign_key(class_name, separate_class_name_and_id_with_underscore = true)
332
- underscore(demodulize(class_name)) + (separate_class_name_and_id_with_underscore ? "_id" : "id")
333
- end
334
-
335
- # Ruby 1.9 introduces an inherit argument for Module#const_get and
336
- # #const_defined? and changes their default behavior.
337
- if Module.method(:const_get).arity == 1
338
- # Tries to find a constant with the name specified in the argument string:
339
- #
340
- # "Module".constantize # => Module
341
- # "Test::Unit".constantize # => Test::Unit
342
- #
343
- # The name is assumed to be the one of a top-level constant, no matter whether
344
- # it starts with "::" or not. No lexical context is taken into account:
345
- #
346
- # C = 'outside'
347
- # module M
348
- # C = 'inside'
349
- # C # => 'inside'
350
- # "C".constantize # => 'outside', same as ::C
351
- # end
352
- #
353
- # NameError is raised when the name is not in CamelCase or the constant is
354
- # unknown.
355
- def constantize(camel_cased_word)
356
- names = camel_cased_word.split('::')
357
- names.shift if names.empty? || names.first.empty?
358
-
359
- constant = Object
360
- names.each do |name|
361
- constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
362
- end
363
- constant
364
- end
365
- else
366
- def constantize(camel_cased_word) #:nodoc:
367
- names = camel_cased_word.split('::')
368
- names.shift if names.empty? || names.first.empty?
369
-
370
- constant = Object
371
- names.each do |name|
372
- constant = constant.const_get(name, false) || constant.const_missing(name)
373
- end
374
- constant
375
- end
376
- end
377
-
378
- # Turns a number into an ordinal string used to denote the position in an
379
- # ordered sequence such as 1st, 2nd, 3rd, 4th.
380
- #
381
- # Examples:
382
- # ordinalize(1) # => "1st"
383
- # ordinalize(2) # => "2nd"
384
- # ordinalize(1002) # => "1002nd"
385
- # ordinalize(1003) # => "1003rd"
386
- def ordinalize(number)
387
- if (11..13).include?(number.to_i % 100)
388
- "#{number}th"
389
- else
390
- case number.to_i % 10
391
- when 1; "#{number}st"
392
- when 2; "#{number}nd"
393
- when 3; "#{number}rd"
394
- else "#{number}th"
395
- end
396
- end
397
- end
398
- end
399
- end
400
-
401
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
+
402
6
  require 'active_support/inflections'
403
7
  require 'active_support/core_ext/string/inflections'
404
- unless String.included_modules.include?(ActiveSupport::CoreExtensions::String::Inflections)
405
- String.send :include, ActiveSupport::CoreExtensions::String::Inflections
406
- end
@@ -7,8 +7,11 @@ module ActiveSupport
7
7
  ParseError = ::JSON::ParserError
8
8
  extend self
9
9
 
10
- # Converts a JSON string into a Ruby object.
10
+ # Parses a JSON string or IO and convert it into an object
11
11
  def decode(json)
12
+ if json.respond_to?(:read)
13
+ json = json.read
14
+ end
12
15
  data = ::JSON.parse(json)
13
16
  if ActiveSupport.parse_json_times
14
17
  convert_dates_from(data)
@@ -20,15 +23,18 @@ module ActiveSupport
20
23
  private
21
24
  def convert_dates_from(data)
22
25
  case data
23
- when DATE_REGEX
24
- DateTime.parse(data)
25
- when Array
26
- data.map! { |d| convert_dates_from(d) }
27
- when Hash
28
- data.each do |key, value|
29
- data[key] = convert_dates_from(value)
30
- end
31
- else data
26
+ when nil
27
+ nil
28
+ when DATE_REGEX
29
+ DateTime.parse(data)
30
+ when Array
31
+ data.map! { |d| convert_dates_from(d) }
32
+ when Hash
33
+ data.each do |key, value|
34
+ data[key] = convert_dates_from(value)
35
+ end
36
+ else
37
+ data
32
38
  end
33
39
  end
34
40
  end
@@ -0,0 +1,40 @@
1
+ require 'yajl-ruby' unless defined?(Yajl)
2
+
3
+ module ActiveSupport
4
+ module JSON
5
+ module Backends
6
+ module Yajl
7
+ ParseError = ::Yajl::ParseError
8
+ extend self
9
+
10
+ # Parses a JSON string or IO and convert it into an object
11
+ def decode(json)
12
+ data = ::Yajl::Parser.new.parse(json)
13
+ if ActiveSupport.parse_json_times
14
+ convert_dates_from(data)
15
+ else
16
+ data
17
+ end
18
+ end
19
+
20
+ private
21
+ def convert_dates_from(data)
22
+ case data
23
+ when nil
24
+ nil
25
+ when DATE_REGEX
26
+ DateTime.parse(data)
27
+ when Array
28
+ data.map! { |d| convert_dates_from(d) }
29
+ when Hash
30
+ data.each do |key, value|
31
+ data[key] = convert_dates_from(value)
32
+ end
33
+ else
34
+ data
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -7,8 +7,11 @@ module ActiveSupport
7
7
  ParseError = ::StandardError
8
8
  extend self
9
9
 
10
- # Converts a JSON string into a Ruby object.
10
+ # Parses a JSON string or IO and converts it into an object
11
11
  def decode(json)
12
+ if json.respond_to?(:read)
13
+ json = json.read
14
+ end
12
15
  YAML.load(convert_json_to_yaml(json))
13
16
  rescue ArgumentError => e
14
17
  raise ParseError, "Invalid JSON string"
@@ -27,11 +30,9 @@ module ActiveSupport
27
30
  pos = scanner.pos
28
31
  elsif quoting == char
29
32
  if json[pos..scanner.pos-2] =~ DATE_REGEX
30
- # found a date, track the exact positions of the quotes so we can remove them later.
31
- # oh, and increment them for each current mark, each one is an extra padded space that bumps
32
- # the position in the final YAML output
33
- total_marks = marks.size
34
- times << pos+total_marks << scanner.pos+total_marks
33
+ # found a date, track the exact positions of the quotes so we can
34
+ # overwrite them with spaces later.
35
+ times << pos << scanner.pos
35
36
  end
36
37
  quoting = false
37
38
  end
@@ -59,7 +60,12 @@ module ActiveSupport
59
60
  output = []
60
61
  left_pos.each_with_index do |left, i|
61
62
  scanner.pos = left.succ
62
- output << scanner.peek(right_pos[i] - scanner.pos + 1).gsub(/\\([\\\/]|u[[:xdigit:]]{4})/) do
63
+ chunk = scanner.peek(right_pos[i] - scanner.pos + 1)
64
+ # overwrite the quotes found around the dates with spaces
65
+ while times.size > 0 && times[0] <= right_pos[i]
66
+ chunk[times.shift - scanner.pos - 1] = ' '
67
+ end
68
+ chunk.gsub!(/\\([\\\/]|u[[:xdigit:]]{4})/) do
63
69
  ustr = $1
64
70
  if ustr.start_with?('u')
65
71
  [ustr[1..-1].to_i(16)].pack("U")
@@ -69,10 +75,10 @@ module ActiveSupport
69
75
  ustr
70
76
  end
71
77
  end
78
+ output << chunk
72
79
  end
73
80
  output = output * " "
74
81
 
75
- times.each { |i| output[i-1] = ' ' }
76
82
  output.gsub!(/\\\//, '/')
77
83
  output
78
84
  end
@@ -1,16 +1,20 @@
1
1
  require 'active_support/core_ext/module/attribute_accessors'
2
+ require 'active_support/core_ext/module/delegation'
2
3
 
3
4
  module ActiveSupport
4
5
  # Look for and parse json strings that look like ISO 8601 times.
5
6
  mattr_accessor :parse_json_times
6
7
 
7
8
  module JSON
9
+ # Listed in order of preference.
10
+ DECODERS = %w(Yajl Yaml)
11
+
8
12
  class << self
9
13
  attr_reader :parse_error
10
14
  delegate :decode, :to => :backend
11
15
 
12
16
  def backend
13
- self.backend = "Yaml" unless defined?(@backend)
17
+ set_default_backend unless defined?(@backend)
14
18
  @backend
15
19
  end
16
20
 
@@ -30,6 +34,18 @@ module ActiveSupport
30
34
  ensure
31
35
  self.backend = old_backend
32
36
  end
37
+
38
+ def set_default_backend
39
+ DECODERS.find do |name|
40
+ begin
41
+ self.backend = name
42
+ true
43
+ rescue LoadError
44
+ # Try next decoder.
45
+ false
46
+ end
47
+ end
48
+ end
33
49
  end
34
50
  end
35
51
  end