rio 0.3.8 → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README +18 -12
- data/Rakefile +57 -87
- data/build_doc.rb +19 -17
- data/doc/ANNOUNCE +3 -32
- data/doc/RELEASE_NOTES +4 -5
- data/doc/RIOIS +215 -0
- data/doc/generators/template/html/rio.css +428 -0
- data/doc/generators/template/html/rio.rb +18 -389
- data/doc/generators/template/html/ugly.rb +130 -0
- data/doc/pkg_def.rb +66 -0
- data/ex/catcsv.rb +64 -0
- data/ex/colx.rb +8 -0
- data/ex/findinruby +15 -0
- data/ex/findruby +14 -0
- data/ex/passwd_report.rb +8 -0
- data/ex/prompt.rb +25 -0
- data/ex/rgb.txt.gz +0 -0
- data/ex/riocat +42 -0
- data/ex/riogunzip +31 -0
- data/ex/riogzip +24 -0
- data/ex/rioprompt.rb +10 -0
- data/ex/targz2zip +17 -0
- data/ex/tonl +10 -0
- data/lib/rio.rb +16 -10
- data/lib/rio/abstract_method.rb +3 -4
- data/lib/rio/argv.rb +3 -4
- data/lib/rio/arycopy.rb +3 -4
- data/lib/rio/assert.rb +3 -4
- data/lib/rio/base.rb +3 -4
- data/lib/rio/callstr.rb +3 -4
- data/lib/rio/const.rb +3 -4
- data/lib/rio/construct.rb +3 -4
- data/lib/rio/constructor.rb +12 -8
- data/lib/rio/context.rb +15 -30
- data/lib/rio/context/autoclose.rb +3 -4
- data/lib/rio/context/copying.rb +3 -4
- data/lib/rio/context/cxx.rb +3 -4
- data/lib/rio/context/dir.rb +3 -4
- data/lib/rio/context/gzip.rb +3 -4
- data/lib/rio/context/methods.rb +16 -5
- data/lib/rio/context/skip.rb +3 -4
- data/lib/rio/context/stream.rb +42 -5
- data/lib/rio/cp.rb +7 -7
- data/lib/rio/def.rb +3 -4
- data/lib/rio/dir.rb +3 -4
- data/lib/rio/doc.rb +4 -5
- data/lib/rio/doc/EXAMPLES.rb +299 -0
- data/lib/rio/doc/HOWTO.rb +3 -4
- data/lib/rio/doc/INTRO.rb +86 -105
- data/lib/rio/doc/OPTIONAL.rb +4 -5
- data/lib/rio/doc/SYNOPSIS.rb +7 -6
- data/lib/rio/entrysel.rb +21 -23
- data/lib/rio/exception.rb +3 -4
- data/lib/rio/exception/copy.rb +3 -4
- data/lib/rio/exception/notimplemented.rb +57 -0
- data/lib/rio/exception/notsupported.rb +3 -4
- data/lib/rio/exception/open.rb +3 -4
- data/lib/rio/exception/state.rb +3 -4
- data/lib/rio/ext.rb +47 -13
- data/lib/rio/ext/csv.rb +4 -5
- data/lib/rio/ext/if.rb +45 -0
- data/lib/rio/ext/mp3info.rb +80 -0
- data/lib/rio/ext/splitlines.rb +253 -0
- data/lib/rio/ext/yaml.rb +9 -5
- data/lib/rio/ext/yaml/doc.rb +133 -0
- data/lib/rio/ext/yaml/tie.rb +149 -0
- data/lib/rio/ext/zipfile.rb +23 -4
- data/lib/rio/ext/zipfile/fs.rb +116 -0
- data/lib/rio/ext/zipfile/rl.rb +251 -0
- data/lib/rio/ext/zipfile/rootdir.rb +117 -0
- data/lib/rio/ext/zipfile/state.rb +161 -0
- data/lib/rio/ext/zipfile/wrap.rb +204 -0
- data/lib/rio/factory.rb +235 -27
- data/lib/rio/file.rb +4 -4
- data/lib/rio/filter.rb +3 -4
- data/lib/rio/filter/closeoneof.rb +3 -4
- data/lib/rio/filter/gzip.rb +9 -4
- data/lib/rio/fs/base.rb +3 -4
- data/lib/rio/fs/impl.rb +4 -5
- data/lib/rio/fs/native.rb +3 -4
- data/lib/rio/fs/stream.rb +3 -4
- data/lib/rio/fs/url.rb +3 -4
- data/lib/rio/ftp/conncache.rb +19 -5
- data/lib/rio/ftp/dir.rb +3 -4
- data/lib/rio/ftp/fs.rb +30 -24
- data/lib/rio/grande.rb +27 -7
- data/lib/rio/handle.rb +3 -4
- data/lib/rio/if.rb +19 -15
- data/lib/rio/if/basic.rb +7 -7
- data/lib/rio/if/csv.rb +5 -6
- data/lib/rio/if/dir.rb +120 -114
- data/lib/rio/if/file.rb +52 -44
- data/lib/rio/if/fileordir.rb +217 -211
- data/lib/rio/if/grande.rb +674 -644
- data/lib/rio/if/grande_entry.rb +321 -313
- data/lib/rio/if/grande_stream.rb +653 -553
- data/lib/rio/if/internal.rb +3 -4
- data/lib/rio/if/path.rb +425 -426
- data/lib/rio/if/rubyio.rb +681 -0
- data/lib/rio/if/string.rb +42 -5
- data/lib/rio/if/temp.rb +3 -4
- data/lib/rio/if/test.rb +245 -238
- data/lib/rio/if/yaml.rb +15 -41
- data/lib/rio/ioh.rb +7 -5
- data/lib/rio/iomode.rb +19 -7
- data/lib/rio/ios/fail.rb +4 -5
- data/lib/rio/ios/generic.rb +4 -5
- data/lib/rio/ios/mode.rb +4 -5
- data/lib/rio/ios/null.rb +6 -7
- data/lib/rio/iowrap.rb +3 -4
- data/lib/rio/kernel.rb +3 -5
- data/lib/rio/local.rb +3 -4
- data/lib/rio/match.rb +3 -4
- data/lib/rio/matchrecord.rb +3 -4
- data/lib/rio/no_warn.rb +3 -4
- data/lib/rio/nullio.rb +3 -4
- data/lib/rio/open3.rb +4 -5
- data/lib/rio/ops/construct.rb +3 -4
- data/lib/rio/ops/create.rb +11 -6
- data/lib/rio/ops/dir.rb +19 -8
- data/lib/rio/ops/either.rb +6 -5
- data/lib/rio/ops/file.rb +3 -4
- data/lib/rio/ops/path.rb +14 -35
- data/lib/rio/ops/stream.rb +3 -4
- data/lib/rio/ops/stream/input.rb +4 -7
- data/lib/rio/ops/stream/output.rb +3 -4
- data/lib/rio/ops/stream/read.rb +6 -5
- data/lib/rio/ops/stream/write.rb +3 -4
- data/lib/rio/ops/symlink.rb +3 -4
- data/lib/rio/path.rb +22 -18
- data/lib/rio/path/reset.rb +4 -5
- data/lib/rio/piper.rb +3 -4
- data/lib/rio/piper/cp.rb +3 -4
- data/lib/rio/prompt.rb +10 -5
- data/lib/rio/rectype.rb +5 -5
- data/lib/rio/rl/base.rb +17 -71
- data/lib/rio/rl/builder.rb +14 -38
- data/lib/rio/rl/chmap.rb +66 -0
- data/lib/rio/rl/fs2url.rb +82 -0
- data/lib/rio/rl/ioi.rb +4 -4
- data/lib/rio/rl/path.rb +44 -122
- data/lib/rio/rl/pathmethods.rb +19 -8
- data/lib/rio/rl/uri.rb +137 -60
- data/lib/rio/rl/withpath.rb +295 -0
- data/lib/rio/scheme/aryio.rb +3 -4
- data/lib/rio/scheme/cmdio.rb +3 -4
- data/lib/rio/scheme/cmdpipe.rb +4 -4
- data/lib/rio/scheme/fd.rb +3 -4
- data/lib/rio/scheme/ftp.rb +7 -7
- data/lib/rio/scheme/http.rb +4 -5
- data/lib/rio/scheme/null.rb +3 -4
- data/lib/rio/scheme/path.rb +3 -4
- data/lib/rio/scheme/stderr.rb +3 -4
- data/lib/rio/scheme/stdio.rb +3 -4
- data/lib/rio/scheme/strio.rb +3 -4
- data/lib/rio/scheme/sysio.rb +3 -4
- data/lib/rio/scheme/tcp.rb +3 -4
- data/lib/rio/scheme/temp.rb +6 -6
- data/lib/rio/state.rb +18 -46
- data/lib/rio/state/error.rb +3 -4
- data/lib/rio/stream.rb +4 -4
- data/lib/rio/stream/base.rb +3 -4
- data/lib/rio/stream/duplex.rb +3 -4
- data/lib/rio/stream/open.rb +3 -8
- data/lib/rio/symantics.rb +3 -4
- data/lib/rio/tempdir.rb +2 -2
- data/lib/rio/to_rio.rb +3 -4
- data/lib/rio/to_rio/all.rb +3 -4
- data/lib/rio/to_rio/array.rb +4 -5
- data/lib/rio/to_rio/io.rb +4 -5
- data/lib/rio/to_rio/object.rb +4 -5
- data/lib/rio/to_rio/string.rb +4 -5
- data/lib/rio/uri/file.rb +41 -5
- data/lib/rio/util.rb +3 -4
- data/lib/rio/version.rb +4 -5
- data/setup.rb +368 -339
- data/test/bin/list_dir.rb +1 -1
- data/test/ftp/anon_misc.rb +13 -1
- data/test/ftp/anon_special.rb +6 -6
- data/test/ftp/anon_write.rb +10 -3
- data/test/ftp/ftp2ftp.rb +2 -2
- data/test/ftp/testdef.rb +9 -6
- data/test/http/all.rb +3 -0
- data/test/http/copy-from-http.rb +140 -0
- data/test/lib/temp_server.rb +44 -0
- data/test/runalltests.rb +3 -1
- data/test/runhttp.rb +12 -0
- data/test/runhttptests.rb +1 -1
- data/test/runtests.rb +41 -3
- data/test/tc/abs.rb +9 -5
- data/test/tc/all.rb +9 -4
- data/test/tc/base.rb +1 -1
- data/test/tc/base2.rb +87 -0
- data/test/tc/{methods.rb → clone.rb} +72 -50
- data/test/tc/closeoncopy.rb +13 -2
- data/test/tc/copy-dir-samevar.rb +91 -0
- data/test/tc/dir_iter.rb +0 -1
- data/test/tc/empty.rb +6 -2
- data/test/tc/expand_path.rb +36 -54
- data/test/tc/ext.rb +42 -18
- data/test/tc/gzip.rb +30 -3
- data/test/tc/likeio.rb +5 -1
- data/test/tc/line_record_row.rb +51 -0
- data/test/tc/noqae.rb +71 -70
- data/test/tc/path_parts.rb +175 -0
- data/test/tc/programs_util.rb +3 -3
- data/test/tc/rename.rb +4 -5
- data/test/tc/riorl.rb +9 -7
- data/test/tc/skip.rb +35 -6
- data/test/tc/skiplines.rb +34 -5
- data/test/tc/split.rb +8 -50
- data/test/tc/splitlines.rb +65 -0
- data/test/tc/splitpath.rb +83 -0
- data/test/tc/testcase.rb +1 -1
- data/test/tc/truncate.rb +39 -0
- data/test/tc/yaml.rb +9 -8
- metadata +261 -207
- data/ChangeLog +0 -1418
- data/VERSION +0 -1
- data/lib/rio/doc/MISC.rb +0 -259
- data/lib/rio/if/stream.rb +0 -680
- data/lib/rio/impl/path.rb +0 -87
- data/test/tc/copy-from-http.rb +0 -89
data/lib/rio/if/grande_entry.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
#--
|
2
2
|
# ===============================================================================
|
3
|
-
# Copyright (c) 2005,
|
3
|
+
# Copyright (c) 2005,2006,2007 Christopher Kleckner
|
4
4
|
# All rights reserved
|
5
5
|
#
|
6
6
|
# This file is part of the Rio library for ruby.
|
@@ -23,343 +23,351 @@
|
|
23
23
|
#
|
24
24
|
# To create the documentation for Rio run the command
|
25
25
|
# ruby build_doc.rb
|
26
|
-
# from the distribution directory.
|
26
|
+
# from the distribution directory.
|
27
27
|
#
|
28
28
|
# Suggested Reading
|
29
29
|
# * RIO::Doc::SYNOPSIS
|
30
30
|
# * RIO::Doc::INTRO
|
31
31
|
# * RIO::Doc::HOWTO
|
32
|
+
# * RIO::Doc::EXAMPLES
|
32
33
|
# * RIO::Rio
|
33
34
|
#
|
34
|
-
# <b>Rio is pre-alpha software.
|
35
|
-
# The documented interface and behavior is subject to change without notice.</b>
|
36
35
|
|
37
36
|
|
38
37
|
module RIO
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
38
|
+
module IF
|
39
|
+
module GrandeEntry
|
40
|
+
# Grande Directory Selection Method
|
41
|
+
#
|
42
|
+
# Sets the rio to return directories. _args_ can be used to select which directories are returned.
|
43
|
+
# ario.files(*args) do |f|
|
44
|
+
# f.directory? #=> true
|
45
|
+
# end
|
46
|
+
#
|
47
|
+
# No aguments selects all directories.
|
48
|
+
# if _args_ are:
|
49
|
+
# Regexp:: selects matching directories
|
50
|
+
# glob:: selects matching directories
|
51
|
+
# Proc:: called for each directory. the directory is processed unless the proc returns false
|
52
|
+
# Symbol:: sent to each directory. Each directory is processed unless the symbol returns false
|
53
|
+
# Fixnum:: matched against the "depth" of the directory
|
54
|
+
#
|
55
|
+
# If a block is given, behaves like <tt>ario.dirs(*args).each(&block)</tt>
|
56
|
+
#
|
57
|
+
# See also #files, #entries, #skipdirs
|
58
|
+
#
|
59
|
+
# rio('adir').dirs { |frio| ... } # process all directories in 'adir'
|
60
|
+
# rio('adir').all.dirs { |frio| ... } # same thing recursively
|
61
|
+
# rio('adir').dirs(/^\./) { |frio| ...} # process dot directories
|
62
|
+
# rio('adir').dirs[/^\./] # return an array of dot directories
|
63
|
+
# rio('adir').dirs[:symlink?] # an array of symlinks to directories
|
64
|
+
#
|
65
|
+
def dirs(*args,&block) target.dirs(*args,&block); self end
|
66
|
+
|
67
|
+
# Grande Directory Exclude Method
|
68
|
+
#
|
69
|
+
# If no args are provided selects anything but directories.
|
70
|
+
# ario.skipdirs do |el|
|
71
|
+
# el.directory? #=> false
|
72
|
+
# end
|
73
|
+
# If args are provided, sets the rio to select directories as with #dirs, but the arguments are
|
74
|
+
# used to determine which directories will *not* be processed
|
75
|
+
#
|
76
|
+
# If a block is given behaves like
|
77
|
+
# ario.skipdirs(*args).each(&block)
|
78
|
+
#
|
79
|
+
# See #dirs
|
80
|
+
#
|
81
|
+
# rio('adir').skipdirs { |ent| ... } # iterate through everything except directories
|
82
|
+
# rio('adir').skipdirs(/^\./) { |drio| ... } # iterate through directories, skipping dot directories
|
83
|
+
#
|
84
|
+
#
|
85
|
+
def skipdirs(*args,&block) target.skipdirs(*args,&block); self end
|
86
86
|
|
87
87
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
88
|
+
# Grande Directory Entry Selection Method
|
89
|
+
#
|
90
|
+
# No aguments selects all entries.
|
91
|
+
#
|
92
|
+
# if +args+ are:
|
93
|
+
# Regexp:: selects matching entries
|
94
|
+
# glob:: selects matching entries
|
95
|
+
# Proc:: called for each entry. the entry is processed unless the proc returns false
|
96
|
+
# Symbol:: sent to each entry. Each entry is processed unless the symbol returns false
|
97
|
+
#
|
98
|
+
# If a block is given, behaves like <tt>ario.etries(*args).each(&block)</tt>
|
99
|
+
#
|
100
|
+
# See also #files, #dirs, #skipentries
|
101
|
+
#
|
102
|
+
# rio('adir').entries { |frio| ... } # process all entries in 'adir'
|
103
|
+
# rio('adir').all.entries { |frio| ... } # same thing recursively
|
104
|
+
# rio('adir').entries(/^\./) { |frio| ...} # process entries starting with a dot
|
105
|
+
# rio('adir').entries[/^\./] # return an array of all entries starting with a dot
|
106
|
+
# rio('adir').entries[:symlink?] # an array of symlinks in 'adir'
|
107
|
+
#
|
108
|
+
def entries(*args,&block) target.entries(*args,&block); self end
|
109
109
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
110
|
+
# Grande Directory Entry Rejection Method
|
111
|
+
#
|
112
|
+
# No aguments rejects all entries.
|
113
|
+
#
|
114
|
+
# Behaves like #entries, except that matching entries are excluded.
|
115
|
+
#
|
116
|
+
# See also #entries, IF::Grande#skip
|
117
|
+
#
|
118
|
+
def skipentries(*args,&block) target.skipentries(*args,&block); self end
|
117
119
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
120
|
+
|
121
|
+
# Grande File Selection Method
|
122
|
+
#
|
123
|
+
# Configures the rio to process files. +args+ can be used to select which files are returned.
|
124
|
+
# ario.files(*args) do |f|
|
125
|
+
# f.file? #=> true
|
126
|
+
# end
|
127
|
+
# No aguments selects all files.
|
128
|
+
#
|
129
|
+
# +args+ may be zero or more of the following:
|
130
|
+
#
|
131
|
+
# Regexp:: selects matching files
|
132
|
+
# String:: treated as a glob, and selects matching files
|
133
|
+
# Proc:: called for each file. the file is processed unless the proc returns false
|
134
|
+
# Symbol:: sent to each file. Each file is processed unless the symbol returns false
|
135
|
+
#
|
136
|
+
# +files+ returns the Rio which called it. This might seem counter-intuitive at first.
|
137
|
+
# One might reasonably assume that
|
138
|
+
# rio('adir').files('*.rb')
|
139
|
+
# would return files. It does not. It configures the rio to return files and returns
|
140
|
+
# the Rio. This enables chaining for further configuration so constructs like
|
141
|
+
# rio('adir').all.files('*.rb').norecurse('.svn')
|
142
|
+
# are possible.
|
143
|
+
#
|
144
|
+
# If a block is given, behaves like
|
145
|
+
# ario.files(*args).each
|
146
|
+
#
|
147
|
+
#
|
148
|
+
# See also #dirs, #entries, #skipfiles
|
149
|
+
#
|
150
|
+
# rio('adir').files { |frio| ... } # process all files in 'adir'
|
151
|
+
# rio('adir').all.files { |frio| ... } # same thing recursively
|
152
|
+
# rio('adir').files('*.rb') { |frio| ...} # process .rb files
|
153
|
+
# rio('adir').files['*.rb'] # return an array of .rb files
|
154
|
+
# rio('adir').files[/\.rb$/] # same thing using a regular expression
|
155
|
+
# rio('adir').files[:symlink?] # an array of symlinks to files
|
156
|
+
# rio('adir').files >> rio('other_dir') # copy files to 'other_dir'
|
157
|
+
# rio('adir').files('*.rb') >> rio('other_dir') # only copy .rb files
|
158
|
+
#
|
159
|
+
# For Rios that refer to files, <tt>files(*args)</tt> causes the file to be processed only if
|
160
|
+
# it meets the criteria specified by the args.
|
161
|
+
#
|
162
|
+
# rio('afile.z').files['*.z'] #=> [rio('afile.z')]
|
163
|
+
# rio('afile.q').files['*.z'] #=> []
|
164
|
+
#
|
165
|
+
# === Example Problem
|
166
|
+
#
|
167
|
+
# Fill the array +ruby_progs+ with all ruby programs in a directory and its subdirectories,
|
168
|
+
# skipping those in _subversion_ (.svn) directories.
|
169
|
+
#
|
170
|
+
# ruby_progs = []
|
171
|
+
#
|
172
|
+
# For the purposes of this problem, a Ruby program is defined as a file ending with .rb or a file
|
173
|
+
# that is executable and whose shebang line contains 'ruby':
|
174
|
+
#
|
175
|
+
# is_ruby_exe = proc{ |f| f.executable? and f.gets =~ /^#!.+ruby/ }
|
176
|
+
#
|
177
|
+
# ==== Solution 1. Use the subscript operator.
|
178
|
+
#
|
179
|
+
# ruby_progs = rio('adir').norecurse('.svn').files['*.rb',is_ruby_exe]
|
180
|
+
#
|
181
|
+
# Explanation:
|
182
|
+
#
|
183
|
+
# 1. Create the Rio
|
184
|
+
#
|
185
|
+
# Create a Rio for a directory
|
186
|
+
# rio('adir')
|
187
|
+
#
|
188
|
+
# 2. Configure the Rio
|
189
|
+
#
|
190
|
+
# Specify recursion and that '.svn' directories should not be included.
|
191
|
+
# rio('adir').norecurse('.svn')
|
192
|
+
# Select files
|
193
|
+
# rio('adir').norecurse('.svn').files
|
194
|
+
# Limit to files ending with '.rb'
|
195
|
+
# rio('adir').norecurse('.svn').files('*.rb')
|
196
|
+
# Also allow files for whom +is_ruby_exe+ returns true
|
197
|
+
# rio('adir').norecurse('.svn').files('*.rb',is_ruby_exe)
|
198
|
+
#
|
199
|
+
# 3. Do the I/O
|
200
|
+
#
|
201
|
+
# Return an array rather than iterating thru them
|
202
|
+
# ruby_progs = rio('adir').norecurse('.svn').files['*.rb',is_ruby_exe]
|
203
|
+
#
|
204
|
+
# ==== Solution 2. Use the copy-to operator
|
205
|
+
#
|
206
|
+
# rio('adir').files('*.rb',is_ruby_exe).norecurse('.svn') > ruby_progs
|
207
|
+
#
|
208
|
+
# Explanation:
|
209
|
+
#
|
210
|
+
# 1. Create the Rio
|
211
|
+
#
|
212
|
+
# Create a Rio for a directory
|
213
|
+
# rio('adir')
|
214
|
+
#
|
215
|
+
# 2. Configure the Rio
|
216
|
+
#
|
217
|
+
# Select only files
|
218
|
+
# rio('adir').files
|
219
|
+
# Limit to files ending with '.rb'
|
220
|
+
# rio('adir').files('*.rb')
|
221
|
+
# Also allow files for whom +is_ruby_exe+ returns true
|
222
|
+
# rio('adir').files('*.rb',is_ruby_exe)
|
223
|
+
# Specify recursion and that '.svn' directories should not be included.
|
224
|
+
# rio('adir').files('*.rb',is_ruby_exe).norecurse('.svn')
|
225
|
+
#
|
226
|
+
# 3. Do the I/O
|
227
|
+
#
|
228
|
+
# Copy the Rio to ruby_progs
|
229
|
+
# rio('adir').files('*.rb',is_ruby_exe).norecurse('.svn') > ruby_progs
|
230
|
+
#
|
231
|
+
# ==== Example Discussion
|
232
|
+
#
|
233
|
+
# Note that the only difference between Step 2 of Solution 1 and that of Solution 2 is
|
234
|
+
# the order of the configuration methods. Step 2 of Solution 1 would have worked equally
|
235
|
+
# well:
|
236
|
+
#
|
237
|
+
# rio('adir').norecurse('.svn').files('*.rb',is_ruby_exe) > ruby_progs
|
238
|
+
#
|
239
|
+
# Furthermore if our problem were changed slightly and instead of having our results
|
240
|
+
# ending up in an array, we wished to iterate through them, we could use:
|
241
|
+
#
|
242
|
+
# rio('adir').norecurse('.svn').files('*.rb',is_ruby_exe) { |ruby_prog_rio| ... }
|
243
|
+
#
|
244
|
+
# Note the similarities. In fact, solution 1 could have been written:
|
245
|
+
#
|
246
|
+
# rio('adir').norecurse('.svn').files('*.rb',is_ruby_exe).to_a
|
247
|
+
# or
|
248
|
+
# rio('adir').norecurse('.svn').files('*.rb',is_ruby_exe)[]
|
249
|
+
#
|
250
|
+
# Passing the arguments for +files+ to the subscript operator is syntactic sugar.
|
251
|
+
# The subscript operator does not really take any arguments of its own. It always
|
252
|
+
# passes them to the most recently called of the grande selection methods (or the
|
253
|
+
# default selection method, if none have been called). So,
|
254
|
+
#
|
255
|
+
# rio('adir').files['*.rb']
|
256
|
+
# is a shortcut for
|
257
|
+
# rio('adir').files('*.rb').to_a
|
258
|
+
#
|
259
|
+
# and
|
260
|
+
#
|
261
|
+
# rio('adir')['*.rb']
|
262
|
+
# is a shortcut for
|
263
|
+
# rio('adir').entries('*.rb').to_a
|
264
|
+
#
|
265
|
+
# and
|
266
|
+
#
|
267
|
+
# rio('afile').lines[0..10]
|
268
|
+
# is a shortcut for
|
269
|
+
# rio('afile').lines(0..10).to_a
|
270
|
+
#
|
271
|
+
# And so on.
|
272
|
+
#
|
273
|
+
#
|
274
|
+
#
|
275
|
+
def files(*args,&block) target.files(*args,&block); self end
|
274
276
|
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
277
|
+
# Grande File Exclude Method
|
278
|
+
#
|
279
|
+
# If no args are provided selects anything but files.
|
280
|
+
# ario.skipfiles do |el|
|
281
|
+
# el.file? #=> false
|
282
|
+
# end
|
283
|
+
# If args are provided, sets the rio to select files as with #files, but the arguments are
|
284
|
+
# used to determine which files will *not* be processed
|
285
|
+
#
|
286
|
+
# If a block is given behaves like <tt>ario.skipfiles(*args).each(&block)</tt>
|
287
|
+
#
|
288
|
+
# See #files, IF::Grande#skip
|
289
|
+
#
|
290
|
+
# rio('adir').skipfiles { |ent| ... } # iterate through everything except files
|
291
|
+
# rio('adir').skipfiles('*~') { |frio| ... } # iterate through files, skipping those ending with a tilde
|
292
|
+
#
|
293
|
+
#
|
294
|
+
def skipfiles(*args,&block) target.skipfiles(*args,&block); self end
|
293
295
|
|
294
296
|
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
297
|
+
# Returns +true+ if the rio is in +all+ (recursive) mode. See #all
|
298
|
+
#
|
299
|
+
# adir = rio('adir').all.dirs
|
300
|
+
# adir.all? # true
|
301
|
+
# adir.each do |subdir|
|
302
|
+
# subdir.all? # true
|
303
|
+
# end
|
304
|
+
#
|
305
|
+
# rio('adir').all? # false
|
306
|
+
#
|
307
|
+
def all?() target.all?() end
|
306
308
|
|
307
309
|
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
310
|
+
# Grande Directory Recursion Method
|
311
|
+
#
|
312
|
+
# Sets the Rio to all mode (recursive)
|
313
|
+
#
|
314
|
+
# When called with a block, behaves as if all.each(&block) had been called
|
315
|
+
#
|
316
|
+
# +all+ causes subsequent calls to +files+ or +dirs+ to be applied recursively
|
317
|
+
# to subdirectories
|
318
|
+
#
|
319
|
+
# rio('adir').all.files('*.[ch]').each { |file| ... } # process all c language source files in adir
|
320
|
+
# # and all subdirectories of adir
|
321
|
+
# rio('adir').all.files(/\.[ch]$/) { |file| ... } # same as above
|
322
|
+
# rio('adir').files("*.[ch]").all { |file| ... } # once again
|
323
|
+
# rio('adir').all.files["*.[ch]"] # same, but return an array instead of iterating
|
324
|
+
#
|
325
|
+
def all(arg=true,&block) target.all(arg,&block); self end
|
324
326
|
|
325
327
|
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
328
|
+
# Grande Directory Recursion Selection Method
|
329
|
+
#
|
330
|
+
# Sets the Rio to recurse into directories like #all. If no args are provided behaves like #all.
|
331
|
+
# If args are provided, they are processed like #dirs to select which subdirectories should
|
332
|
+
# be recursed into. #recurse always implies #all.
|
333
|
+
#
|
334
|
+
# +args+ may be one or more of:
|
335
|
+
# Regexp:: recurse into matching subdirectories
|
336
|
+
# glob:: recurse into matching subdirectories
|
337
|
+
# Proc:: called for each directory. The directory is recursed into unless the proc returns false
|
338
|
+
# Symbol:: sent to each directory. Each directory is recursed into unless the symbol returns false
|
339
|
+
# Fixnum:: recurse into directories only at the given depth
|
340
|
+
# Range:: recurse into directories at a range of depths
|
341
|
+
#
|
342
|
+
# If a block is given, behaves like <tt>ario.recurse(*args).each(&block)</tt>
|
343
|
+
#
|
344
|
+
# See also #norecurse, #all, #dirs
|
345
|
+
#
|
346
|
+
# rio('adir').recurse('test*') { |drio| ... } # process all entries and all entries in subdirectories
|
347
|
+
# # starting with 'test' -- recursively
|
348
|
+
#
|
349
|
+
def recurse(*args,&block) target.recurse(*args,&block); self end
|
348
350
|
|
349
351
|
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
352
|
+
# Grande Directory Recursion Exclude Method
|
353
|
+
#
|
354
|
+
# Sets the Rio to recurse into directories like #all. If no args are provided, no
|
355
|
+
# directories will be recursed into. If args are provided, behaves like #recurse, except
|
356
|
+
# that matching directories will *not* be recursed into
|
357
|
+
#
|
358
|
+
# rio('adir').norecurse('.svn') { |drio| ... } # recurse, skipping subversion directories
|
359
|
+
#
|
360
|
+
# rio('adir').norecurse(3) {|drio| ... } # only recurse 2 levels deep into a directory structure
|
361
|
+
#
|
362
|
+
def norecurse(*args,&block) target.norecurse(*args,&block); self end
|
361
363
|
|
362
364
|
|
365
|
+
end
|
363
366
|
end
|
364
367
|
end
|
365
368
|
|
369
|
+
module RIO
|
370
|
+
class Rio
|
371
|
+
include RIO::IF::GrandeEntry
|
372
|
+
end
|
373
|
+
end
|