rio 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (342) hide show
  1. data/ChangeLog +171 -0
  2. data/README +3 -16
  3. data/RUNME.1st.rb +1 -3
  4. data/Rakefile +10 -7
  5. data/VERSION +1 -1
  6. data/doc/ANNOUNCE +1 -1
  7. data/doc/RELEASE_NOTES +3 -4
  8. data/ex/colx.rb +8 -0
  9. data/ex/findinruby +16 -0
  10. data/ex/findruby +15 -0
  11. data/ex/passwd_report.rb +8 -0
  12. data/ex/prompt.rb +25 -0
  13. data/ex/rgb.txt.gz +0 -0
  14. data/ex/riocat +35 -0
  15. data/ex/riogunzip +31 -0
  16. data/ex/riogzip +24 -0
  17. data/ex/rioprompt.rb +6 -0
  18. data/ex/targz2zip +17 -0
  19. data/ex/tolf +11 -0
  20. data/lib/rio.rb +0 -3
  21. data/lib/rio/construct.rb +14 -20
  22. data/lib/rio/dir.rb +2 -2
  23. data/lib/rio/doc/INTRO.rb +12 -16
  24. data/lib/rio/ext.rb +2 -1
  25. data/lib/rio/ext/csv.rb +5 -1
  26. data/lib/rio/ext/yaml.rb +11 -12
  27. data/lib/rio/filter.rb +1 -1
  28. data/lib/rio/ftp.rb +1 -1
  29. data/lib/rio/if/dir.rb +2 -2
  30. data/lib/rio/if/grande.rb +7 -1
  31. data/lib/rio/if/yaml.rb +1 -1
  32. data/lib/rio/ioh.rb +11 -1
  33. data/lib/rio/ops/construct.rb +11 -10
  34. data/lib/rio/ops/dir.rb +38 -19
  35. data/lib/rio/rl/ioi.rb +2 -2
  36. data/lib/rio/scheme/temp.rb +2 -2
  37. data/lib/rio/state.rb +1 -1
  38. data/lib/rio/stream/open.rb +9 -6
  39. data/lib/rio/util.rb +49 -0
  40. data/lib/rio/version.rb +1 -1
  41. data/test/tc/all.rb +3 -1
  42. data/test/tc/cd1.rb +0 -3
  43. data/test/tc/clearsel.rb +1 -2
  44. data/test/tc/copy-from.rb +0 -3
  45. data/test/tc/copy-to.rb +0 -3
  46. data/test/tc/copyarray.rb +1 -4
  47. data/test/tc/copydir.rb +0 -3
  48. data/test/tc/copydirlines.rb +0 -3
  49. data/test/tc/copynonex.rb +0 -3
  50. data/test/tc/csv.rb +0 -3
  51. data/test/tc/dir.rb +0 -3
  52. data/test/tc/dir_iter.rb +384 -0
  53. data/test/tc/dirautoclose.rb +4 -7
  54. data/test/tc/dirent.rb +3 -5
  55. data/test/tc/dirss.rb +2 -5
  56. data/test/tc/each.rb +3 -3
  57. data/test/tc/each_break.rb +17 -28
  58. data/test/tc/edf.rb +1 -2
  59. data/test/tc/entary.rb +1 -4
  60. data/test/tc/expand_path.rb +1 -2
  61. data/test/tc/ext.rb +0 -3
  62. data/test/tc/fileno.rb +1 -2
  63. data/test/tc/get.rb +151 -0
  64. data/test/tc/lineno.rb +1 -2
  65. data/test/tc/methods.rb +1 -1
  66. data/test/tc/misc.rb +1 -5
  67. data/test/tc/nolines.rb +3 -4
  68. data/test/tc/noqae.rb +1 -4
  69. data/test/tc/pa.rb +1 -2
  70. data/test/tc/pathop.rb +0 -3
  71. data/test/tc/paths.rb +1 -3
  72. data/test/tc/qae.rb +1 -2
  73. data/test/tc/qae_riovar.rb +1 -2
  74. data/test/tc/records.rb +1 -2
  75. data/test/tc/rename.rb +1 -3
  76. data/test/tc/rename_assign.rb +0 -3
  77. data/test/tc/riorl.rb +82 -52
  78. data/test/tc/selnosel.rb +0 -3
  79. data/test/tc/sub.rb +0 -3
  80. data/test/tc/symlink.rb +1 -2
  81. data/test/tc/symlink0.rb +1 -2
  82. data/test/tc/symlink1.rb +1 -2
  83. data/test/tc/temp.rb +0 -3
  84. data/test/tc/tempdir.rb +0 -3
  85. data/test/tc/tempfile.rb +0 -3
  86. data/test/tc/testcase.rb +9 -4
  87. data/test/tc/yaml.rb +11 -1
  88. metadata +141 -386
  89. data/doc/rdoc/classes/Kernel.html +0 -181
  90. data/doc/rdoc/classes/Kernel.src/M000214.html +0 -18
  91. data/doc/rdoc/classes/RIO.html +0 -621
  92. data/doc/rdoc/classes/RIO.src/M000001.html +0 -18
  93. data/doc/rdoc/classes/RIO.src/M000002.html +0 -18
  94. data/doc/rdoc/classes/RIO.src/M000003.html +0 -18
  95. data/doc/rdoc/classes/RIO/Doc.html +0 -138
  96. data/doc/rdoc/classes/RIO/Doc/HOWTO.html +0 -1040
  97. data/doc/rdoc/classes/RIO/Doc/INTRO.html +0 -1613
  98. data/doc/rdoc/classes/RIO/Doc/MISC.html +0 -443
  99. data/doc/rdoc/classes/RIO/Doc/SYNOPSIS.html +0 -338
  100. data/doc/rdoc/classes/RIO/IF.html +0 -114
  101. data/doc/rdoc/classes/RIO/IF/CSV.html +0 -202
  102. data/doc/rdoc/classes/RIO/IF/CSV.src/M000004.html +0 -19
  103. data/doc/rdoc/classes/RIO/IF/CSV.src/M000005.html +0 -16
  104. data/doc/rdoc/classes/RIO/IF/CSV.src/M000006.html +0 -16
  105. data/doc/rdoc/classes/RIO/IF/YAML.html +0 -499
  106. data/doc/rdoc/classes/RIO/IF/YAML.src/M000007.html +0 -19
  107. data/doc/rdoc/classes/RIO/IF/YAML.src/M000008.html +0 -16
  108. data/doc/rdoc/classes/RIO/IF/YAML.src/M000009.html +0 -16
  109. data/doc/rdoc/classes/RIO/IF/YAML.src/M000010.html +0 -16
  110. data/doc/rdoc/classes/RIO/IF/YAML.src/M000011.html +0 -16
  111. data/doc/rdoc/classes/RIO/IF/YAML.src/M000012.html +0 -16
  112. data/doc/rdoc/classes/RIO/IF/YAML.src/M000013.html +0 -16
  113. data/doc/rdoc/classes/RIO/IF/YAML.src/M000014.html +0 -16
  114. data/doc/rdoc/classes/RIO/IF/YAML.src/M000015.html +0 -16
  115. data/doc/rdoc/classes/RIO/IF/YAML.src/M000016.html +0 -16
  116. data/doc/rdoc/classes/RIO/IF/YAML.src/M000017.html +0 -16
  117. data/doc/rdoc/classes/RIO/Rio.html +0 -7121
  118. data/doc/rdoc/classes/RIO/Rio.src/M000018.html +0 -18
  119. data/doc/rdoc/classes/RIO/Rio.src/M000019.html +0 -20
  120. data/doc/rdoc/classes/RIO/Rio.src/M000020.html +0 -27
  121. data/doc/rdoc/classes/RIO/Rio.src/M000021.html +0 -16
  122. data/doc/rdoc/classes/RIO/Rio.src/M000023.html +0 -19
  123. data/doc/rdoc/classes/RIO/Rio.src/M000024.html +0 -20
  124. data/doc/rdoc/classes/RIO/Rio.src/M000025.html +0 -16
  125. data/doc/rdoc/classes/RIO/Rio.src/M000026.html +0 -16
  126. data/doc/rdoc/classes/RIO/Rio.src/M000027.html +0 -16
  127. data/doc/rdoc/classes/RIO/Rio.src/M000028.html +0 -16
  128. data/doc/rdoc/classes/RIO/Rio.src/M000029.html +0 -16
  129. data/doc/rdoc/classes/RIO/Rio.src/M000030.html +0 -16
  130. data/doc/rdoc/classes/RIO/Rio.src/M000031.html +0 -16
  131. data/doc/rdoc/classes/RIO/Rio.src/M000032.html +0 -16
  132. data/doc/rdoc/classes/RIO/Rio.src/M000033.html +0 -16
  133. data/doc/rdoc/classes/RIO/Rio.src/M000034.html +0 -16
  134. data/doc/rdoc/classes/RIO/Rio.src/M000035.html +0 -16
  135. data/doc/rdoc/classes/RIO/Rio.src/M000036.html +0 -16
  136. data/doc/rdoc/classes/RIO/Rio.src/M000037.html +0 -16
  137. data/doc/rdoc/classes/RIO/Rio.src/M000038.html +0 -16
  138. data/doc/rdoc/classes/RIO/Rio.src/M000039.html +0 -16
  139. data/doc/rdoc/classes/RIO/Rio.src/M000040.html +0 -16
  140. data/doc/rdoc/classes/RIO/Rio.src/M000041.html +0 -16
  141. data/doc/rdoc/classes/RIO/Rio.src/M000042.html +0 -16
  142. data/doc/rdoc/classes/RIO/Rio.src/M000043.html +0 -16
  143. data/doc/rdoc/classes/RIO/Rio.src/M000044.html +0 -16
  144. data/doc/rdoc/classes/RIO/Rio.src/M000045.html +0 -16
  145. data/doc/rdoc/classes/RIO/Rio.src/M000046.html +0 -16
  146. data/doc/rdoc/classes/RIO/Rio.src/M000047.html +0 -16
  147. data/doc/rdoc/classes/RIO/Rio.src/M000048.html +0 -16
  148. data/doc/rdoc/classes/RIO/Rio.src/M000049.html +0 -16
  149. data/doc/rdoc/classes/RIO/Rio.src/M000050.html +0 -16
  150. data/doc/rdoc/classes/RIO/Rio.src/M000051.html +0 -16
  151. data/doc/rdoc/classes/RIO/Rio.src/M000052.html +0 -16
  152. data/doc/rdoc/classes/RIO/Rio.src/M000053.html +0 -16
  153. data/doc/rdoc/classes/RIO/Rio.src/M000054.html +0 -16
  154. data/doc/rdoc/classes/RIO/Rio.src/M000055.html +0 -16
  155. data/doc/rdoc/classes/RIO/Rio.src/M000056.html +0 -16
  156. data/doc/rdoc/classes/RIO/Rio.src/M000057.html +0 -16
  157. data/doc/rdoc/classes/RIO/Rio.src/M000058.html +0 -16
  158. data/doc/rdoc/classes/RIO/Rio.src/M000059.html +0 -16
  159. data/doc/rdoc/classes/RIO/Rio.src/M000060.html +0 -16
  160. data/doc/rdoc/classes/RIO/Rio.src/M000061.html +0 -16
  161. data/doc/rdoc/classes/RIO/Rio.src/M000062.html +0 -16
  162. data/doc/rdoc/classes/RIO/Rio.src/M000063.html +0 -16
  163. data/doc/rdoc/classes/RIO/Rio.src/M000064.html +0 -16
  164. data/doc/rdoc/classes/RIO/Rio.src/M000065.html +0 -16
  165. data/doc/rdoc/classes/RIO/Rio.src/M000066.html +0 -16
  166. data/doc/rdoc/classes/RIO/Rio.src/M000067.html +0 -16
  167. data/doc/rdoc/classes/RIO/Rio.src/M000068.html +0 -16
  168. data/doc/rdoc/classes/RIO/Rio.src/M000069.html +0 -16
  169. data/doc/rdoc/classes/RIO/Rio.src/M000070.html +0 -16
  170. data/doc/rdoc/classes/RIO/Rio.src/M000071.html +0 -16
  171. data/doc/rdoc/classes/RIO/Rio.src/M000072.html +0 -16
  172. data/doc/rdoc/classes/RIO/Rio.src/M000073.html +0 -16
  173. data/doc/rdoc/classes/RIO/Rio.src/M000074.html +0 -16
  174. data/doc/rdoc/classes/RIO/Rio.src/M000075.html +0 -16
  175. data/doc/rdoc/classes/RIO/Rio.src/M000076.html +0 -16
  176. data/doc/rdoc/classes/RIO/Rio.src/M000077.html +0 -16
  177. data/doc/rdoc/classes/RIO/Rio.src/M000078.html +0 -16
  178. data/doc/rdoc/classes/RIO/Rio.src/M000079.html +0 -16
  179. data/doc/rdoc/classes/RIO/Rio.src/M000080.html +0 -16
  180. data/doc/rdoc/classes/RIO/Rio.src/M000081.html +0 -16
  181. data/doc/rdoc/classes/RIO/Rio.src/M000082.html +0 -16
  182. data/doc/rdoc/classes/RIO/Rio.src/M000083.html +0 -16
  183. data/doc/rdoc/classes/RIO/Rio.src/M000084.html +0 -16
  184. data/doc/rdoc/classes/RIO/Rio.src/M000085.html +0 -16
  185. data/doc/rdoc/classes/RIO/Rio.src/M000086.html +0 -16
  186. data/doc/rdoc/classes/RIO/Rio.src/M000087.html +0 -16
  187. data/doc/rdoc/classes/RIO/Rio.src/M000088.html +0 -16
  188. data/doc/rdoc/classes/RIO/Rio.src/M000089.html +0 -16
  189. data/doc/rdoc/classes/RIO/Rio.src/M000090.html +0 -16
  190. data/doc/rdoc/classes/RIO/Rio.src/M000091.html +0 -16
  191. data/doc/rdoc/classes/RIO/Rio.src/M000092.html +0 -16
  192. data/doc/rdoc/classes/RIO/Rio.src/M000093.html +0 -16
  193. data/doc/rdoc/classes/RIO/Rio.src/M000094.html +0 -16
  194. data/doc/rdoc/classes/RIO/Rio.src/M000095.html +0 -16
  195. data/doc/rdoc/classes/RIO/Rio.src/M000096.html +0 -16
  196. data/doc/rdoc/classes/RIO/Rio.src/M000097.html +0 -16
  197. data/doc/rdoc/classes/RIO/Rio.src/M000098.html +0 -16
  198. data/doc/rdoc/classes/RIO/Rio.src/M000099.html +0 -16
  199. data/doc/rdoc/classes/RIO/Rio.src/M000100.html +0 -16
  200. data/doc/rdoc/classes/RIO/Rio.src/M000101.html +0 -16
  201. data/doc/rdoc/classes/RIO/Rio.src/M000102.html +0 -16
  202. data/doc/rdoc/classes/RIO/Rio.src/M000103.html +0 -16
  203. data/doc/rdoc/classes/RIO/Rio.src/M000104.html +0 -16
  204. data/doc/rdoc/classes/RIO/Rio.src/M000105.html +0 -16
  205. data/doc/rdoc/classes/RIO/Rio.src/M000106.html +0 -16
  206. data/doc/rdoc/classes/RIO/Rio.src/M000107.html +0 -16
  207. data/doc/rdoc/classes/RIO/Rio.src/M000108.html +0 -16
  208. data/doc/rdoc/classes/RIO/Rio.src/M000109.html +0 -16
  209. data/doc/rdoc/classes/RIO/Rio.src/M000110.html +0 -16
  210. data/doc/rdoc/classes/RIO/Rio.src/M000111.html +0 -16
  211. data/doc/rdoc/classes/RIO/Rio.src/M000112.html +0 -16
  212. data/doc/rdoc/classes/RIO/Rio.src/M000113.html +0 -16
  213. data/doc/rdoc/classes/RIO/Rio.src/M000114.html +0 -16
  214. data/doc/rdoc/classes/RIO/Rio.src/M000115.html +0 -16
  215. data/doc/rdoc/classes/RIO/Rio.src/M000116.html +0 -16
  216. data/doc/rdoc/classes/RIO/Rio.src/M000117.html +0 -16
  217. data/doc/rdoc/classes/RIO/Rio.src/M000118.html +0 -16
  218. data/doc/rdoc/classes/RIO/Rio.src/M000119.html +0 -16
  219. data/doc/rdoc/classes/RIO/Rio.src/M000120.html +0 -16
  220. data/doc/rdoc/classes/RIO/Rio.src/M000121.html +0 -16
  221. data/doc/rdoc/classes/RIO/Rio.src/M000122.html +0 -16
  222. data/doc/rdoc/classes/RIO/Rio.src/M000123.html +0 -16
  223. data/doc/rdoc/classes/RIO/Rio.src/M000124.html +0 -16
  224. data/doc/rdoc/classes/RIO/Rio.src/M000125.html +0 -16
  225. data/doc/rdoc/classes/RIO/Rio.src/M000126.html +0 -16
  226. data/doc/rdoc/classes/RIO/Rio.src/M000127.html +0 -16
  227. data/doc/rdoc/classes/RIO/Rio.src/M000128.html +0 -16
  228. data/doc/rdoc/classes/RIO/Rio.src/M000129.html +0 -16
  229. data/doc/rdoc/classes/RIO/Rio.src/M000130.html +0 -16
  230. data/doc/rdoc/classes/RIO/Rio.src/M000131.html +0 -16
  231. data/doc/rdoc/classes/RIO/Rio.src/M000132.html +0 -16
  232. data/doc/rdoc/classes/RIO/Rio.src/M000133.html +0 -16
  233. data/doc/rdoc/classes/RIO/Rio.src/M000134.html +0 -16
  234. data/doc/rdoc/classes/RIO/Rio.src/M000135.html +0 -16
  235. data/doc/rdoc/classes/RIO/Rio.src/M000136.html +0 -16
  236. data/doc/rdoc/classes/RIO/Rio.src/M000137.html +0 -16
  237. data/doc/rdoc/classes/RIO/Rio.src/M000138.html +0 -16
  238. data/doc/rdoc/classes/RIO/Rio.src/M000139.html +0 -16
  239. data/doc/rdoc/classes/RIO/Rio.src/M000140.html +0 -16
  240. data/doc/rdoc/classes/RIO/Rio.src/M000141.html +0 -16
  241. data/doc/rdoc/classes/RIO/Rio.src/M000142.html +0 -16
  242. data/doc/rdoc/classes/RIO/Rio.src/M000143.html +0 -16
  243. data/doc/rdoc/classes/RIO/Rio.src/M000144.html +0 -16
  244. data/doc/rdoc/classes/RIO/Rio.src/M000145.html +0 -16
  245. data/doc/rdoc/classes/RIO/Rio.src/M000146.html +0 -16
  246. data/doc/rdoc/classes/RIO/Rio.src/M000147.html +0 -16
  247. data/doc/rdoc/classes/RIO/Rio.src/M000148.html +0 -16
  248. data/doc/rdoc/classes/RIO/Rio.src/M000149.html +0 -16
  249. data/doc/rdoc/classes/RIO/Rio.src/M000150.html +0 -16
  250. data/doc/rdoc/classes/RIO/Rio.src/M000151.html +0 -16
  251. data/doc/rdoc/classes/RIO/Rio.src/M000152.html +0 -16
  252. data/doc/rdoc/classes/RIO/Rio.src/M000153.html +0 -16
  253. data/doc/rdoc/classes/RIO/Rio.src/M000154.html +0 -16
  254. data/doc/rdoc/classes/RIO/Rio.src/M000155.html +0 -16
  255. data/doc/rdoc/classes/RIO/Rio.src/M000156.html +0 -16
  256. data/doc/rdoc/classes/RIO/Rio.src/M000157.html +0 -16
  257. data/doc/rdoc/classes/RIO/Rio.src/M000158.html +0 -16
  258. data/doc/rdoc/classes/RIO/Rio.src/M000159.html +0 -16
  259. data/doc/rdoc/classes/RIO/Rio.src/M000160.html +0 -16
  260. data/doc/rdoc/classes/RIO/Rio.src/M000161.html +0 -16
  261. data/doc/rdoc/classes/RIO/Rio.src/M000162.html +0 -16
  262. data/doc/rdoc/classes/RIO/Rio.src/M000163.html +0 -16
  263. data/doc/rdoc/classes/RIO/Rio.src/M000164.html +0 -16
  264. data/doc/rdoc/classes/RIO/Rio.src/M000165.html +0 -16
  265. data/doc/rdoc/classes/RIO/Rio.src/M000166.html +0 -16
  266. data/doc/rdoc/classes/RIO/Rio.src/M000167.html +0 -16
  267. data/doc/rdoc/classes/RIO/Rio.src/M000168.html +0 -16
  268. data/doc/rdoc/classes/RIO/Rio.src/M000169.html +0 -16
  269. data/doc/rdoc/classes/RIO/Rio.src/M000170.html +0 -16
  270. data/doc/rdoc/classes/RIO/Rio.src/M000171.html +0 -16
  271. data/doc/rdoc/classes/RIO/Rio.src/M000172.html +0 -16
  272. data/doc/rdoc/classes/RIO/Rio.src/M000173.html +0 -16
  273. data/doc/rdoc/classes/RIO/Rio.src/M000174.html +0 -16
  274. data/doc/rdoc/classes/RIO/Rio.src/M000175.html +0 -16
  275. data/doc/rdoc/classes/RIO/Rio.src/M000176.html +0 -16
  276. data/doc/rdoc/classes/RIO/Rio.src/M000177.html +0 -16
  277. data/doc/rdoc/classes/RIO/Rio.src/M000178.html +0 -16
  278. data/doc/rdoc/classes/RIO/Rio.src/M000179.html +0 -16
  279. data/doc/rdoc/classes/RIO/Rio.src/M000180.html +0 -16
  280. data/doc/rdoc/classes/RIO/Rio.src/M000181.html +0 -16
  281. data/doc/rdoc/classes/RIO/Rio.src/M000182.html +0 -16
  282. data/doc/rdoc/classes/RIO/Rio.src/M000183.html +0 -16
  283. data/doc/rdoc/classes/RIO/Rio.src/M000184.html +0 -16
  284. data/doc/rdoc/classes/RIO/Rio.src/M000185.html +0 -16
  285. data/doc/rdoc/classes/RIO/Rio.src/M000186.html +0 -16
  286. data/doc/rdoc/classes/RIO/Rio.src/M000187.html +0 -16
  287. data/doc/rdoc/classes/RIO/Rio.src/M000188.html +0 -16
  288. data/doc/rdoc/classes/RIO/Rio.src/M000189.html +0 -16
  289. data/doc/rdoc/classes/RIO/Rio.src/M000190.html +0 -16
  290. data/doc/rdoc/classes/RIO/Rio.src/M000191.html +0 -16
  291. data/doc/rdoc/classes/RIO/Rio.src/M000192.html +0 -16
  292. data/doc/rdoc/classes/RIO/Rio.src/M000193.html +0 -16
  293. data/doc/rdoc/classes/RIO/Rio.src/M000194.html +0 -16
  294. data/doc/rdoc/classes/RIO/Rio.src/M000195.html +0 -16
  295. data/doc/rdoc/classes/RIO/Rio.src/M000196.html +0 -16
  296. data/doc/rdoc/classes/RIO/Rio.src/M000197.html +0 -16
  297. data/doc/rdoc/classes/RIO/Rio.src/M000198.html +0 -16
  298. data/doc/rdoc/classes/RIO/Rio.src/M000199.html +0 -16
  299. data/doc/rdoc/classes/RIO/Rio.src/M000200.html +0 -16
  300. data/doc/rdoc/classes/RIO/Rio.src/M000201.html +0 -16
  301. data/doc/rdoc/classes/RIO/Rio.src/M000202.html +0 -16
  302. data/doc/rdoc/classes/RIO/Rio.src/M000203.html +0 -16
  303. data/doc/rdoc/classes/RIO/Rio.src/M000204.html +0 -16
  304. data/doc/rdoc/classes/RIO/Rio.src/M000205.html +0 -16
  305. data/doc/rdoc/classes/RIO/Rio.src/M000206.html +0 -16
  306. data/doc/rdoc/classes/RIO/Rio.src/M000207.html +0 -16
  307. data/doc/rdoc/classes/RIO/Rio.src/M000208.html +0 -16
  308. data/doc/rdoc/classes/RIO/Rio.src/M000209.html +0 -16
  309. data/doc/rdoc/classes/RIO/Rio.src/M000210.html +0 -16
  310. data/doc/rdoc/classes/RIO/Rio.src/M000211.html +0 -16
  311. data/doc/rdoc/classes/RIO/Rio.src/M000212.html +0 -16
  312. data/doc/rdoc/classes/RIO/Rio.src/M000213.html +0 -16
  313. data/doc/rdoc/created.rid +0 -1
  314. data/doc/rdoc/files/README.html +0 -243
  315. data/doc/rdoc/files/lib/rio/constructor_rb.html +0 -142
  316. data/doc/rdoc/files/lib/rio/doc/HOWTO_rb.html +0 -135
  317. data/doc/rdoc/files/lib/rio/doc/INTRO_rb.html +0 -135
  318. data/doc/rdoc/files/lib/rio/doc/MISC_rb.html +0 -135
  319. data/doc/rdoc/files/lib/rio/doc/SYNOPSIS_rb.html +0 -135
  320. data/doc/rdoc/files/lib/rio/if/basic_rb.html +0 -135
  321. data/doc/rdoc/files/lib/rio/if/csv_rb.html +0 -135
  322. data/doc/rdoc/files/lib/rio/if/dir_rb.html +0 -135
  323. data/doc/rdoc/files/lib/rio/if/file_rb.html +0 -135
  324. data/doc/rdoc/files/lib/rio/if/fileordir_rb.html +0 -135
  325. data/doc/rdoc/files/lib/rio/if/grande_entry_rb.html +0 -135
  326. data/doc/rdoc/files/lib/rio/if/grande_rb.html +0 -135
  327. data/doc/rdoc/files/lib/rio/if/grande_stream_rb.html +0 -135
  328. data/doc/rdoc/files/lib/rio/if/internal_rb.html +0 -135
  329. data/doc/rdoc/files/lib/rio/if/path_rb.html +0 -135
  330. data/doc/rdoc/files/lib/rio/if/stream_rb.html +0 -135
  331. data/doc/rdoc/files/lib/rio/if/string_rb.html +0 -135
  332. data/doc/rdoc/files/lib/rio/if/temp_rb.html +0 -135
  333. data/doc/rdoc/files/lib/rio/if/test_rb.html +0 -135
  334. data/doc/rdoc/files/lib/rio/if/yaml_rb.html +0 -135
  335. data/doc/rdoc/files/lib/rio/kernel_rb.html +0 -142
  336. data/doc/rdoc/files/lib/rio_rb.html +0 -154
  337. data/doc/rdoc/fr_class_index.html +0 -37
  338. data/doc/rdoc/fr_file_index.html +0 -49
  339. data/doc/rdoc/fr_method_index.html +0 -241
  340. data/doc/rdoc/index.html +0 -24
  341. data/doc/rdoc/rdoc-style.css +0 -384
  342. data/test/methods/path.rb +0 -12
@@ -1,1613 +0,0 @@
1
- <?xml version="1.0" encoding="iso-8859-1"?>
2
- <!DOCTYPE html
3
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
-
6
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
- <head>
8
- <title>Module: RIO::Doc::INTRO</title>
9
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
- <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
- <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
12
- <script type="text/javascript">
13
- // <![CDATA[
14
-
15
- function popupCode( url ) {
16
- window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
- }
18
-
19
- function toggleCode( id ) {
20
- if ( document.getElementById )
21
- elem = document.getElementById( id );
22
- else if ( document.all )
23
- elem = eval( "document.all." + id );
24
- else
25
- return false;
26
-
27
- elemStyle = elem.style;
28
-
29
- if ( elemStyle.display != "block" ) {
30
- elemStyle.display = "block"
31
- } else {
32
- elemStyle.display = "none"
33
- }
34
-
35
- return true;
36
- }
37
-
38
- // Make codeblocks hidden by default
39
- document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
-
41
- // ]]>
42
- </script>
43
-
44
- </head>
45
- <body>
46
-
47
-
48
-
49
- <div id="classHeader">
50
- <table class="header-table">
51
- <tr class="top-aligned-row">
52
- <td class="class-mod"><strong>Module</strong></td>
53
- <td class="class-name-in-header">RIO::Doc::INTRO</td>
54
- <td rowspan="2" class="class-header-space-col"></td>
55
- <td rowspan="2">
56
- <a class="in-url" href="../../../files/lib/rio/doc/INTRO_rb.html">
57
- lib/rio/doc/INTRO.rb
58
- </a>
59
- &nbsp;&nbsp;
60
- </td>
61
- </tr>
62
-
63
- </table>
64
- </div>
65
- <!-- banner header -->
66
-
67
- <div id="bodyContent">
68
-
69
-
70
-
71
- <div id="contextContent">
72
-
73
- <div id="description">
74
- <h1><a href="../Rio.html">Rio</a> - Ruby I/O Comfort Class</h1>
75
- <p>
76
- <a href="../Rio.html">Rio</a> is a convenience class wrapping much of the
77
- functionality of IO, File, Dir, Pathname, FileUtils, Tempfile, StringIO,
78
- and OpenURI and uses Zlib, and CSV to extend that functionality using a
79
- simple consistent interface. Most of the instance methods of IO, File and
80
- Dir are simply forwarded to the appropriate handle to provide identical
81
- functionality. <a href="../Rio.html">Rio</a> also provides a
82
- &quot;grande&quot; interface that allows many application level IO tasks to
83
- be accomplished in line or two of code.
84
- </p>
85
- <p>
86
- <a href="../Rio.html">Rio</a> functionality can be broadly broken into
87
- three categories
88
- </p>
89
- <ul>
90
- <li>path manipulation
91
-
92
- </li>
93
- <li>file system access
94
-
95
- </li>
96
- <li>stream manipulation
97
-
98
- </li>
99
- </ul>
100
- <p>
101
- Which methods are available to a given <a href="../Rio.html">Rio</a>,
102
- depends on the underlying object.
103
- </p>
104
- <p>
105
- A <a href="../Rio.html">Rio</a> generally does not need to be opened or
106
- have its mode specified. Most of <a href="../Rio.html">Rio</a>&#8217;s
107
- methods simply configure it. When an actual IO operation is specified, <a
108
- href="../Rio.html">Rio</a> determines how to open it based on the object it
109
- is opening, the operation it is performing, and the options specified.
110
- </p>
111
- <p>
112
- <a href="../Rio.html">Rio</a> configuration methods return the <a
113
- href="../Rio.html">Rio</a> for easy chaining and regard the presence of a
114
- block as an implied <tt>each</tt>.
115
- </p>
116
- <h2>Using a <a href="../Rio.html">Rio</a></h2>
117
- <p>
118
- Using a <a href="../Rio.html">Rio</a> can be described as having 3 steps:
119
- </p>
120
- <ul>
121
- <li>Creating a <a href="../Rio.html">Rio</a> (using the constructor or as the
122
- result of one of the path manipulation methods)
123
-
124
- </li>
125
- <li>Configuring a <a href="../Rio.html">Rio</a>
126
-
127
- </li>
128
- <li><a href="../Rio.html">Rio</a> I/O
129
-
130
- </li>
131
- </ul>
132
- <h3>Creating a <a href="../Rio.html">Rio</a></h3>
133
- <p>
134
- <a href="../Rio.html">Rio</a> extends <a
135
- href="../../Kernel.html">Kernel</a> with one function <tt>rio</tt>, its
136
- constructor. This function is overloaded to create any type of <a
137
- href="../Rio.html">Rio</a>. <tt>rio</tt> looks at the class and sometimes
138
- the value of its first argument to create an internal representation of the
139
- resource specified, additional arguments are used as needed by the resource
140
- type. The rio constructor does not initiate any io, it does not check for a
141
- resources existance or type. It neither knows nor cares what can be done
142
- with this <a href="../Rio.html">Rio</a>. Using methods like
143
- <tt>respond_to?</tt> are meaningless at best and usually misleading.
144
- </p>
145
- <p>
146
- For purposes of discussion, we divide Rios into two catagories, those that
147
- have a path and those that don&#8217;t.
148
- </p>
149
- <h4>Creating a <a href="../Rio.html">Rio</a> that has a path</h4>
150
- <p>
151
- To create a <a href="../Rio.html">Rio</a> that has a path the arguments to
152
- <tt>rio</tt> may be:
153
- </p>
154
- <ul>
155
- <li>a string representing the entire path. The separator used for Rios is as
156
- specified in RFC1738 (&#8217;/&#8217;).
157
-
158
- <pre>
159
- rio('adir/afile')
160
- </pre>
161
- </li>
162
- <li>a string representing a fully qualified <tt>file</tt> URI as per RFC1738
163
-
164
- <pre>
165
- rio('file:///atopleveldir/adir/afile')
166
- </pre>
167
- </li>
168
- <li>a <tt>URI</tt> object representing a <tt>file</tt> or generic <tt>URI</tt>
169
-
170
- <pre>
171
- rio(URI('adir/afile'))
172
- </pre>
173
- </li>
174
- <li>the components of a path as separate arguments
175
-
176
- <pre>
177
- rio('adir','afile')
178
- </pre>
179
- </li>
180
- <li>the components of a path as an array
181
-
182
- <pre>
183
- rio(%w/adir afile/)
184
- </pre>
185
- </li>
186
- <li>another <a href="../Rio.html">Rio</a>
187
-
188
- <pre>
189
- another_rio = rio('adir/afile')
190
- rio(another_rio)
191
- </pre>
192
- </li>
193
- <li>any object whose <tt>to_s</tt> method returns one of the above
194
-
195
- <pre>
196
- rio(Pathname.new('apath'))
197
- </pre>
198
- </li>
199
- <li>any combination of the above either as separate arguments or as elements of
200
- an array,
201
-
202
- <pre>
203
- another_rio = rio('dir1/dir2')
204
- auri = URI('dir4/dir5)
205
- rio(another_rio,'dir3',auri,'dir6/dir7')
206
- </pre>
207
- </li>
208
- </ul>
209
- <h5>Creating a <a href="../Rio.html">Rio</a> that refers to a web page</h5>
210
- <p>
211
- To create a <a href="../Rio.html">Rio</a> that refers to a web page the
212
- arguments to <tt>rio</tt> may be:
213
- </p>
214
- <ul>
215
- <li>a string representing a fully qualified <tt>http</tt> URI
216
-
217
- <pre>
218
- rio('http://ruby-doc.org/index.html')
219
- </pre>
220
- </li>
221
- <li>a <tt>URI</tt> object representing a <tt>http</tt> <tt>URI</tt>
222
-
223
- <pre>
224
- rio(URI('http://ruby-doc.org/index.html'))
225
- </pre>
226
- </li>
227
- <li>either of the above with additional path elements
228
-
229
- <pre>
230
- rio('http://www.ruby-doc.org/','core','classes/Object.html')
231
- </pre>
232
- </li>
233
- </ul>
234
- <h5>Creating a <a href="../Rio.html">Rio</a> that refers to a file or directory on a FTP server</h5>
235
- <p>
236
- To create a <a href="../Rio.html">Rio</a> that refers to a file on a FTP
237
- server the arguments to <tt>rio</tt> may be:
238
- </p>
239
- <ul>
240
- <li>a string representing a fully qualified <tt>ftp</tt> URI
241
-
242
- <pre>
243
- rio('ftp://user:password@ftp.example.com/afile.tar.gz')
244
- </pre>
245
- </li>
246
- <li>a <tt>URI</tt> object representing a <tt>ftp</tt> <tt>URI</tt>
247
-
248
- <pre>
249
- rio(URI('ftp://ftp.example.com/afile.tar.gz'))
250
- </pre>
251
- </li>
252
- <li>either of the above with additional path elements
253
-
254
- <pre>
255
- rio('ftp://ftp.gnu.org/pub/gnu','emacs','windows','README')
256
- </pre>
257
- </li>
258
- </ul>
259
- <h4>Creating Rios that do not have a path</h4>
260
- <p>
261
- To create a <a href="../Rio.html">Rio</a> without a path, the first
262
- argument to <tt>rio</tt> is usually a single character.
263
- </p>
264
- <h5>Creating a <a href="../Rio.html">Rio</a> that refers to a clone of your programs stdin or stdout.</h5>
265
- <p>
266
- <tt>rio(?-)</tt> (mnemonic: &#8217;-&#8217; is used by some Unix programs
267
- to specify stdin or stdout in place of a file)
268
- </p>
269
- <p>
270
- Just as a <a href="../Rio.html">Rio</a> that refers to a file, does not
271
- know whether that file will be opened for reading or writing until an io
272
- operation is specified, a <tt>stdio:</tt> <a href="../Rio.html">Rio</a>
273
- does not know whether it will connect to stdin or stdout until an I/O
274
- operation is specified.
275
- </p>
276
- <h5>Creating a <a href="../Rio.html">Rio</a> that refers to a clone of your programs stderr.</h5>
277
- <p>
278
- <tt>rio(?=)</tt> (mnemonic: &#8217;-&#8217; refers to fileno 1, so
279
- &#8217;=&#8217; refers to fileno 2)
280
- </p>
281
- <h5>Creating a <a href="../Rio.html">Rio</a> that refers to an arbitrary IO object.</h5>
282
- <pre>
283
- an_io = ::File.new('afile')
284
- rio(an_io)
285
- </pre>
286
- <h5>Creating a <a href="../Rio.html">Rio</a> that refers to a file descriptor</h5>
287
- <p>
288
- <tt>rio(?#,fd)</tt> (mnemonic: a file descriptor is a number
289
- &#8217;#&#8217; )
290
- </p>
291
- <pre>
292
- an_io = ::File.new('afile')
293
- rio(an_io)
294
- </pre>
295
- <h5>Creating a <a href="../Rio.html">Rio</a> that refers to a StringIO object</h5>
296
- <p>
297
- <tt>rio(?&quot;)</tt> (mnemonic: &#8217;&quot;&#8217; surrounds strings)
298
- </p>
299
- <ul>
300
- <li>create a <a href="../Rio.html">Rio</a> that refers to its own string
301
-
302
- </li>
303
- </ul>
304
- <pre>
305
- rio(?&quot;)
306
- </pre>
307
- <ul>
308
- <li>create a <a href="../Rio.html">Rio</a> that refers to a string of your
309
- choosing
310
-
311
- </li>
312
- </ul>
313
- <pre>
314
- astring = &quot;&quot;
315
- rio(?&quot;,&quot;&quot;)
316
- </pre>
317
- <h5>Creating a <a href="../Rio.html">Rio</a> that refers to a Temporary object</h5>
318
- <p>
319
- <tt>rio(??)</tt> (mnemonic: &#8217;?&#8217; you don&#8217;t know its name)
320
- </p>
321
- <p>
322
- To create a temporary object that will become a file or a directory,
323
- depending on how you use it:
324
- </p>
325
- <pre>
326
- rio(??)
327
- rio(??,basename='rio',tmpdir=Dir::tmpdir)
328
- </pre>
329
- <p>
330
- To force it to become a file
331
- </p>
332
- <pre>
333
- rio(??).file
334
- </pre>
335
- <p>
336
- or just write to it.
337
- </p>
338
- <p>
339
- To force it to become a directory:
340
- </p>
341
- <pre>
342
- rio(??).dir
343
- </pre>
344
- <p>
345
- or
346
- </p>
347
- <pre>
348
- rio(??).mkdir
349
- </pre>
350
- <p>
351
- or
352
- </p>
353
- <pre>
354
- rio(??).chdir
355
- </pre>
356
- <h5>Creating a <a href="../Rio.html">Rio</a> that refers to an arbitrary TCPSocket</h5>
357
- <pre>
358
- rio('tcp:',hostname,port)
359
- </pre>
360
- <p>
361
- or
362
- </p>
363
- <pre>
364
- rio('tcp://hostname:port')
365
- </pre>
366
- <h5>Creating a <a href="../Rio.html">Rio</a> that runs an external program and connects to its</h5>
367
- <pre>
368
- stdin and stdout
369
- </pre>
370
- <p>
371
- <tt>rio(?-,cmd)</tt> (mnemonic: &#8217;-&#8217; is used by some Unix
372
- programs to specify stdin or stdout in place of a file)
373
- </p>
374
- <p>
375
- or
376
- </p>
377
- <p>
378
- <tt>rio(?`,cmd)</tt> (mnemonic: &#8217;`&#8217; (backtick) runs an external
379
- program in ruby)
380
- </p>
381
- <p>
382
- This is <a href="../Rio.html">Rio</a>&#8217;s interface to IO#popen
383
- </p>
384
- <h3>Path Manipulation</h3>
385
- <p>
386
- <a href="../Rio.html">Rio</a>&#8217;s path manipulation methods are for the
387
- most part simply forwarded to the File or URI classes with the return
388
- values converted to a <a href="../Rio.html">Rio</a>.
389
- </p>
390
- <h4>Creating a <a href="../Rio.html">Rio</a> from a <a href="../Rio.html">Rio</a>&#8217;s component parts.</h4>
391
- <p>
392
- The <a href="../Rio.html">Rio</a> methods for creating a <a
393
- href="../Rio.html">Rio</a> from a <a href="../Rio.html">Rio</a>&#8217;s
394
- component parts are <a href="../Rio.html#M000119">Rio#dirname</a>, <a
395
- href="../Rio.html#M000121">Rio#filename</a>, <a
396
- href="../Rio.html#M000118">Rio#basename</a>, and <a
397
- href="../Rio.html#M000120">Rio#extname</a>. The behavior of <a
398
- href="../Rio.html#M000118">Rio#basename</a> depends on the setting of the
399
- <tt>ext</tt> configuration variable and is different from its counterpart
400
- in the File class. The default value of the <tt>ext</tt> configuration
401
- variable is the string returned File#extname. The <tt>ext</tt>
402
- configuration variable can be changed using <a
403
- href="../Rio.html#M000115">Rio#ext</a> and <a
404
- href="../Rio.html#M000116">Rio#noext</a> and can be queried using <a
405
- href="../Rio.html#M000115">Rio#ext</a>?. This value is used by calls to <a
406
- href="../Rio.html#M000118">Rio#basename</a>.
407
- </p>
408
- <p>
409
- <a href="../Rio.html#M000121">Rio#filename</a> returns the last component
410
- of a path, and is basically the same as <tt>basename</tt> without
411
- consideration of an extension.
412
- </p>
413
- <pre>
414
- rio('afile.txt').basename #=&gt; rio('afile')
415
- rio('afile.txt').filename #=&gt; rio('afile.txt')
416
-
417
- ario = rio('afile.tar.gz')
418
- ario.basename #=&gt; rio('afile.tar')
419
- ario.ext? #=&gt; &quot;.gz&quot;
420
- ario.ext('.tar.gz').basename #=&gt; rio('afile')
421
- ario.ext? #=&gt; &quot;.tar.gz&quot;
422
- </pre>
423
- <h4>Changing a path&#8217;s component parts.</h4>
424
- <p>
425
- <a href="../Rio.html">Rio</a> also provides methods for changing the
426
- component parts of its path. They are <a
427
- href="../Rio.html#M000119">Rio#dirname</a>=, <a
428
- href="../Rio.html#M000121">Rio#filename</a>=, <a
429
- href="../Rio.html#M000118">Rio#basename</a>=, and <a
430
- href="../Rio.html#M000120">Rio#extname</a>=. These methods replace the part
431
- extracted as described above with their argument.
432
- </p>
433
- <pre>
434
- ario = rio('dirA/dirB/afile.rb')
435
- ario.dirname = 'dirC' # rio('dirC/afile.rb')
436
- ario.basename = 'bfile' # rio('dirC/bfile.rb')
437
- ario.extname = '.txt' # rio('dirC/bfile.txt')
438
- ario.filename = 'cfile.rb' # rio('dirC/cfile.rb')
439
- </pre>
440
- <p>
441
- <a href="../Rio.html">Rio</a> also has a <tt>rename</tt> mode which causes
442
- each of these to rename the actual file system object as well as changing
443
- the <a href="../Rio.html">Rio</a>. This is discussed in the section on
444
- Renaming and Moving.
445
- </p>
446
- <h4>Splitting a <a href="../Rio.html">Rio</a></h4>
447
- <p>
448
- <a href="../Rio.html#M000127">Rio#split</a> returns an array of Rios, one
449
- for each path element. (Note that this behavior differs from File#split.)
450
- </p>
451
- <pre>
452
- rio('a/b/c').split #=&gt; [rio('a'),rio('b'),rio('c')]
453
- </pre>
454
- <p>
455
- The array returned is extended wwith a <tt>to_rio</tt> method, which will
456
- put the parts back together again.
457
- </p>
458
- <pre>
459
- ary = rio('a/b/c').split #=&gt; [rio('a'),rio('b'),rio('c')]
460
- ary.to_rio #=&gt; rio('a/b/c')
461
- </pre>
462
- <h4>Creating a <a href="../Rio.html">Rio</a> by specifying the individual parts of its path</h4>
463
- <p>
464
- The first way to create a <a href="../Rio.html">Rio</a> by specifying its
465
- parts is to use the <a href="../Rio.html">Rio</a> constructor <a
466
- href="../Rio.html#M000020">Rio#rio</a>. Since a <a
467
- href="../Rio.html">Rio</a> is among the arguments the constructor will
468
- take, the constructor can be used.
469
- </p>
470
- <pre>
471
- ario = rio('adir')
472
- rio(ario,'b') #=&gt; rio('adir/b')
473
- </pre>
474
- <p>
475
- <a href="../Rio.html#M000126">Rio#join</a> and <a
476
- href="../Rio.html">Rio</a>#/ do the same thing, but the operator version
477
- <tt>/</tt> can take only one argument.
478
- </p>
479
- <pre>
480
- a = rio('a')
481
- b = rio('b')
482
- c = a.join(b) #=&gt; rio('a/b')
483
- c = a/b #=&gt; rio('a/b')
484
- </pre>
485
- <p>
486
- The arguments to <tt>join</tt> and <tt>/</tt> do not need to be Rios, of
487
- course
488
- </p>
489
- <pre>
490
- ario = rio('adir')
491
- ario/'afile.rb' #=&gt; rio('ario/afile.rb')
492
- ario.join('b','c','d') #=&gt; rio('ario/b/c/d')
493
- ario/'b'/'c'/'d' #=&gt; rio('ario/b/c/d')
494
- ario /= 'e' #=&gt; rio('ario/b/c/d/e')
495
- </pre>
496
- <h4>Manipulating a <a href="../Rio.html">Rio</a> path by treating it as a string.</h4>
497
- <p>
498
- The <a href="../Rio.html">Rio</a> methods which treat a <a
499
- href="../Rio.html">Rio</a> as a string are <a
500
- href="../Rio.html#M000130">Rio#sub</a>, <a
501
- href="../Rio.html#M000131">Rio#gsub</a> and <a
502
- href="../Rio.html">Rio</a>#+. These methods create a new <a
503
- href="../Rio.html">Rio</a> using the string created by forwarding the
504
- method to the String returned by <a
505
- href="../Rio.html#M000021">Rio#to_s</a>.
506
- </p>
507
- <pre>
508
- ario = rio('dirA/dirB/afile') + '-1.1.1' # rio('dirA/dirB/afile-1.1.1')
509
- brio = ario.sub(/^dirA/, 'dirC') # rio('dirC/dirB/afile-1.1.1')
510
- </pre>
511
- <h4>Creating a <a href="../Rio.html">Rio</a> based on its relationship to another</h4>
512
- <p>
513
- <a href="../Rio.html#M000112">Rio#abs</a> creates a new rio whose path is
514
- the absolute path of a <a href="../Rio.html">Rio</a>. If provided with an
515
- argument, it uses that as the base path, otherwise it uses an internal base
516
- path (usually the current working directory when it was created).
517
- </p>
518
- <pre>
519
- rio('/tmp').chdir do
520
- rio('a').abs #=&gt; rio('/tmp/a')
521
- rio('a').abs('/usr') #=&gt; rio('/usr/a')
522
- end
523
- </pre>
524
- <p>
525
- <a href="../Rio.html#M000113">Rio#rel</a> creates a new rio with a path
526
- relative to a <a href="../Rio.html">Rio</a>.
527
- </p>
528
- <pre>
529
- rio('/tmp').chdir do
530
- rio('/tmp/a').rel #=&gt; rio('a')
531
- end
532
- rio('/tmp/b').rel('/tmp') #=&gt; rio('b')
533
- </pre>
534
- <p>
535
- <a href="../Rio.html#M000138">Rio#route_to</a> and <a
536
- href="../Rio.html#M000137">Rio#route_from</a> creates a new rio with a path
537
- representing the route to get to/from a <a href="../Rio.html">Rio</a>. They
538
- are based on the methods of the same names in the URI class
539
- </p>
540
- <h3>Configuring a <a href="../Rio.html">Rio</a></h3>
541
- <p>
542
- The second step in using a rio is configuring it. Note that many times no
543
- configuration is necessary and that this is not a comprehensive list of all
544
- of <a href="../Rio.html">Rio</a>&#8217;s configuration methods.
545
- </p>
546
- <p>
547
- <a href="../Rio.html">Rio</a>&#8217;s configuration mehods fall into three
548
- categories.
549
- </p>
550
- <p>
551
- [IO manipulators]
552
- </p>
553
- <pre>
554
- An IO manipulator alters the behavior of a Rio's underlying IO
555
- object. These affect the behaviour of I/O methods which are
556
- forwarded directly to the underlying object as well as the grande
557
- I/O methods.
558
- </pre>
559
- <p>
560
- [Grande configuration methods]
561
- </p>
562
- <pre>
563
- The grande configuration methods affect the behaviour of Rio's
564
- grande I/O methods
565
- </pre>
566
- <p>
567
- [Grande selection methods]
568
- </p>
569
- <pre>
570
- The grande selection methods select what data is returned by Rio's
571
- grande I/O methods
572
- </pre>
573
- <p>
574
- All of <a href="../Rio.html">Rio</a>&#8217;s configuration and selection
575
- methods can be passed a block, which will cause the <a
576
- href="../Rio.html">Rio</a> to behave as if <tt>each</tt> had been called
577
- with the block after the method.
578
- </p>
579
- <h4>IO manipulators</h4>
580
- <ul>
581
- <li><tt>gzip</tt> a file on output, and ungzip it on input
582
-
583
- <pre>
584
- rio('afile.gz').gzip
585
- </pre>
586
- <p>
587
- This causes the rio to read through a Zlib::GzipReader and to write
588
- Zlib::GzipWriter.
589
- </p>
590
- </li>
591
- <li><tt>chomp</tt> lines as they are read
592
-
593
- <pre>
594
- rio('afile').chomp
595
- </pre>
596
- <p>
597
- This causes a <a href="../Rio.html">Rio</a> to call String#chomp on the the
598
- String returned by all line oriented read operations.
599
- </p>
600
- </li>
601
- </ul>
602
- <h4>Grande configuration methods</h4>
603
- <ul>
604
- <li><tt>all</tt>, <tt>recurse</tt>, <tt>norecurse</tt>
605
-
606
- <pre>
607
- rio('adir').all
608
- rio('adir').norecurse('CVS')
609
- </pre>
610
- <p>
611
- These methods instruct the <a href="../Rio.html">Rio</a> to also include
612
- entries in subdirectories when iterating through directories and control
613
- which subdirectories are included or excluded.
614
- </p>
615
- </li>
616
- <li><tt>bytes</tt>
617
-
618
- <pre>
619
- rio('afile').bytes(1024)
620
- </pre>
621
- <p>
622
- This causes a <a href="../Rio.html">Rio</a> to read the specified number of
623
- bytes at a time as a file is iterated through.
624
- </p>
625
- </li>
626
- </ul>
627
- <h4>Grande selection methods</h4>
628
- <ul>
629
- <li><tt>lines</tt>, <tt>skiplines</tt>
630
-
631
- <pre>
632
- rio('afile').lines(0..9)
633
- rio('afile').skiplines(/^\s*#/)
634
- </pre>
635
- <p>
636
- Strictly speaking these are both configuration and selection methods. They
637
- configure the <a href="../Rio.html">Rio</a> to iterate through an input
638
- stream as lines. The arguments select which lines are actually returned.
639
- Lines are included (<tt>lines</tt>) or excluded (<tt>skiplines</tt>) if
640
- they match <b>any</b> of the arguments as follows.
641
- </p>
642
- <p>
643
- If the argument is a:
644
- </p>
645
- <table>
646
- <tr><td valign="top"><tt>RegExp</tt>:</td><td>the line is matched against it
647
-
648
- </td></tr>
649
- <tr><td valign="top"><tt>Range</tt>:</td><td>the lineno is matched against it
650
-
651
- </td></tr>
652
- <tr><td valign="top"><tt>Integer</tt>:</td><td>the lineno is matched against it as if it were a one element range
653
-
654
- </td></tr>
655
- <tr><td valign="top"><tt>Symbol</tt>:</td><td>the symbol is <tt>sent</tt> to the string; the line is included unless it
656
- returns false
657
-
658
- </td></tr>
659
- <tr><td valign="top"><tt>Proc</tt>:</td><td>the proc is called with the line as an argument; the line is included
660
- unless it returns false
661
-
662
- </td></tr>
663
- <tr><td valign="top"><tt>Array</tt>:</td><td>an array containing any of the above, all of which must match for the line
664
- to be included
665
-
666
- </td></tr>
667
- </table>
668
- </li>
669
- <li><tt>entries</tt>, <tt>files</tt>, <tt>dirs</tt>, <tt>skipentries</tt>,
670
- <tt>skipfiles</tt>, <tt>skipdirs</tt>
671
-
672
- <pre>
673
- rio('adir').files('*.txt')
674
- rio('adir').skipfiles(/^\./)
675
- </pre>
676
- <p>
677
- These methods select which entries will be returned when iterating throug
678
- directories. Entries are included
679
- (<tt>entries</tt>,<tt>files</tt>,<tt>dirs</tt>) or
680
- excluded(<tt>skipentries</tt>,<tt>skipfiles</tt>,<tt>skipdirs</tt>) if they
681
- match <b>any</b> of the arguments as follows.
682
- </p>
683
- <p>
684
- If the argument is a:
685
- </p>
686
- <table>
687
- <tr><td valign="top"><tt>String</tt>:</td><td>the arg is treated as a glob; the filname is matched against it
688
-
689
- </td></tr>
690
- <tr><td valign="top"><tt>RegExp</tt>:</td><td>the filname is matched against it
691
-
692
- </td></tr>
693
- <tr><td valign="top"><tt>Symbol</tt>:</td><td>the symbol is <tt>sent</tt> to the entry (a <a href="../Rio.html">Rio</a>);
694
- the entry is included unless it returns false
695
-
696
- </td></tr>
697
- <tr><td valign="top"><tt>Proc</tt>:</td><td>the proc is called with the entry (a <a href="../Rio.html">Rio</a>) as an
698
- argument; the entry is included unless it returns false
699
-
700
- </td></tr>
701
- <tr><td valign="top"><tt>Array</tt>:</td><td>an array containing any of the above, all of which must match for the line
702
- to be included
703
-
704
- </td></tr>
705
- </table>
706
- </li>
707
- <li><tt>records</tt>, <tt>rows</tt>, <tt>skiprecords</tt>, <tt>skiprows</tt>
708
-
709
- <pre>
710
- rio('afile').bytes(1024).records(0...10)
711
- </pre>
712
- <p>
713
- These select items from an input stream just as <tt>lines</tt>, but without
714
- specifying lines as the input record type. They can be used to select
715
- different record types in extension modules. The only such module at this
716
- writing is the CSV extension. In that case <tt>records</tt> causes each
717
- line of a CSV file to be parsed into an array while <tt>lines</tt> causes
718
- each line of the file to be returned normally.
719
- </p>
720
- </li>
721
- </ul>
722
- <h3><a href="../Rio.html">Rio</a> I/O</h3>
723
- <p>
724
- As stated above the the three steps to using a <a
725
- href="../Rio.html">Rio</a> are:
726
- </p>
727
- <ul>
728
- <li>Creating a <a href="../Rio.html">Rio</a>
729
-
730
- </li>
731
- <li>Configuring a <a href="../Rio.html">Rio</a>
732
-
733
- </li>
734
- <li>Doing I/O
735
-
736
- </li>
737
- </ul>
738
- <p>
739
- This section describes that final step.
740
- </p>
741
- <p>
742
- After creating and configuring a <a href="../Rio.html">Rio</a>, the
743
- file-system has not been accessed, no socket has been opened, not so much
744
- as a test for a files existance has been done. When an I/O method is called
745
- on a <a href="../Rio.html">Rio</a>, the sequence of events required to
746
- complete that operation on the underlying object takes place. <a
747
- href="../Rio.html">Rio</a> takes care of creating the apropriate object (eg
748
- IO,Dir), opening the object with the apropriate mode, performing the
749
- operation, closing the object if required, and returning the results of the
750
- operation.
751
- </p>
752
- <p>
753
- <a href="../Rio.html">Rio</a>&#8217;s I/O operations can be divide into two
754
- catagories:
755
- </p>
756
- <ul>
757
- <li>Proxy operations
758
-
759
- </li>
760
- <li>Grande operations
761
-
762
- </li>
763
- </ul>
764
- <h4>Proxy operations</h4>
765
- <p>
766
- These are calls which are forwarded to the underlying object (eg
767
- IO,Dir,Net::FTP), after apropriately creating and configuring that object.
768
- The result produced by the method is returned, and the object is closed.
769
- </p>
770
- <p>
771
- In some cases the result is modified before being returned, as when a <a
772
- href="../Rio.html">Rio</a> is configured with <tt>chomp</tt>.
773
- </p>
774
- <p>
775
- In all cases, if the result returned by the underlying object, could itself
776
- be used for further I/O operations it is returned as a <a
777
- href="../Rio.html">Rio</a>. For example: where File#dirname returns a
778
- string, <a href="../Rio.html#M000119">Rio#dirname</a> returns a <a
779
- href="../Rio.html">Rio</a>; where Dir#read returns a string representing a
780
- directory entry, <a href="../Rio.html#M000045">Rio#read</a> returns a <a
781
- href="../Rio.html">Rio</a>.
782
- </p>
783
- <p>
784
- With some noteable exceptions, most of the operations available if one were
785
- using the underlying Ruby I/O class are available to the <a
786
- href="../Rio.html">Rio</a> and will behave identically.
787
- </p>
788
- <p>
789
- For things that exist on a file system:
790
- </p>
791
- <ul>
792
- <li>All the methods in FileTest are available as <a href="../Rio.html">Rio</a>
793
- instance methods. For example
794
-
795
- <pre>
796
- FileTest.file?('afile')
797
- </pre>
798
- <p>
799
- becomes
800
- </p>
801
- <pre>
802
- rio('afile').file?
803
- </pre>
804
- </li>
805
- <li>All the instance methods of <tt>File</tt> except <tt>path</tt> are
806
- available to a rio without change
807
-
808
- </li>
809
- <li>Most of the class methods of <tt>File</tt> are available.
810
-
811
- <ul>
812
- <li>For those that take a filename as their only argument the calls are mapped
813
- to <a href="../Rio.html">Rio</a> instance methods as described above for
814
- FileTest.
815
-
816
- </li>
817
- <li><tt>dirname</tt>, and <tt>readlink</tt> return Rios instead of strings
818
-
819
- </li>
820
- <li><a href="../Rio.html">Rio</a> has its own <a
821
- href="../Rio.html#M000118">Rio#basename</a>, <a
822
- href="../Rio.html#M000126">Rio#join</a> and <a
823
- href="../Rio.html#M000041">Rio#symlink</a>, which provide similar
824
- functionality.
825
-
826
- </li>
827
- <li>The class methods which take multiple filenames
828
- (<tt>chmod</tt>,<tt>chown</tt>,<tt>lchmod</tt>,<tt>lchown</tt>) are
829
- available as <a href="../Rio.html">Rio</a> instance methods. For example
830
-
831
- <pre>
832
- File.chmod(0666,'afile')
833
- </pre>
834
- <p>
835
- becomes
836
- </p>
837
- <pre>
838
- rio('afile').chmod(06660)
839
- </pre>
840
- </li>
841
- </ul>
842
- </li>
843
- </ul>
844
- <p>
845
- For I/O Streams
846
- </p>
847
- <p>
848
- Most of the instance methods of IO are available, and most do the same
849
- thing, with some interface changes. <b>The big exception to this is the
850
- &#8217;&lt;&lt;&#8217; operator.</b> This is one of <a
851
- href="../Rio.html">Rio</a>&#8217;s grande operators. While the symantics
852
- one would use to write to an IO object would actually accomplish the same
853
- thing with a <a href="../Rio.html">Rio</a>, It is a very different
854
- operator. Read the section on grande operators. The other differences
855
- between IO instance methods and the <a href="../Rio.html">Rio</a>
856
- equivelence can be summarized as follows.
857
- </p>
858
- <ul>
859
- <li>The simple instance methods (eg <tt>fcntl</tt>, <tt>eof?</tt>,
860
- <tt>tty?</tt> etc.) are forwarded and the result returned as is
861
-
862
- </li>
863
- <li>Anywhere IO returns an IO, <a href="../Rio.html">Rio</a> returns a <a
864
- href="../Rio.html">Rio</a>
865
-
866
- </li>
867
- <li><tt>close</tt> and its cousins return the <a href="../Rio.html">Rio</a>.
868
-
869
- </li>
870
- <li><tt>each_byte</tt> and <tt>each_line</tt> are forwarded as is.
871
-
872
- </li>
873
- <li>All methods which read (read*,get*,each*) will cause the file to closed
874
- when the end of file is reached. This behavior is configurable, but the
875
- default is to close on eof
876
-
877
- </li>
878
- <li>The methods which write (put*,print*) are forwarded as is; put* and print*
879
- return the <a href="../Rio.html">Rio</a>; write returns the value returned
880
- by IO#write; as mentioned above &#8217;&lt;&lt;&#8217; is a grande operator
881
- in <a href="../Rio.html">Rio</a>.
882
-
883
- </li>
884
- </ul>
885
- <p>
886
- For directories:
887
- </p>
888
- <ul>
889
- <li>all the instance methods of Dir are available except <tt>each</tt> which is
890
- a grande method.
891
-
892
- </li>
893
- <li>the class methods <tt>mkdir</tt>, <tt>delete</tt>, <tt>rmdir</tt> are
894
- provided as instance methods.
895
-
896
- </li>
897
- <li><tt>chdir</tt> is provided as an instance method. <a
898
- href="../Rio.html#M000031">Rio#chdir</a> returns a <a
899
- href="../Rio.html">Rio</a> and passes a <a href="../Rio.html">Rio</a> to a
900
- block if one is provided.
901
-
902
- </li>
903
- <li><tt>glob</tt> is provided as an instance method, but returns an array of
904
- Rios
905
-
906
- </li>
907
- <li><tt>foreach</tt> is not supported
908
-
909
- </li>
910
- <li><tt>each</tt> and <tt>[]</tt> have similar functionality provided by <a
911
- href="../Rio.html">Rio</a>
912
-
913
- </li>
914
- </ul>
915
- <p>
916
- For other Rios, instance methods are generally forwarded where appropriate.
917
- For example
918
- </p>
919
- <ul>
920
- <li>Rios that refer to StringIO objects forward &#8216;string&#8217; and
921
- &#8216;string=&#8217;
922
-
923
- </li>
924
- <li>Rios that refer to http URIs support all the Meta methods provided by
925
- open-uri
926
-
927
- </li>
928
- </ul>
929
- <h4>Grande operators</h4>
930
- <p>
931
- The primary grande operator is <a href="../Rio.html#M000052">Rio#each</a>.
932
- <tt>each</tt> is used to iterate through Rios. When applied to a file it
933
- iterates through records in the file. When applied to a directory it
934
- iterates through the entries in the directory. Its behavior is modified by
935
- configuring the <a href="../Rio.html">Rio</a> prior to calling it using the
936
- configuration methods discussed above. Since iterating through things is
937
- ubiquitous in ruby, it is implied by the presence of a block after any of
938
- the grande configuration methods and many times does not need to be call
939
- explicitly. For example:
940
- </p>
941
- <pre>
942
- # iterate through chomped ruby comment lines
943
- rio('afile.rb').chomp.lines(/^\s*#/) { |line| ... }
944
-
945
- # iterate through all .rb files in 'adir' and its subdirectories
946
- rio('adir').all.files('*.rb') { |f| ... }
947
- </pre>
948
- <p>
949
- Because a <a href="../Rio.html">Rio</a> is an Enumerable, it supports
950
- <tt>to_a</tt>, which is the basis for the grande subscript operator. <a
951
- href="../Rio.html">Rio</a>#[] with no arguments simply calls to_a. With
952
- arguments it behaves as if those arguments had been passed to the most
953
- recently called of the grande selection methods listed above, and then
954
- calls to_a. For example to get the first ten lines of a file into an array
955
- with lines chomped
956
- </p>
957
- <pre>
958
- rio('afile').chomp.lines(0...10).to_a
959
- </pre>
960
- <p>
961
- can be written as
962
- </p>
963
- <pre>
964
- rio('afile.gz').chomp.lines[0...10]
965
- </pre>
966
- <p>
967
- or, to create an array of all the .c files in a directory, one could write
968
- </p>
969
- <pre>
970
- rio('adir').files['*.c']
971
- </pre>
972
- <p>
973
- The other grande operators are its copy operators. They are:
974
- </p>
975
- <ul>
976
- <li><tt>&lt;</tt> (copy-from)
977
-
978
- </li>
979
- <li><tt>&lt;&lt;</tt> (append-from)
980
-
981
- </li>
982
- <li><tt>&gt;</tt> (copy-to)
983
-
984
- </li>
985
- <li><tt>&gt;&gt;</tt> (append-to)
986
-
987
- </li>
988
- </ul>
989
- <p>
990
- The only difference between the &#8216;copy&#8217; and &#8216;append&#8217;
991
- versions is how they deal with an unopened resource. In the former the open
992
- it with mode &#8216;w&#8217; and in the latter, mode &#8216;a&#8217;.
993
- Beyond that, their behavior can be summarized as:
994
- </p>
995
- <pre>
996
- source.each do |entry|
997
- destination &lt;&lt; entry
998
- end
999
- </pre>
1000
- <p>
1001
- Since they are based on the <tt>each</tt> operator, all of the selection
1002
- and configuration options are available. And the right-hand-side argument
1003
- of the operators are not restricted to Rios &#8212; Strings and Arrays are
1004
- also supported.
1005
- </p>
1006
- <p>
1007
- For example:
1008
- </p>
1009
- <pre>
1010
- rio('afile') &gt; astring # copy a file into a string
1011
-
1012
- rio('afile').chomp &gt; anarray # copy the chomped lines of afile into an array
1013
-
1014
- rio('afile.gz').gzip.lines(0...100) &gt; rio('bfile') # copy 100 lines from a gzipped file into another file
1015
-
1016
- rio(?-) &lt; rio('http://rubydoc.org/') # copy a web page to stdout
1017
-
1018
- rio('bdir') &lt; rio('adir') # copy an entire directory structure
1019
-
1020
- rio('adir').dirs.files('README') &gt; rio('bdir') # same thing, but only README files
1021
-
1022
- rio(?-,'ps -a').skiplines(0,/ps$/) &gt; anarray # copy the output of th ps command into an array, skippying
1023
- # the header line and the ps command entry
1024
- </pre>
1025
- <h3>Renaming and Moving</h3>
1026
- <p>
1027
- <a href="../Rio.html">Rio</a> provides two methods for directly renaming
1028
- objects on the filesystem: <a href="../Rio.html#M000043">Rio#rename</a> and
1029
- <a href="../Rio.html#M000043">Rio#rename</a>!. Both of these use
1030
- File#rename. The difference between them is the returned <a
1031
- href="../Rio.html">Rio</a>. <a href="../Rio.html#M000043">Rio#rename</a>
1032
- leaves the path of the <a href="../Rio.html">Rio</a> unchanged, while <a
1033
- href="../Rio.html#M000043">Rio#rename</a>! changes the path of the <a
1034
- href="../Rio.html">Rio</a> to refer to the renamed path.
1035
- </p>
1036
- <pre>
1037
- ario = rio('a')
1038
- ario.rename('b') # file 'a' has been renamed to 'b' but 'ario' =&gt; rio('a')
1039
- ario.rename!('b') # file 'a' has been renamed to 'b' and 'ario' =&gt; rio('b')
1040
- </pre>
1041
- <p>
1042
- <a href="../Rio.html">Rio</a> also has a <tt>rename</tt> mode, which causes
1043
- the path manipulation methods <a
1044
- href="../Rio.html#M000119">Rio#dirname</a>=, <a
1045
- href="../Rio.html#M000121">Rio#filename</a>=, <a
1046
- href="../Rio.html#M000118">Rio#basename</a>= and <a
1047
- href="../Rio.html#M000120">Rio#extname</a>= to rename an object on the
1048
- filesystem when they are used to change a <a
1049
- href="../Rio.html">Rio</a>&#8217;s path. A <a href="../Rio.html">Rio</a> is
1050
- put in <tt>rename</tt> mode by calling <a
1051
- href="../Rio.html#M000043">Rio#rename</a> with no arguments.
1052
- </p>
1053
- <pre>
1054
- rio('adir/afile.txt').rename.filename = 'bfile.rb' # adir/afile.txt =&gt; adir/bfile.rb
1055
- rio('adir/afile.txt').rename.basename = 'bfile' # adir/afile.txt =&gt; adir/bfile.txt
1056
- rio('adir/afile.txt').rename.extname = '.rb' # adir/afile.txt =&gt; adir/afile.rb
1057
- rio('adir/afile.txt').rename.dirname = 'b/c' # adir/afile.txt =&gt; b/c/afile.txt
1058
- </pre>
1059
- <p>
1060
- When <tt>rename</tt> mode is set for a directory <a
1061
- href="../Rio.html">Rio</a>, it is automatically set in the Rios created
1062
- when iterating through that directory.
1063
- </p>
1064
- <pre>
1065
- rio('adir').rename.files('*.htm') do |frio|
1066
- frio.extname = '.html' #=&gt; changes the rio and renames the file
1067
- end
1068
- </pre>
1069
- <h3>Deleting</h3>
1070
- <p>
1071
- The <a href="../Rio.html">Rio</a> methods for deleting filesystem objects
1072
- are <a href="../Rio.html#M000038">Rio#rm</a>, <a
1073
- href="../Rio.html#M000034">Rio#rmdir</a>, <a
1074
- href="../Rio.html#M000035">Rio#rmtree</a>, <a
1075
- href="../Rio.html#M000053">Rio#delete</a>, and <a
1076
- href="../Rio.html#M000053">Rio#delete</a>!. <tt>rm</tt>, <tt>rmdir</tt> and
1077
- <tt>rmtree</tt> are passed the like named methods in the FileUtils module.
1078
- <a href="../Rio.html#M000053">Rio#delete</a> calls <tt>rmdir</tt> for
1079
- directories and <tt>rm</tt> for anything else, while <a
1080
- href="../Rio.html#M000053">Rio#delete</a>! calls <a
1081
- href="../Rio.html#M000035">Rio#rmtree</a> for directories.
1082
- </p>
1083
- <ul>
1084
- <li>To delete something only if it is not a directory use <a
1085
- href="../Rio.html#M000038">Rio#rm</a>
1086
-
1087
- </li>
1088
- <li>To delete an empty directory use <a
1089
- href="../Rio.html#M000034">Rio#rmdir</a>
1090
-
1091
- </li>
1092
- <li>To delete an entire directory tree use <a
1093
- href="../Rio.html#M000035">Rio#rmtree</a>
1094
-
1095
- </li>
1096
- <li>To delete anything except a populated directory use <a
1097
- href="../Rio.html#M000053">Rio#delete</a>
1098
-
1099
- </li>
1100
- <li>To delete anything use <a href="../Rio.html#M000053">Rio#delete</a>!
1101
-
1102
- </li>
1103
- </ul>
1104
- <p>
1105
- It is not an error to call any of the deleting methods on something that
1106
- does not exist. <a href="../Rio.html">Rio</a> provides Rio#exist? and <a
1107
- href="../Rio.html#M000041">Rio#symlink</a>? to check if something exists
1108
- (<tt>exist?</tt> returns false for symlinks to non-existant object even
1109
- though the symlink itself exists). The deleting methods&#8217; purpose is
1110
- to make things not exist, so calling one of them on something that already
1111
- does not exist is considered a success.
1112
- </p>
1113
- <p>
1114
- To create a clean copy of a directory whether or not anything with that
1115
- name exists one might do this
1116
- </p>
1117
- <pre>
1118
- rio('adir').delete!.mkpath.chdir do
1119
- # do something in adir
1120
- end
1121
- </pre>
1122
- <hr size="1"></hr><h2>Miscellany</h2>
1123
- <h4>Using Symbolic Links</h4>
1124
- <p>
1125
- To create a symbolic link (symlink) to the file-system entry refered to by
1126
- a <a href="../Rio.html">Rio</a>, use <a
1127
- href="../Rio.html#M000041">Rio#symlink</a>. <a
1128
- href="../Rio.html#M000041">Rio#symlink</a> differs from File#symlink in
1129
- that it calculates the path from the symlink location to the <a
1130
- href="../Rio.html">Rio</a>&#8217;s position.
1131
- </p>
1132
- <pre>
1133
- File#symlink('adir/afile','adir/alink')
1134
- </pre>
1135
- <p>
1136
- creates a symlink in the directory &#8216;adir&#8217; named
1137
- &#8216;alink&#8217; which references &#8216;adir/afile&#8217;. From the
1138
- perspective of &#8216;alink&#8217;, &#8216;adir/afile&#8217; does not
1139
- exist. While:
1140
- </p>
1141
- <pre>
1142
- rio('adir/afile').symlink('adir/alink')
1143
- </pre>
1144
- <p>
1145
- creates a symlink in the directory &#8216;adir&#8217; named
1146
- &#8216;alink&#8217; which references &#8216;afile&#8217;. This is the route
1147
- to &#8216;adir/afile&#8217; from the perspective of
1148
- &#8216;adir/alink&#8217;.
1149
- </p>
1150
- <p>
1151
- Note that the return value from <tt>symlink</tt> is the calling <a
1152
- href="../Rio.html">Rio</a> and not a <a href="../Rio.html">Rio</a> refering
1153
- to the symlink. This is done for consistency with the rest of <a
1154
- href="../Rio.html">Rio</a>.
1155
- </p>
1156
- <p>
1157
- <a href="../Rio.html#M000041">Rio#symlink</a>? can be used to test if a
1158
- file-system object is a symlink. A <a href="../Rio.html">Rio</a> is
1159
- extended with <a href="../Rio.html#M000042">Rio#readlink</a>, and <a
1160
- href="../Rio.html#M000191">Rio#lstat</a> only if <a
1161
- href="../Rio.html#M000041">Rio#symlink</a>? returns true. So for
1162
- non-symlinks, these will raise a NoMethodError. These are both passed to
1163
- their counterparts in File. <a href="../Rio.html#M000042">Rio#readlink</a>
1164
- returns a <a href="../Rio.html">Rio</a> refering to the result of
1165
- File#readlink.
1166
- </p>
1167
- <h4>Using A <a href="../Rio.html">Rio</a> as an IO (or File or Dir)</h4>
1168
- <p>
1169
- <a href="../Rio.html">Rio</a> supports so much of IO&#8217;s interface that
1170
- one might be tempted to pass it to a method that expects an IO. While <a
1171
- href="../Rio.html">Rio</a> is not and is not intended to be a stand in for
1172
- IO, this can work. It requires knowledge of every IO method that will be
1173
- called, under any circumstances.
1174
- </p>
1175
- <p>
1176
- Even in cases where <a href="../Rio.html">Rio</a> supports the required IO
1177
- interface, A <a href="../Rio.html">Rio</a> feature that seems to cause the
1178
- most incompatibility, is its automatic closing of files. To turn off all of
1179
- <a href="../Rio.html">Rio</a>&#8217;s automatic closing use
1180
- Rio#noautoclose.
1181
- </p>
1182
- <p>
1183
- For example:
1184
- </p>
1185
- <pre>
1186
- require 'yaml'
1187
- yrio = rio('ran.yaml').delete!.noautoclose
1188
- YAML.dump( ['badger', 'elephant', 'tiger'], yrio )
1189
- obj = YAML::load( yrio ) #=&gt; [&quot;badger&quot;, &quot;tiger&quot;, &quot;elephant&quot;]
1190
- </pre>
1191
- <h4>Automatically Closing Files</h4>
1192
- <p>
1193
- <a href="../Rio.html">Rio</a> closes files automatically in three
1194
- instances.
1195
- </p>
1196
- <p>
1197
- When reading from an IO it is closed when the end of file is reached. While
1198
- this is a reasonable thing to do in many cases, sometimes this is not
1199
- desired. To turn <a href="../Rio.html">Rio</a>&#8217;s automatic closing on
1200
- end of file use <a href="../Rio.html#M000094">Rio#nocloseoneof</a> (it can
1201
- be turned back on via <a href="../Rio.html#M000093">Rio#closeoneof</a>)
1202
- </p>
1203
- <pre>
1204
- ario = rio('afile').nocloseoneof
1205
- lines = ario[]
1206
- ario.closed? #=&gt; false
1207
- </pre>
1208
- <p>
1209
- Closing on end-of-file is necessary for many of <a
1210
- href="../Rio.html">Rio</a>&#8217;s one-liners, but has an implication that
1211
- may be surprising at first. A <a href="../Rio.html">Rio</a> starts life as
1212
- a path, not much more than a string. When one of its read methods is called
1213
- it becomes an input stream. When the stream is closed, it becomes a path
1214
- again. This means that when reading from a <a href="../Rio.html">Rio</a>,
1215
- the end-of-file condition is seen only once before it becomes a path again,
1216
- and will be reopened if another read operation is attempted.
1217
- </p>
1218
- <p>
1219
- Another time a <a href="../Rio.html">Rio</a> will be closed atomatically is
1220
- when writing to it with one of the copy operators (<tt>&lt;, &lt;&lt;,
1221
- &gt;, &gt;&gt;</tt>). This behavior can be turned off with <a
1222
- href="../Rio.html#M000097">Rio#nocloseoncopy</a>.
1223
- </p>
1224
- <p>
1225
- To turn off both of thes types of automatic closing use Rio#noautoclose.
1226
- </p>
1227
- <p>
1228
- The third instance when <a href="../Rio.html">Rio</a> will close a file
1229
- automatically is when a file opened for one type of access receives a
1230
- method which that access mode does not support. So, the code
1231
- rio(&#8216;afile&#8217;).puts(&quot;Hello World&quot;).gets will open the
1232
- file for write access when the <tt>puts</tt> method is received. When
1233
- <tt>gets</tt> is called the file is closed and reopened with read access.
1234
- </p>
1235
- <h4>Explicitly Closing Files</h4>
1236
- <p>
1237
- <a href="../Rio.html">Rio</a> can not determine when the client is finished
1238
- writing to it, as it does using <tt>eof</tt> on read. It is the
1239
- author&#8217;s understanding that Ruby does not support a mechanism to have
1240
- code run when there are no more references to it &#8212; that finalizers
1241
- are not necessarily run immediatly upon an object&#8217;s reference count
1242
- reaching 0. If this understanding is incorrect, some of <a
1243
- href="../Rio.html">Rio</a>&#8217;s extranious ways of closing a file may be
1244
- rethought.
1245
- </p>
1246
- <p>
1247
- That being said, <a href="../Rio.html">Rio</a> support several ways to
1248
- explicitly close a file. <a href="../Rio.html#M000167">Rio#close</a> will
1249
- close any open <a href="../Rio.html">Rio</a>. The output methods <a
1250
- href="../Rio.html#M000158">Rio#puts</a>!, <a
1251
- href="../Rio.html#M000157">Rio#putc</a>!, <a
1252
- href="../Rio.html#M000155">Rio#printf</a>!, <a
1253
- href="../Rio.html#M000152">Rio#print</a>!, and <a
1254
- href="../Rio.html#M000161">Rio#write</a>! behave as if their counterparts
1255
- without the exclamation point had been called and then call <a
1256
- href="../Rio.html#M000167">Rio#close</a> or Rio#close_write if the
1257
- underlying IO object is opened for duplex access.
1258
- </p>
1259
- <h4>Open mode selection</h4>
1260
- <p>
1261
- A <a href="../Rio.html">Rio</a> is typically not explicitly opened. It
1262
- opens a file automatically when an input or output methed is called. For
1263
- output methods <a href="../Rio.html">Rio</a> opens a file with mode
1264
- &#8216;w&#8217;, and otherwise opens a file with mode &#8216;r&#8217;. This
1265
- behavior can be modified using the tersely named methods <a
1266
- href="../Rio.html#M000087">Rio#a</a>, <a
1267
- href="../Rio.html#M000087">Rio#a</a>!, <a
1268
- href="../Rio.html#M000089">Rio#r</a>, <a
1269
- href="../Rio.html#M000089">Rio#r</a>!, <a
1270
- href="../Rio.html#M000091">Rio#w</a>, and <a
1271
- href="../Rio.html#M000091">Rio#w</a>!, which cause the <a
1272
- href="../Rio.html">Rio</a> to use modes
1273
- &#8216;a&#8217;,&#8217;a+&#8217;,&#8217;r&#8217;,&#8217;r+&#8217;,&#8217;w&#8217;,and
1274
- &#8216;w+&#8217; respectively.
1275
- </p>
1276
- <p>
1277
- One way to append a string to a file and close it in one line is
1278
- </p>
1279
- <pre>
1280
- rio('afile').a.puts!(&quot;Hello World&quot;)
1281
- </pre>
1282
- <p>
1283
- Run a cmd that must be opened for read and write
1284
- </p>
1285
- <pre>
1286
- ans = rio(?-,'cat').w!.puts!(&quot;Hello Kitty&quot;).readlines
1287
- </pre>
1288
- <p>
1289
- The automatic selection of mode can be bypassed entirely using <a
1290
- href="../Rio.html#M000165">Rio#mode</a> and <a
1291
- href="../Rio.html#M000040">Rio#open</a>.
1292
- </p>
1293
- <p>
1294
- If a mode is specified using <tt>mode</tt>, the file will still be opened
1295
- automatically, but the mode specified in the <tt>mode</tt> method will be
1296
- used regardless of whether it makes sense.
1297
- </p>
1298
- <p>
1299
- A <a href="../Rio.html">Rio</a> can also be opened explicitly using <a
1300
- href="../Rio.html#M000040">Rio#open</a>. <tt>open</tt> takes one parameter,
1301
- a mode. This also will override all of <a
1302
- href="../Rio.html">Rio</a>&#8217;s automatic mode selection.
1303
- </p>
1304
- <h4>CSV mode</h4>
1305
- <p>
1306
- <a href="../Rio.html">Rio</a> uses the CSV class from the Ruby standard
1307
- library to provide support for reading and writing comma-separated-value
1308
- files. Normally using <tt>(no)records</tt> is identical to
1309
- <tt>(no)lines</tt> because while <tt>records</tt> only selects and does not
1310
- specify the record-type, <tt>lines</tt> is the default.
1311
- </p>
1312
- <pre>
1313
- rio('afile').records(1..2)
1314
- </pre>
1315
- <p>
1316
- effectively means
1317
- </p>
1318
- <pre>
1319
- rio('afile').lines.records(1..2)
1320
- </pre>
1321
- <p>
1322
- The CSV extension distingishes between items selected using <a
1323
- href="../Rio.html#M000082">Rio#records</a> and those selected using <a
1324
- href="../Rio.html#M000080">Rio#lines</a>. <a href="../Rio.html">Rio</a>
1325
- returns records parsed into Arrays by the CSV library when <tt>records</tt>
1326
- is used, and returns Strings as normal when <tt>lines</tt> is used.
1327
- <tt>records</tt> is the default.
1328
- </p>
1329
- <pre>
1330
- rio('f.csv').puts!([&quot;h0,h1&quot;,&quot;f0,f1&quot;])
1331
-
1332
- rio('f.csv').csv.records[] #==&gt;[[&quot;h0&quot;, &quot;h1&quot;], [&quot;f0&quot;, &quot;f1&quot;]]
1333
- rio('f.csv').csv[] #==&gt; same thing
1334
- rio('f.csv').csv.lines[] #==&gt;[&quot;h0,h1\n&quot;, &quot;f0,f1\n&quot;]
1335
- rio('f.csv').csv.records[0] #==&gt;[[&quot;h0&quot;, &quot;h1&quot;]]
1336
- rio('f.csv').csv[0] #==&gt; same thing
1337
- rio('f.csv').csv.lines[0] #==&gt;[&quot;h0,h1\n&quot;]
1338
- rio('f.csv').csv.skiprecords[0] #==&gt;[[&quot;f0&quot;, &quot;f1&quot;]]
1339
- rio('f.csv').csv.skiplines[0] #==&gt;[&quot;f0,f1\n&quot;]
1340
- </pre>
1341
- <p>
1342
- This distinction, of course, applies equally when using the copy operators
1343
- and <tt>each</tt>
1344
- </p>
1345
- <pre>
1346
- rio('f.csv').csv[0] &gt; rio('out').csv # out contains &quot;f0,f1\n&quot;
1347
-
1348
- rio('f.csv').csv { |array_of_fields| ... }
1349
- </pre>
1350
- <p>
1351
- Notice that <tt>csv</tt> mode is called on both the input and output Rios.
1352
- The <tt>csv</tt> on the &#8216;out&#8217; <a href="../Rio.html">Rio</a>
1353
- causes it to treat an array written to it as an array of records which is
1354
- converted into CSV format before writing. Without the <tt>csv</tt>, the
1355
- output would be written as if Array#to_s on
1356
- [[&quot;f0&quot;,&quot;f1&quot;]] had been called
1357
- </p>
1358
- <pre>
1359
- rio('f.csv').csv[0] &gt; rio('out') # out contains &quot;f0f1&quot;
1360
- </pre>
1361
- <p>
1362
- The String representing a record that is returned when using <tt>lines</tt>
1363
- is extended with a <tt>to_a</tt> method which will parse it into an array
1364
- of fields. Likewise the Array returned when a record is returned using
1365
- <tt>records</tt> is extended with a modified <tt>to_s</tt> which treats it
1366
- as an array CSV fields, rather than just an array of strings.
1367
- </p>
1368
- <pre>
1369
- array_of_lines = rio('f.csv').csv.lines[1] #==&gt;[&quot;f0,f1\n&quot;]
1370
- array_of_records = rio('f.csv').csv.records[1] #==&gt;[[&quot;f0&quot;, &quot;f1&quot;]]
1371
-
1372
- array_of_lines[0].to_a #==&gt;[&quot;f0&quot;, &quot;f1&quot;]
1373
- array_of_records[0].to_s #==&gt;&quot;f0,f1&quot;
1374
- </pre>
1375
- <p>
1376
- Rio#csv takes two optional parameters, which are passed on to the CSV
1377
- library. They are the <tt>field_separator</tt> and the
1378
- <tt>record_separator</tt>.
1379
- </p>
1380
- <pre>
1381
- rio('semisep').puts!([&quot;h0;h1&quot;,&quot;f0;f1&quot;])
1382
-
1383
- rio('semisep').csv(';').to_a #==&gt;[[&quot;h0&quot;, &quot;h1&quot;], [&quot;f0&quot;, &quot;f1&quot;]]
1384
- </pre>
1385
- <p>
1386
- These are specified independently on the source and destination when using
1387
- the copy operators.
1388
- </p>
1389
- <pre>
1390
- rio('semisep').csv(';') &gt; rio('colonsep').csv(':')
1391
- rio('colonsep').contents #==&gt;&quot;h0:h1\nf0:f1\n&quot;
1392
- </pre>
1393
- <p>
1394
- <a href="../Rio.html">Rio</a> provides two methods for selecting fields
1395
- from CSV records in a manner similar to that provided for selecting lines
1396
- &#8212; Rio#columns and Rio#skipcolumns.
1397
- </p>
1398
- <pre>
1399
- rio('f.csv').puts!([&quot;h0,h1,h2,h3&quot;,&quot;f0,f1,f2,f3&quot;])
1400
-
1401
- rio('f.csv').csv.columns(0).to_a #==&gt;[[&quot;h0&quot;], [&quot;f0&quot;]]
1402
- rio('f.csv').csv.skipcolumns(0).to_a #==&gt;[[&quot;h1&quot;, &quot;h2&quot;, &quot;h3&quot;], [&quot;f1&quot;, &quot;f2&quot;, &quot;f3&quot;]]
1403
- rio('f.csv').csv.columns(1..2).to_a #==&gt;[[&quot;h1&quot;, &quot;h2&quot;], [&quot;f1&quot;, &quot;f2&quot;]]
1404
- rio('f.csv').csv.skipcolumns(1..2).to_a #==&gt;[[&quot;h0&quot;, &quot;h3&quot;], [&quot;f0&quot;, &quot;f3&quot;]]
1405
- </pre>
1406
- <p>
1407
- Rio#columns can, of course be used with the <tt>each</tt> and the copy
1408
- operators:
1409
- </p>
1410
- <pre>
1411
- rio('f.csv').csv.columns(0..1) &gt; rio('out').csv
1412
- rio('out').contents #==&gt;&quot;h0,h1\nf0,f1\n&quot;
1413
- </pre>
1414
- <h4>YAML mode</h4>
1415
- <p>
1416
- <a href="../Rio.html">Rio</a> uses the YAML class from the Ruby standard
1417
- library to provide support for reading and writing YAML files. Normally
1418
- using <tt>(skip)records</tt> is identical to <tt>(skip)lines</tt> because
1419
- while <tt>records</tt> only selects and does not specify the record-type,
1420
- <tt>lines</tt> is the default.
1421
- </p>
1422
- <p>
1423
- The YAML extension distingishes between items selected using <a
1424
- href="../Rio.html#M000082">Rio#records</a>, <a
1425
- href="../Rio.html#M000085">Rio#rows</a> and <a
1426
- href="../Rio.html#M000080">Rio#lines</a>. <a href="../Rio.html">Rio</a>
1427
- returns objects loaded via YAML#load when <tt>records</tt> is used; returns
1428
- the YAML text as a String when <tt>rows</tt> is used; and returns lines as
1429
- Strings as normal when <tt>lines</tt> is used. <tt>records</tt> is the
1430
- default. In yaml-mode, <tt>(skip)records</tt> can be called as
1431
- <tt>(skip)objects</tt> and <tt>(skip)rows</tt> can be called as
1432
- <tt>(skip)documents</tt>
1433
- </p>
1434
- <p>
1435
- To read a single YAML document, <a href="../Rio.html">Rio</a> provides
1436
- getobj and load For example, consider the following partial
1437
- &#8216;database.yml&#8217; from the rails distribution:
1438
- </p>
1439
- <pre>
1440
- development:
1441
- adapter: mysql
1442
- database: rails_development
1443
-
1444
- test:
1445
- adapter: mysql
1446
- database: rails_test
1447
- </pre>
1448
- <p>
1449
- To get the object represented in the yaml file:
1450
- </p>
1451
- <pre>
1452
- rio('database.yml').yaml.load
1453
- ==&gt;{&quot;development&quot;=&gt;{&quot;adapter&quot;=&gt;&quot;mysql&quot;, &quot;database&quot;=&gt;&quot;rails_development&quot;},
1454
- &quot;test&quot;=&gt;{&quot;adapter&quot;=&gt;&quot;mysql&quot;, &quot;database&quot;=&gt;&quot;rails_test&quot;}}
1455
- </pre>
1456
- <p>
1457
- Or one could read parts of the file like so:
1458
- </p>
1459
- <pre>
1460
- rio('database.yml').yaml.getobj['development']['database']
1461
- ==&gt;&quot;rails_development&quot;
1462
- </pre>
1463
- <p>
1464
- Single objects can be written using putobj and putobj! which is aliased to
1465
- dump
1466
- </p>
1467
- <pre>
1468
- anobject = {
1469
- 'production' =&gt; {
1470
- 'adapter' =&gt; 'mysql',
1471
- 'database' =&gt; 'rails_production',
1472
- }
1473
- }
1474
- rio('afile.yaml').yaml.dump(anobject)
1475
- </pre>
1476
- <p>
1477
- The YAML extension changes the way the grande copy operators interpret
1478
- their argument. <a href="../Rio.html">Rio</a>#&lt; (copy-from) and <a
1479
- href="../Rio.html">Rio</a>#&lt;&lt; (append-from) treat an array as an
1480
- array of objects which are converted using their to_yaml method before
1481
- writing.
1482
- </p>
1483
- <pre>
1484
- rio('afile.yaml').yaml &lt; [obj1, obj2, obj3]
1485
- </pre>
1486
- <p>
1487
- Because of this, copying an ::Array must be done like this:
1488
- </p>
1489
- <pre>
1490
- rio('afile.yaml').yaml &lt; [anarray]
1491
- </pre>
1492
- <p>
1493
- If their argument is a <a href="../Rio.html">Rio</a> or ::IO it is iterate
1494
- through as normal, with each record converted using its to_yaml method.
1495
- </p>
1496
- <p>
1497
- For all other objects, the result of their <tt>to_yaml</tt> operator is
1498
- simply written.
1499
- </p>
1500
- <pre>
1501
- rio('afile.yaml').yaml &lt; anobject
1502
- </pre>
1503
- <p>
1504
- <a href="../Rio.html">Rio</a>#&gt; (copy-to) and <a
1505
- href="../Rio.html">Rio</a>#&gt;&gt; (append-to) will fill an array with
1506
- with all selected YAML documents in the <a href="../Rio.html">Rio</a>. For
1507
- non-arrays, the yaml text is copied. (This may change if a useful
1508
- reasonable alternative can be found)
1509
- </p>
1510
- <pre>
1511
- rio('afile.yaml').yaml &gt; anarray # load all YAML documents from 'afile.yaml'
1512
- </pre>
1513
- <p>
1514
- Single objects can be written using <a
1515
- href="../Rio.html#M000068">Rio#putrec</a> (aliased to Rio#putobj and
1516
- Rio#dump)
1517
- </p>
1518
- <pre>
1519
- rio('afile.yaml').yaml.putobj(anobject)
1520
- </pre>
1521
- <p>
1522
- Single objects can be loaded using <a
1523
- href="../Rio.html#M000064">Rio#getrec</a> (aliase to Rio#getobj and
1524
- Rio#load)
1525
- </p>
1526
- <pre>
1527
- anobject = rio('afile.yaml').yaml.getobj
1528
- </pre>
1529
- <p>
1530
- Note that other than this redefinition of what a record is and how the copy
1531
- operators interpret their argument, a <a href="../Rio.html">Rio</a> in
1532
- yaml-mode is just like any other <a href="../Rio.html">Rio</a>. And all the
1533
- things you can do with any <a href="../Rio.html">Rio</a> come for free.
1534
- They can be iterated over using each and read into an array using #[] just
1535
- like any other <a href="../Rio.html">Rio</a>. All the selection criteria
1536
- are identical also.
1537
- </p>
1538
- <p>
1539
- Get the first three objects into an array:
1540
- </p>
1541
- <pre>
1542
- array_of_objects = rio('afile.yaml').yaml[0..2]
1543
- </pre>
1544
- <p>
1545
- Iterate over only YAML documents that are a kind_of ::Hash use:
1546
- </p>
1547
- <pre>
1548
- rio('afile.yaml').yaml(::Hash) {|ahash| ...}
1549
- </pre>
1550
- <p>
1551
- This takes advantage of the fact that the default for matching records is
1552
- <tt>===</tt>
1553
- </p>
1554
- <p>
1555
- Selecting records using a Proc can be used as normal:
1556
- </p>
1557
- <pre>
1558
- anarray = rio('afile.yaml').yaml(proc{|anobject| ...}).to_a
1559
- </pre>
1560
- <p>
1561
- One could even use the copy operator to convert a CSV file to a YAML
1562
- representation of the same data:
1563
- </p>
1564
- <pre>
1565
- rio('afile.yaml').yaml &lt; rio('afile.csv').csv
1566
- </pre>
1567
- <hr size="1"></hr><p>
1568
- See also:
1569
- </p>
1570
- <ul>
1571
- <li><a href="SYNOPSIS.html">RIO::Doc::SYNOPSIS</a>
1572
-
1573
- </li>
1574
- <li><a href="HOWTO.html">RIO::Doc::HOWTO</a>
1575
-
1576
- </li>
1577
- <li><a href="../Rio.html">RIO::Rio</a>
1578
-
1579
- </li>
1580
- </ul>
1581
-
1582
- </div>
1583
-
1584
-
1585
- </div>
1586
-
1587
-
1588
- </div>
1589
-
1590
-
1591
- <!-- if includes -->
1592
-
1593
- <div id="section">
1594
-
1595
-
1596
-
1597
-
1598
-
1599
-
1600
-
1601
-
1602
- <!-- if method_list -->
1603
-
1604
-
1605
- </div>
1606
-
1607
-
1608
- <div id="validator-badges">
1609
- <p><small>Copyright &copy; 2005 Christopher Kleckner. <a href="http://www.gnu.org/licenses/gpl.html">All rights reserved</a>.</small></p>
1610
- </div>
1611
-
1612
- </body>
1613
- </html>