rio 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +140 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/doc/ANNOUNCE +87 -0
- data/doc/RELEASE_NOTES +7 -0
- data/doc/rdoc/classes/Kernel.html +9 -9
- data/doc/rdoc/classes/Kernel.src/{M000183.html → M000182.html} +0 -0
- data/doc/rdoc/classes/RIO.html +35 -0
- data/doc/rdoc/classes/RIO.src/M000001.html +4 -4
- data/doc/rdoc/classes/RIO.src/M000002.html +4 -4
- data/doc/rdoc/classes/RIO.src/M000003.html +4 -4
- data/doc/rdoc/classes/RIO/Doc/HOWTO.html +11 -7
- data/doc/rdoc/classes/RIO/Doc/INTRO.html +255 -36
- data/doc/rdoc/classes/RIO/Doc/SYNOPSIS.html +47 -17
- data/doc/rdoc/classes/RIO/Rio.html +1032 -1007
- data/doc/rdoc/classes/RIO/Rio.src/M000011.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000012.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000013.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000014.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000015.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000016.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000017.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000018.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000019.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000020.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000021.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000022.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000023.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000024.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000025.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000026.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000027.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000028.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000029.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000030.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000031.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000032.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000033.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000034.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000035.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000036.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000037.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000038.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000039.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000040.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000041.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000042.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000043.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000044.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000045.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000046.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000047.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000048.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000049.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000050.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000051.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000052.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000053.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000054.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000055.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000056.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000057.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000058.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000059.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000060.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000061.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000062.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000063.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000064.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000065.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000066.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000067.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000068.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000069.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000070.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000071.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000072.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000073.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000074.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000075.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000076.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000077.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000078.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000079.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000080.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000081.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000082.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000083.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000084.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000085.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000086.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000087.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000088.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000089.html +2 -2
- data/doc/rdoc/classes/RIO/Rio.src/M000090.html +2 -2
- data/doc/rdoc/classes/RIO/Rio.src/M000091.html +2 -2
- data/doc/rdoc/classes/RIO/Rio.src/M000092.html +2 -2
- data/doc/rdoc/classes/RIO/Rio.src/M000093.html +2 -2
- data/doc/rdoc/classes/RIO/Rio.src/M000094.html +2 -2
- data/doc/rdoc/classes/RIO/Rio.src/M000095.html +2 -2
- data/doc/rdoc/classes/RIO/Rio.src/M000096.html +2 -2
- data/doc/rdoc/classes/RIO/Rio.src/M000097.html +2 -2
- data/doc/rdoc/classes/RIO/Rio.src/M000098.html +2 -2
- data/doc/rdoc/classes/RIO/Rio.src/M000099.html +2 -2
- data/doc/rdoc/classes/RIO/Rio.src/M000100.html +2 -2
- data/doc/rdoc/classes/RIO/Rio.src/M000101.html +2 -2
- data/doc/rdoc/classes/RIO/Rio.src/M000102.html +2 -2
- data/doc/rdoc/classes/RIO/Rio.src/M000103.html +2 -2
- data/doc/rdoc/classes/RIO/Rio.src/M000104.html +2 -2
- data/doc/rdoc/classes/RIO/Rio.src/M000105.html +2 -2
- data/doc/rdoc/classes/RIO/Rio.src/M000106.html +2 -2
- data/doc/rdoc/classes/RIO/Rio.src/M000107.html +2 -2
- data/doc/rdoc/classes/RIO/Rio.src/M000108.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000109.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000110.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000111.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000112.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000113.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000114.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000115.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000116.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000117.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000118.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000119.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000120.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000121.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000122.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000123.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000124.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000125.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000126.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000127.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000128.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000129.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000130.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000131.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000132.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000133.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000134.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000135.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000136.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000137.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000138.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000139.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000140.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000141.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000142.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000143.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000144.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000145.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000146.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000147.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000148.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000149.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000150.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000151.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000152.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000153.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000154.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000155.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000156.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000157.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000158.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000159.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000160.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000161.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000162.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000163.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000164.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000165.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000166.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000167.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000168.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000169.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000170.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000171.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000172.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000173.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000174.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000175.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000176.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000177.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000178.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000179.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000180.html +3 -3
- data/doc/rdoc/classes/RIO/Rio.src/M000181.html +3 -3
- data/doc/rdoc/created.rid +1 -1
- data/doc/rdoc/files/lib/rio/constructor_rb.html +1 -1
- data/doc/rdoc/files/lib/rio/doc/HOWTO_rb.html +1 -1
- data/doc/rdoc/files/lib/rio/doc/INTRO_rb.html +1 -1
- data/doc/rdoc/files/lib/rio/doc/SYNOPSIS_rb.html +1 -1
- data/doc/rdoc/files/lib/rio/if/basic_rb.html +1 -1
- data/doc/rdoc/files/lib/rio/if/path_rb.html +1 -1
- data/doc/rdoc/files/lib/rio_rb.html +1 -1
- data/doc/rdoc/fr_method_index.html +154 -155
- data/ex/findinruby +7 -3
- data/ex/findruby +6 -2
- data/lib/rio.rb +1 -1
- data/lib/rio/argv.rb +4 -0
- data/lib/rio/constructor.rb +17 -0
- data/lib/rio/context.rb +1 -1
- data/lib/rio/context/dir.rb +1 -0
- data/lib/rio/context/methods.rb +3 -3
- data/lib/rio/dir.rb +2 -2
- data/lib/rio/doc/HOWTO.rb +11 -6
- data/lib/rio/doc/INTRO.rb +149 -12
- data/lib/rio/doc/SYNOPSIS.rb +26 -13
- data/lib/rio/factory.rb +13 -2
- data/lib/rio/grande.rb +25 -0
- data/lib/rio/if/basic.rb +1 -1
- data/lib/rio/if/path.rb +61 -35
- data/lib/rio/matchrecord.rb +20 -1
- data/lib/rio/ops/dir.rb +2 -3
- data/lib/rio/ops/path.rb +25 -11
- data/lib/rio/ops/stream/input.rb +6 -3
- data/lib/rio/rl/base.rb +3 -2
- data/lib/rio/rl/ioi.rb +2 -1
- data/lib/rio/rl/path.rb +18 -3
- data/lib/rio/rl/uri.rb +8 -4
- data/lib/rio/scheme/cmdio.rb +1 -1
- data/lib/rio/scheme/path.rb +1 -0
- data/lib/rio/scheme/stdio.rb +1 -1
- data/lib/rio/scheme/strio.rb +1 -1
- data/lib/rio/scheme/sysio.rb +1 -1
- data/lib/rio/scheme/tcp.rb +1 -0
- data/lib/rio/scheme/temp.rb +184 -0
- data/lib/rio/state.rb +17 -6
- data/lib/rio/stream.rb +1 -1
- data/lib/rio/stream/open.rb +1 -1
- data/lib/rio/tempdir.rb +132 -0
- data/lib/rio/version.rb +1 -1
- data/test/tc/all.rb +4 -0
- data/test/tc/copylines.rb +38 -32
- data/test/tc/riorl.rb +104 -0
- data/test/tc/temp.rb +155 -0
- data/test/tc/tempdir.rb +63 -0
- data/test/tc/tempfile.rb +38 -0
- metadata +10 -5
- data/doc/rdoc/classes/RIO/Rio.src/M000182.html +0 -16
- data/lib/rio/scheme/tempfile.rb +0 -104
data/ex/findinruby
CHANGED
@@ -1,16 +1,20 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'rio'
|
4
|
+
require 'rio/argv'
|
4
5
|
|
5
6
|
re = ARGV.shift
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
8
|
+
is_ruby_exe = proc{ |f| f.executable? and f[0][0] =~ /^#!.+ruby/ }
|
9
|
+
|
10
|
+
RIO.ARGV.each do |rpath|
|
11
|
+
rpath.norecurse('.svn','pkg').files('*.rb',is_ruby_exe) do |f|
|
10
12
|
print f.lines[/#{re}/].map{ |line| "#{f}: #{line}" }
|
11
13
|
end
|
14
|
+
|
12
15
|
end
|
13
16
|
__END__
|
17
|
+
|
14
18
|
ARGV.each do |path|
|
15
19
|
rio(path).norecurse('.svn','pkg').files('*.rb',proc{ |f| f.executable? and f[0] =~ /^#!.+ruby/ }) do |f|
|
16
20
|
print f.lines[/#{re}/].map{ |line| "#{f}: #{line}" }
|
data/ex/findruby
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require 'rio'
|
4
|
+
require 'rio/argv'
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
#is_ruby_exe = proc{ |f| f.executable? and f[0][0] =~ /^#!.+ruby/ }
|
7
|
+
is_ruby_exe = proc{ |f| f.executable? and f.gets =~ /^#!.+ruby/ }
|
8
|
+
|
9
|
+
RIO.ARGV.each do |rpath|
|
10
|
+
rpath.norecurse('.svn','pkg').files('*.rb',is_ruby_exe) do |f|
|
7
11
|
puts f
|
8
12
|
end
|
9
13
|
end
|
data/lib/rio.rb
CHANGED
data/lib/rio/argv.rb
CHANGED
data/lib/rio/constructor.rb
CHANGED
@@ -135,6 +135,23 @@ module RIO
|
|
135
135
|
# rio(??)
|
136
136
|
# rio(??,basename='rio',tmpdir=Dir::tmpdir)
|
137
137
|
#
|
138
|
+
# To create a temporary object that will become a file
|
139
|
+
# or a directory, depending on how you use it:
|
140
|
+
# rio(??)
|
141
|
+
# rio(??,basename='rio',tmpdir=Dir::tmpdir)
|
142
|
+
#
|
143
|
+
# To force it to become a file
|
144
|
+
# rio(??).file
|
145
|
+
# or just write to it.
|
146
|
+
#
|
147
|
+
# To force it to become a directory:
|
148
|
+
# rio(??).dir
|
149
|
+
# or
|
150
|
+
# rio(??).mkdir
|
151
|
+
# or
|
152
|
+
# rio(??).chdir
|
153
|
+
#
|
154
|
+
#
|
138
155
|
# ===== Creating a Rio that refers to an arbitrary TCPSocket
|
139
156
|
#
|
140
157
|
# rio('tcp:',hostname,port)
|
data/lib/rio/context.rb
CHANGED
data/lib/rio/context/dir.rb
CHANGED
data/lib/rio/context/methods.rb
CHANGED
@@ -85,13 +85,13 @@ module RIO
|
|
85
85
|
|
86
86
|
module Cx
|
87
87
|
module Methods
|
88
|
-
def
|
88
|
+
def noautoclose(arg=false,&block)
|
89
89
|
closeoncopy(arg).closeoneof(arg,&block)
|
90
90
|
end
|
91
|
-
def
|
91
|
+
def noautoclose_(arg=false)
|
92
92
|
closeoncopy_(arg).closeoneof_(arg)
|
93
93
|
end
|
94
|
-
protected :
|
94
|
+
protected :noautoclose_
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
data/lib/rio/dir.rb
CHANGED
data/lib/rio/doc/HOWTO.rb
CHANGED
@@ -103,7 +103,7 @@ IO, File, Dir, Pathname, FileUtils, Tempfile, StringIO, OpenURI, Zlib, and CSV.
|
|
103
103
|
|
104
104
|
* Read all lines starting with 'require' into an array, with each line chomped
|
105
105
|
# method 1
|
106
|
-
array = ario.chomp.lines
|
106
|
+
array = ario.chomp.lines[/^\s*require/]
|
107
107
|
# method 2
|
108
108
|
ario.chomp.lines(/^\s*require/) > array
|
109
109
|
|
@@ -173,7 +173,7 @@ IO, File, Dir, Pathname, FileUtils, Tempfile, StringIO, OpenURI, Zlib, and CSV.
|
|
173
173
|
# method 2
|
174
174
|
ario.print(string)
|
175
175
|
# method 3
|
176
|
-
ario.
|
176
|
+
ario.noautoclose < string
|
177
177
|
|
178
178
|
* Write a string to a file and close the file
|
179
179
|
# method 1
|
@@ -189,7 +189,7 @@ IO, File, Dir, Pathname, FileUtils, Tempfile, StringIO, OpenURI, Zlib, and CSV.
|
|
189
189
|
# method 2
|
190
190
|
ario.a.print(string)
|
191
191
|
# method 3
|
192
|
-
ario.
|
192
|
+
ario.noautoclose << string
|
193
193
|
|
194
194
|
* Append a string to a file and close the file
|
195
195
|
# method 1
|
@@ -204,7 +204,7 @@ IO, File, Dir, Pathname, FileUtils, Tempfile, StringIO, OpenURI, Zlib, and CSV.
|
|
204
204
|
ario = rio('afile').nocloseoncopy
|
205
205
|
ario << array
|
206
206
|
# method 2
|
207
|
-
ario.
|
207
|
+
ario.noautoclose < array
|
208
208
|
|
209
209
|
* Write an array to a file and close the file
|
210
210
|
# method 1
|
@@ -302,9 +302,14 @@ IO, File, Dir, Pathname, FileUtils, Tempfile, StringIO, OpenURI, Zlib, and CSV.
|
|
302
302
|
# method 5
|
303
303
|
array = ario.norecurse('.svn')['*.txt']
|
304
304
|
|
305
|
-
* Iterate through
|
305
|
+
* Iterate through ruby files in a directory and subdirectories skipping
|
306
|
+
those in the '.svn', and 'pkg' directories
|
306
307
|
# method 1
|
307
|
-
|
308
|
+
is_ruby_exe = proc{ |f| f.executable? and f[0][0] =~ /^#!.+ruby/ }
|
309
|
+
ario.norecurse('.svn','pkg').files('*.rb',is_ruby_exe) { |f| ... }
|
310
|
+
# method 2
|
311
|
+
is_ruby_exe = proc{ |f| f.executable? and f.gets =~ /^#!.+ruby/ }
|
312
|
+
ario.norecurse('.svn','pkg').files('*.rb',is_ruby_exe) { |f| ... }
|
308
313
|
|
309
314
|
* Put all files excluding those that are symlinks to files in an array
|
310
315
|
# method 1
|
data/lib/rio/doc/INTRO.rb
CHANGED
@@ -67,7 +67,7 @@ as an implied +each+.
|
|
67
67
|
== Using a Rio
|
68
68
|
|
69
69
|
Using a Rio can be described as having 3 steps:
|
70
|
-
* Creating a Rio (using the constructor or as the result of one of path manipulation methods)
|
70
|
+
* Creating a Rio (using the constructor or as the result of one of the path manipulation methods)
|
71
71
|
* Configuring a Rio
|
72
72
|
* Rio I/O
|
73
73
|
|
@@ -139,8 +139,8 @@ character.
|
|
139
139
|
<tt>rio(?-)</tt> (mnemonic: '-' is used by some Unix programs to specify stdin or stdout in place of a file)
|
140
140
|
|
141
141
|
Just as a Rio that refers to a file, does not know whether that file will be opened for reading or
|
142
|
-
writing until an io operation is specified, a
|
143
|
-
to stdin or stdout until an
|
142
|
+
writing until an io operation is specified, a <tt>stdio:</tt> Rio does not know whether it will connect
|
143
|
+
to stdin or stdout until an I/O operation is specified.
|
144
144
|
|
145
145
|
===== Creating a Rio that refers to a clone of your programs stderr.
|
146
146
|
|
@@ -167,12 +167,28 @@ to stdin or stdout until an io operation is specified.
|
|
167
167
|
astring = ""
|
168
168
|
rio(?","")
|
169
169
|
|
170
|
-
===== Creating a Rio that refers to a
|
170
|
+
===== Creating a Rio that refers to a Temporary object
|
171
171
|
|
172
172
|
<tt>rio(??)</tt> (mnemonic: '?' you don't know its name)
|
173
|
+
|
174
|
+
To create a temporary object that will become a file
|
175
|
+
or a directory, depending on how you use it:
|
173
176
|
rio(??)
|
174
177
|
rio(??,basename='rio',tmpdir=Dir::tmpdir)
|
175
178
|
|
179
|
+
To force it to become a file
|
180
|
+
rio(??).file
|
181
|
+
or just write to it.
|
182
|
+
|
183
|
+
To force it to become a directory:
|
184
|
+
rio(??).dir
|
185
|
+
or
|
186
|
+
rio(??).mkdir
|
187
|
+
or
|
188
|
+
rio(??).chdir
|
189
|
+
|
190
|
+
|
191
|
+
|
176
192
|
===== Creating a Rio that refers to an arbitrary TCPSocket
|
177
193
|
|
178
194
|
rio('tcp:',hostname,port)
|
@@ -196,10 +212,10 @@ the return values converted to a Rio.
|
|
196
212
|
|
197
213
|
==== Creating a Rio from a Rio's component parts.
|
198
214
|
|
199
|
-
The Rio methods for creating a Rio from a Rio's component parts are
|
200
|
-
Rio#filename, Rio#basename,
|
201
|
-
|
202
|
-
|
215
|
+
The Rio methods for creating a Rio from a Rio's component parts are
|
216
|
+
Rio#dirname, Rio#filename, Rio#basename, and Rio#extname.
|
217
|
+
The behavior of Rio#basename depends on the setting of the +ext+
|
218
|
+
configuration variable
|
203
219
|
and is different from its counterpart in the File class. The default value of the +ext+ configuration variable
|
204
220
|
is the string returned File#extname. The +ext+ configuration variable can be changed using Rio#ext and Rio#noext
|
205
221
|
and can be queried using Rio#ext?. This value is used by calls to Rio#basename.
|
@@ -562,10 +578,131 @@ symlinks to non-existant object even though the symlink itself exists).
|
|
562
578
|
The deleting methods' purpose is to make things not exist, so
|
563
579
|
calling one of them on something that already does not exist is considered a success.
|
564
580
|
|
565
|
-
To create a clean copy of a directory whether or not anything with that name exists
|
566
|
-
|
567
|
-
|
568
|
-
|
581
|
+
To create a clean copy of a directory whether or not anything with that name exists one might do this
|
582
|
+
rio('adir').delete!.mkpath.chdir do
|
583
|
+
# do something in adir
|
584
|
+
end
|
585
|
+
|
586
|
+
---
|
587
|
+
|
588
|
+
== Miscellany
|
589
|
+
|
590
|
+
|
591
|
+
==== Using Symbolic Links
|
592
|
+
|
593
|
+
To create a symbolic link (symlink) to the file-system entry refered to by a Rio, use Rio#symlink.
|
594
|
+
Rio#symlink differs from File#symlink in that it calculates the path from the symlink location to
|
595
|
+
the Rio's position. So:
|
596
|
+
|
597
|
+
File#symlink('adir/afile','adir/alink')
|
598
|
+
|
599
|
+
creates a symlink in the directory 'adir' named 'alink' which references 'adir/afile'. From the
|
600
|
+
perspective of 'alink', 'adir/afile' does not exist. While:
|
601
|
+
|
602
|
+
rio('adir/afile').symlink('adir/alink')
|
603
|
+
|
604
|
+
creates a symlink in the directory 'adir' named 'alink' which references 'afile'. This is the route
|
605
|
+
to 'adir/afile' from the perspective of 'adir/alink'.
|
606
|
+
|
607
|
+
Note that the return value from +symlink+ is the calling Rio and not a Rio refering to the symlink.
|
608
|
+
This is done for consistency with the rest of Rio.
|
609
|
+
|
610
|
+
Rio#symlink? can be used to test if a file-system object is a symlink. A Rio is extended with
|
611
|
+
Rio#readlink, and Rio#lstat only if Rio#symlink? returns true. So for non-symlinks, these
|
612
|
+
will raise a NoMethodError. These are both passed to their counterparts in File. Rio#readlink
|
613
|
+
returns a Rio refering to the result of File#readlink.
|
614
|
+
|
615
|
+
==== Using A Rio as an IO (or File or Dir)
|
616
|
+
|
617
|
+
Rio supports so much of IO's interface that one might be tempted to pass it to a method that
|
618
|
+
expects an IO. While Rio is not and is not intended to be a stand in for IO, this can work.
|
619
|
+
It requires knowledge of every IO method that will be called, under any circumstances.
|
620
|
+
|
621
|
+
Even in cases where Rio supports the required IO interface, A Rio feature that seems to
|
622
|
+
cause the most incompatibility, is its automatic closing of files. To turn off all of Rio's
|
623
|
+
automatic closing use Rio#noautoclose.
|
624
|
+
|
625
|
+
For example:
|
626
|
+
require 'yaml'
|
627
|
+
yrio = rio('ran.yaml').delete!.noautoclose
|
628
|
+
YAML.dump( ['badger', 'elephant', 'tiger'], yrio )
|
629
|
+
obj = YAML::load( yrio ) #=> ["badger", "tiger", "elephant"]
|
630
|
+
|
631
|
+
==== Automatic Closing of Files
|
632
|
+
|
633
|
+
Rio closes files automatically in three instances.
|
634
|
+
|
635
|
+
When reading from an IO it is closed when the end of file is reached. While
|
636
|
+
this is a reasonable thing to do in many cases, sometimes this is not desired.
|
637
|
+
To turn Rio's automatic closing on end of file use Rio#nocloseoneof (it can
|
638
|
+
be turned back on via Rio#closeoneof)
|
639
|
+
|
640
|
+
ario = rio('afile').nocloseoneof
|
641
|
+
lines = ario[]
|
642
|
+
ario.closed? #=> false
|
643
|
+
|
644
|
+
Closing on end-of-file is necessary for many of Rio's "one-liners", but has an
|
645
|
+
implication that may be surprising at first. A Rio starts life as a path, not
|
646
|
+
much more than a string. When one of its read methods is called it becomes an
|
647
|
+
input stream. When the stream is closed, it becomes a path again. This means
|
648
|
+
that when reading from a Rio, the end-of-file condition is seen only once before it
|
649
|
+
becomes a path again, and will be reopened if another read operation is attempted.
|
650
|
+
|
651
|
+
Another time a Rio will be closed atomatically is when writing to it with one
|
652
|
+
of the copy operators (<tt><, <<, >, >></tt>).
|
653
|
+
This behavior can be turned off with Rio#nocloseoncopy.
|
654
|
+
|
655
|
+
To turn off both of thes types of automatic closing use Rio#noautoclose.
|
656
|
+
|
657
|
+
The third instance when Rio will close a file automatically is when a file opened
|
658
|
+
for one type of access receives a method which that access mode does not support.
|
659
|
+
So, the code
|
660
|
+
rio('afile').puts("Hello World").gets
|
661
|
+
will open the file for write access when the +puts+ method is received. When +gets+ is
|
662
|
+
called the file is closed and reopened with read access.
|
663
|
+
|
664
|
+
==== Explicit Closing of Files
|
665
|
+
|
666
|
+
Rio can not determine when the client is finished writing to it, as it does
|
667
|
+
using +eof+ on read. It is the author's understanding that Ruby does not support
|
668
|
+
a mechanism to have code run when there are no more references to it -- that finalizers
|
669
|
+
are not necessarily run immediatly upon an object's reference count reaching 0.
|
670
|
+
If this understanding is incorrect, some of Rio's extranious ways of closing a file
|
671
|
+
may be rethought.
|
672
|
+
|
673
|
+
That being said, Rio support several ways to explicitly close a file. Rio#close will close
|
674
|
+
any open Rio. The output methods Rio#puts!, Rio#putc!, Rio#printf!, Rio#print!, and Rio#write!
|
675
|
+
behave as if their counterparts without the exclamation point had been called and
|
676
|
+
then call Rio#close or Rio#close_write if the underlying IO object is opened for duplex access.
|
677
|
+
|
678
|
+
|
679
|
+
==== Open mode selection
|
680
|
+
|
681
|
+
A Rio is typically not explicitly opened. It opens a file automatically when an
|
682
|
+
input or output methed is called. For output methods Rio opens a file with mode 'w',
|
683
|
+
and otherwise opens a file with mode 'r'. This behavior can be modified using the
|
684
|
+
tersely named methods Rio#a, Rio#a!, Rio#r, Rio#r!, Rio#w, and Rio#w!, which cause
|
685
|
+
the Rio to use modes 'a','a+','r','r+','w',and 'w+' respectively.
|
686
|
+
|
687
|
+
One way to append a string to a file and close it in one line is
|
688
|
+
rio('afile').a.puts!("Hello World")
|
689
|
+
|
690
|
+
Run a cmd that must be opened for read and write
|
691
|
+
ans = rio(?-,'cat').w!.puts!("Hello Kitty").readlines
|
692
|
+
|
693
|
+
The automatic selection of mode can be bypassed entirely using Rio#mode and Rio#open.
|
694
|
+
|
695
|
+
If a mode is specified using +mode+, the file will still be opened automatically, but
|
696
|
+
the mode specified in the +mode+ method will be used regardless of whether it makes sense.
|
697
|
+
|
698
|
+
A Rio can also be opened explicitly using Rio#open. +open+ takes one parameter, a mode.
|
699
|
+
This also will override all of Rio's automatic mode selection.
|
700
|
+
|
701
|
+
|
702
|
+
|
703
|
+
|
704
|
+
---
|
705
|
+
|
569
706
|
|
570
707
|
See also:
|
571
708
|
* RIO::Doc::SYNOPSIS
|
data/lib/rio/doc/SYNOPSIS.rb
CHANGED
@@ -63,6 +63,9 @@ For the following assume:
|
|
63
63
|
Copy a file into a string
|
64
64
|
rio('afile') > astring
|
65
65
|
|
66
|
+
Copy a string into a file
|
67
|
+
rio('afile') < astring
|
68
|
+
|
66
69
|
Copy the chomped lines of a file into an array
|
67
70
|
rio('afile').chomp > anarray
|
68
71
|
|
@@ -78,18 +81,18 @@ Copy an entire directory structure into another directory
|
|
78
81
|
Copy a web page into a file
|
79
82
|
rio('http://rubydoc.org/') > rio('afile')
|
80
83
|
|
81
|
-
Copy a file from a ftp server into a file
|
84
|
+
Copy a file from a ftp server into a local file
|
82
85
|
rio('ftp://host/afile.gz') > rio('afile.gz')
|
83
86
|
|
84
87
|
Copy a gzipped file un-gzipping it
|
85
88
|
rio('afile.gz').gzip > rio('afile')
|
86
89
|
|
87
|
-
Copy a file from a ftp server into a local file un-gzipping it
|
88
|
-
rio('ftp://host/afile.gz').gzip > rio('afile')
|
89
|
-
|
90
90
|
Copy a plain file, gzipping it
|
91
91
|
rio('afile.gz').gzip < rio('afile')
|
92
92
|
|
93
|
+
Copy a file from a ftp server into a local file un-gzipping it
|
94
|
+
rio('ftp://host/afile.gz').gzip > rio('afile')
|
95
|
+
|
93
96
|
Iterate over the entries in a directory
|
94
97
|
rio('adir').entries { |entrio| ... }
|
95
98
|
|
@@ -99,6 +102,15 @@ Iterate over only the files in a directory
|
|
99
102
|
Iterate over only the .rb files in a directory
|
100
103
|
rio('adir').files('*.rb') { |entrio| ... }
|
101
104
|
|
105
|
+
Iterate over only the directories in a directory
|
106
|
+
rio('adir').dirs { |entrio| ... }
|
107
|
+
|
108
|
+
Iterate over only the _dot_ files in a directory
|
109
|
+
rio('adir').dirs(/^\./) { |entrio| ... }
|
110
|
+
|
111
|
+
Iterate over the files in a directory and its subdirectories, skipping '.svn' and 'CVS' directories
|
112
|
+
rio('adir').norecurse(/^\.svn$/,'CVS').files { |entrio| ... }
|
113
|
+
|
102
114
|
Create an array of the .rb entries in a directory
|
103
115
|
anarray = rio('adir')['*.rb']
|
104
116
|
|
@@ -111,8 +123,7 @@ Create an array of the .rb entries in a directory and its subdirectories
|
|
111
123
|
Create an array of the .rb files in a directory and its subdirectories
|
112
124
|
anarray = rio('adir').all.files['*.rb']
|
113
125
|
|
114
|
-
Copy an entire directory structure
|
115
|
-
into another directory
|
126
|
+
Copy an entire directory structure and the .rb files within it
|
116
127
|
rio('adir').dirs.files('*.rb') > rio('another_directory')
|
117
128
|
|
118
129
|
Iterate over the chomped lines of a file
|
@@ -133,14 +144,17 @@ Copy the first 10 lines of a file into another file
|
|
133
144
|
Copy the first 10 lines of a file to stdout
|
134
145
|
rio('afile').lines(0..9) > rio(?-)
|
135
146
|
|
136
|
-
Copy the first 10 lines of a gzipped file to stdout
|
137
|
-
rio('afile.gz').gzip.lines(0..9) > rio(?-)
|
138
|
-
|
139
147
|
Copy the first 10 lines of a gzipped file on an ftp server to stdout
|
140
148
|
rio('ftp://host/afile.gz').gzip.lines(0..9) > rio(?-)
|
141
149
|
|
142
150
|
Put the first 100 chomped lines of a gzipped file into an array
|
143
|
-
anarray = rio('afile.gz').gzip[0...100]
|
151
|
+
anarray = rio('afile.gz').chomp.gzip[0...100]
|
152
|
+
|
153
|
+
Put chomped lines that start with 'Rio' into an array
|
154
|
+
anarray = rio('afile').chomp[/^Rio/]
|
155
|
+
|
156
|
+
Iterate over the non-empty, non-comment chomped lines of a file
|
157
|
+
rio('afile').chomp.nolines(:empty?,/^\s*#/) { |line| ... }
|
144
158
|
|
145
159
|
Copy the output of th ps command into an array, skipping the header line and the ps command entry
|
146
160
|
rio(?-,'ps -a').nolines(0,/ps$/) > anarray
|
@@ -148,14 +162,13 @@ Copy the output of th ps command into an array, skipping the header line and the
|
|
148
162
|
Prompt for input and return what was typed
|
149
163
|
ans = rio(?-).print("Type Something: ").chomp.gets
|
150
164
|
|
151
|
-
Change the extension of all
|
152
|
-
subdirectories to have the extension '.html'
|
165
|
+
Change the extension of all .htm files in a directory and its subdirectories to .html
|
153
166
|
rio('adir').rename.all.files('*.htm') do |htmfile|
|
154
167
|
htmfile.extname = '.html'
|
155
168
|
end
|
156
169
|
|
157
170
|
Create a symbolic link 'asymlink' in 'adir' which refers to 'adir/afile'
|
158
|
-
rio('adir/afile').
|
171
|
+
rio('adir/afile').symlink('adir/asymlink')
|
159
172
|
|
160
173
|
=== SUGGESTED READING
|
161
174
|
|