rio 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. data/ChangeLog +225 -0
  2. data/README +12 -0
  3. data/Rakefile +1 -1
  4. data/VERSION +1 -1
  5. data/doc/ANNOUNCE +160 -71
  6. data/doc/RELEASE_NOTES +71 -2
  7. data/ex/colx.rb +1 -1
  8. data/ex/passwd_report.rb +4 -8
  9. data/ex/riocat +5 -5
  10. data/ex/riogunzip +1 -1
  11. data/ex/riogzip +6 -6
  12. data/ex/rioprompt.rb +6 -0
  13. data/lib/rio.rb +3 -13
  14. data/lib/rio/arycopy.rb +1 -1
  15. data/lib/rio/base.rb +1 -5
  16. data/lib/rio/construct.rb +75 -0
  17. data/lib/rio/constructor.rb +42 -11
  18. data/lib/rio/context.rb +1 -1
  19. data/lib/rio/context/dir.rb +50 -23
  20. data/lib/rio/context/methods.rb +5 -3
  21. data/lib/rio/{cxdir.rb → context/skip.rb} +24 -36
  22. data/lib/rio/context/stream.rb +38 -16
  23. data/lib/rio/cp.rb +24 -5
  24. data/lib/rio/dir.rb +8 -7
  25. data/lib/rio/doc/HOWTO.rb +33 -33
  26. data/lib/rio/doc/INTRO.rb +416 -256
  27. data/lib/rio/doc/MISC.rb +3 -1
  28. data/lib/rio/doc/SYNOPSIS.rb +28 -33
  29. data/lib/rio/entrysel.rb +76 -9
  30. data/lib/rio/file.rb +2 -1
  31. data/lib/rio/filter.rb +95 -0
  32. data/lib/rio/filter/closeoneof.rb +1 -1
  33. data/lib/rio/grande.rb +0 -74
  34. data/lib/rio/if.rb +2 -1
  35. data/lib/rio/if/basic.rb +1 -1
  36. data/lib/rio/if/csv.rb +1 -1
  37. data/lib/rio/if/dir.rb +1 -220
  38. data/lib/rio/if/fileordir.rb +26 -12
  39. data/lib/rio/if/grande.rb +55 -6
  40. data/lib/rio/if/grande_entry.rb +355 -0
  41. data/lib/rio/if/{methods.rb → grande_stream.rb} +69 -88
  42. data/lib/rio/if/path.rb +25 -3
  43. data/lib/rio/if/stream.rb +62 -37
  44. data/lib/rio/if/temp.rb +2 -2
  45. data/lib/rio/if/test.rb +23 -0
  46. data/lib/rio/impl/path.rb +5 -0
  47. data/lib/rio/match.rb +6 -3
  48. data/lib/rio/matchrecord.rb +50 -46
  49. data/lib/rio/{filter/chomp.rb → ops/construct.rb} +12 -20
  50. data/lib/rio/ops/create.rb +3 -0
  51. data/lib/rio/ops/dir.rb +12 -6
  52. data/lib/rio/ops/either.rb +17 -3
  53. data/lib/rio/ops/path.rb +4 -1
  54. data/lib/rio/ops/stream/input.rb +6 -1
  55. data/lib/rio/ops/stream/read.rb +1 -3
  56. data/lib/rio/{context/chomp.rb → prompt.rb} +17 -13
  57. data/lib/rio/rl/base.rb +1 -1
  58. data/lib/rio/rl/builder.rb +3 -1
  59. data/lib/rio/state.rb +7 -13
  60. data/lib/rio/stream.rb +8 -5
  61. data/lib/rio/stream/open.rb +1 -1
  62. data/lib/rio/version.rb +1 -1
  63. data/test/mswin32.rb +1 -1
  64. data/test/runtests_gem.rb +1 -1
  65. data/test/tc/all.rb +3 -0
  66. data/test/tc/copy-from.rb +13 -13
  67. data/test/tc/copy-to.rb +1 -1
  68. data/test/tc/copy.rb +1 -1
  69. data/test/tc/copydir.rb +0 -24
  70. data/test/tc/copysymlink.rb +39 -0
  71. data/test/tc/csv.rb +2 -2
  72. data/test/tc/csv2.rb +4 -4
  73. data/test/tc/misc.rb +16 -16
  74. data/test/tc/nolines.rb +26 -26
  75. data/test/tc/noqae.rb +74 -74
  76. data/test/tc/overload.rb +28 -28
  77. data/test/tc/riorl.rb +36 -0
  78. data/test/tc/selnosel.rb +36 -0
  79. data/test/tc/skip.rb +58 -0
  80. data/test/tc/skiplines.rb +42 -0
  81. data/test/tc/symlink.rb +1 -1
  82. data/test/tc/symlink0.rb +1 -1
  83. data/test/tc/temp.rb +1 -1
  84. data/test/tc/tempdir.rb +1 -1
  85. data/test/tc/testcase.rb +7 -1
  86. metadata +14 -8
  87. data/lib/rio/matchcolumns.rb +0 -266
  88. data/lib/rio/rangemath.rb +0 -44
@@ -1,6 +1,6 @@
1
1
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2
2
  Rio is pre-alpha software.
3
- The documented interface and behavior is subject to change without notice.
3
+ The documented interface and behaviour is subject to change without notice.
4
4
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
5
5
 
6
6
  === Rio - Ruby I/O Comfort Class
@@ -24,6 +24,75 @@ Suggested Reading
24
24
  * RIO::Doc::HOWTO
25
25
  * RIO::Rio
26
26
 
27
+ == New for version 0.3.4
28
+ * New Grande Selection parameter.
29
+
30
+ A major weakness of Rio's selection methods (lines, files, etc.)
31
+ has always been that it only implemented a logical OR.
32
+
33
+ rio('afile').lines(0..10,/Rio/) {...}
34
+ iterates through lines that are in the range 0..10 OR
35
+ contain 'Rio'.
36
+
37
+ rio('adir').files(:executable?,'*.rb') {...}
38
+ iterates through files that are executable OR match '*.rb'
39
+
40
+ Selecting files that matched both required using a proc.
41
+ rio('adir').files(proc{ |f| f.executable? and f.fnmatch?('*.rb')}) {...}
42
+
43
+ Rio's grande selection methods will now accept an array of conditions
44
+ which must all be matched, in order to be selected. A logical AND.
45
+
46
+ rio('adir').files([:executable?,'*.rb']) {...}
47
+
48
+ The array, of course, need not be the only paramter.
49
+
50
+ rio('adir').files('*.exe',[:executable?,'*.rb']) {...}
51
+
52
+ selects .exe files and .rb files that are executable.
53
+
54
+ * Renamed some of grande rejection methods.
55
+ (based on a suggestion by Gavin Sinclair)
56
+ nolines => skiplines
57
+ nofiles => skipfiles
58
+ etc.
59
+
60
+ * New skip() grande method
61
+ rio('afile').skip.lines(/Rio/) # same as skiplines(/Rio/)
62
+ rio('afile').lines(/Rio/).skip(0..9) # lines with 'Rio', exclude
63
+ # the first ten lines
64
+
65
+ * Alternative syntaxes for creating Rios that have no path.
66
+
67
+ rio(?-) # create a Rio refering to stdio
68
+ rio(:stdio) # same thing.
69
+ rio.stdio # same thing
70
+ RIO.stdio # ditto
71
+ RIO::Rio.stdio # once again
72
+
73
+ * From Pathname added
74
+ * root?
75
+ * mountpoint?
76
+ * realpath
77
+ * cleanpath
78
+
79
+ * Removed Rio#slurp in favor of Rio#contents.
80
+
81
+
82
+ * Added aliases for the copy operators. (suggested by Dave Burt)
83
+ * copy_to >
84
+ * append_to >>
85
+ * copy_from <
86
+ * append_from <<
87
+
88
+
89
+ * Bug fixes and corrections
90
+
91
+ Project:: http://rubyforge.org/projects/rio/
92
+ Documentation:: http://rio.rubyforge.org/
93
+ Bugs:: http://rubyforge.org/tracker/?group_id=821
94
+ Email:: rio4ruby@rubyforge.org
95
+
27
96
  == New for version 0.3.3
28
97
  * Expanded support and documentation for CSV files
29
98
  Examples:
@@ -137,7 +206,7 @@ Put the first 100 chomped lines of a gzipped file into an array
137
206
  anarray = rio('afile.gz').gzip[0...100]
138
207
 
139
208
  Copy the output of th ps command into an array, skipping the header line and the ps command entry
140
- rio(?-,'ps -a').nolines(0,/ps$/) > anarray
209
+ rio(?-,'ps -a').skiplines(0,/ps$/) > anarray
141
210
 
142
211
  Prompt for input and return what was typed
143
212
  ans = rio(?-).print("Type Something: ").chomp.gets
data/ex/colx.rb CHANGED
@@ -4,5 +4,5 @@ require 'rio'
4
4
  RGBFILE = rio(__FILE__).dirname/'rgb.txt.gz'
5
5
 
6
6
  RGBFILE.gzip.lines(/^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\S.+)/) do |line,ma|
7
- printf("#%02x%02x%02x\t%s\n",ma[1],ma[2],ma[3],ma[4])
7
+ printf("#%02x%02x%02x\t%s\n",*ma[1..4])
8
8
  end
@@ -1,12 +1,8 @@
1
- #!/usr/bin/env ruby
1
+ #!/usr/local/bin/ruby
2
2
  require 'rio'
3
3
 
4
- rio('/etc/passwd').csv(':').columns(0,2,4) > rio(?-).csv("\t")
5
-
6
- __END__
4
+ # Create a tab separated file of accounts in a UNIX passwd file,
5
+ # listing only the username, uid, and realname fields
7
6
 
8
- From Seattle,Wa
9
- Take I-90 east, take exit 143 Gorge Amphitheatre. Follow amphitheatre signs approximately 6 miles.
7
+ rio('/etc/passwd').csv(':').columns(0,2,4) > rio(?-).csv("\t")
10
8
 
11
- 206-242-8738
12
- 3:00
data/ex/riocat CHANGED
@@ -6,11 +6,11 @@ require 'rio'
6
6
  #
7
7
  # explanation:
8
8
  #
9
- # rio('-')
10
- # rio('-'): a rio that will be connected to stdin or stdout depending how it is used
9
+ # rio(?-)
10
+ # rio(?-): a rio that will be connected to stdin or stdout depending how it is used
11
11
  #
12
- # rio('-')
13
- # rio('-'): a rio that will be connected to stdin or stdout depending how it is used
12
+ # rio(?-)
13
+ # rio(?-): a rio that will be connected to stdin or stdout depending how it is used
14
14
  #
15
15
  # <
16
16
  # <: copy operator indicating rio on left is written to and the rio on the right is read from
@@ -22,7 +22,7 @@ rio(?-) < rio(?-)
22
22
  # rio(?-) > rio(?-)
23
23
  #
24
24
  # this is similar but reads the entire file before writing
25
- #rio('-').print!( rio('-').slurp )
25
+ #rio(?-).print!( rio(?-).slurp )
26
26
 
27
27
 
28
28
 
@@ -24,7 +24,7 @@ rio(?-).gzip > rio(?-)
24
24
  # rio(?-) < rio(?-).gzip
25
25
  #
26
26
  # this is similar, but reads the entire file in before writing it out
27
- # rio('-').print!( rio('-').gzip.contents )
27
+ # rio(?-).print!( rio(?-).gzip.contents )
28
28
  #
29
29
  #rio(?-).gzip.each_record do |rec|
30
30
  # rio(?-).print(rec)
data/ex/riogzip CHANGED
@@ -6,19 +6,19 @@ require 'rio'
6
6
  #
7
7
  # explanation:
8
8
  #
9
- # rio('-').gzip
10
- # rio('-'): a rio that will be connected to stdin or stdout depending how it is used
9
+ # rio(?-).gzip
10
+ # rio(?-): a rio that will be connected to stdin or stdout depending how it is used
11
11
  # .gzip: filter the input or output through Zlib:Gzip[Reader or Writer]
12
12
  #
13
- # rio('-')
14
- # rio('-'): a rio that will be connected to stdin or stdout depending how it is used
13
+ # rio(?-)
14
+ # rio(?-): a rio that will be connected to stdin or stdout depending how it is used
15
15
  #
16
16
  # <
17
17
  # rio copy operator indicating the direction of data
18
18
 
19
- rio('-').gzip < rio('-')
19
+ rio(?-).gzip < rio(?-)
20
20
 
21
21
  #
22
22
  # could also be written:
23
- # rio('-') > rio('-').gzip
23
+ # rio(?-) > rio(?-).gzip
24
24
  #
@@ -0,0 +1,6 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ require 'rio/prompt'
4
+
5
+ ans = RIO.prompt("Name: ")
6
+ puts "You typed '#{ans}'"
data/lib/rio.rb CHANGED
@@ -40,6 +40,7 @@
40
40
  require 'rio/version'
41
41
  require 'rio/base'
42
42
  require 'rio/exception'
43
+
43
44
  require 'extensions/symbol'
44
45
  require 'extensions/enumerable'
45
46
  require 'extensions/string'
@@ -53,6 +54,7 @@ end
53
54
 
54
55
  require 'rio/kernel'
55
56
  require 'rio/constructor'
57
+ require 'rio/construct'
56
58
 
57
59
  module RIO
58
60
  SEEK_SET = IO::SEEK_SET
@@ -97,19 +99,6 @@ module RIO
97
99
  ario
98
100
  end
99
101
 
100
- def open(m,*args,&block)
101
- target.open(m,*args)
102
- if block_given?
103
- old_closeoncopy,old_closeoneof = closeoncopy?,closeoneof?
104
- begin
105
- return yield(nocloseoncopy.nocloseoneof)
106
- ensure
107
- reset.closeoncopy(old_closeoncopy).closeoneof(old_closeoneof)
108
- end
109
- end
110
- self
111
- end
112
-
113
102
  # returns the Rio#fspath, which is the path for the Rio on the underlying filesystem
114
103
  def to_s() target.to_s end
115
104
  alias :to_str :to_s
@@ -138,6 +127,7 @@ module RIO
138
127
  require 'rio/if'
139
128
  include Enumerable
140
129
  end
130
+
141
131
  protected
142
132
 
143
133
  def target() @state.target end
@@ -38,7 +38,7 @@
38
38
  module RIO
39
39
  module AryCopy #:nodoc: all
40
40
  def >>(dest)
41
- rio(?$) << self >> dest
41
+ rio(?") << self >> dest
42
42
  end
43
43
  end
44
44
  end
@@ -37,10 +37,6 @@
37
37
 
38
38
  module RIO
39
39
  class Base < ::Object #:nodoc: all
40
- # KIOSYMS = [:gets,:open,:readline,:readlines,
41
- # :chop,:chomp!,:chop!,
42
- # :to_a,:putc,:puts,:print,:printf,:split,:=~]
43
- # @@kernel_cleaned ||= KIOSYMS.each { |sym| undef_method(sym) }
44
40
  KEEPSYM = {
45
41
  '__id__' => true,
46
42
  '__send__' => true,
@@ -54,7 +50,7 @@ module RIO
54
50
  'dup' => true,
55
51
  'clone' => true,
56
52
  'nil?' => true,
57
- # 'to_s' => true,
53
+ 'open' => true,
58
54
  }.freeze
59
55
  instance_methods.each { |m| undef_method m unless KEEPSYM[m] }
60
56
  end
@@ -0,0 +1,75 @@
1
+ #--
2
+ # ===============================================================================
3
+ # Copyright (c) 2005, Christopher Kleckner
4
+ # All rights reserved
5
+ #
6
+ # This file is part of the Rio library for ruby.
7
+ #
8
+ # Rio is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # Rio is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with Rio; if not, write to the Free Software
20
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
+ # ===============================================================================
22
+ #++
23
+ #
24
+ # To create the documentation for Rio run the command
25
+ # rake rdoc
26
+ # from the distribution directory. Then point your browser at the 'doc/rdoc' directory.
27
+ #
28
+ # Suggested Reading
29
+ # * RIO::Doc::SYNOPSIS
30
+ # * RIO::Doc::INTRO
31
+ # * RIO::Doc::HOWTO
32
+ # * RIO::Rio
33
+ #
34
+ # <b>Rio is pre-alpha software.
35
+ # The documented interface and behavior is subject to change without notice.</b>
36
+
37
+
38
+ module RIO
39
+ def strio(*args) rio(:strio,*args) end
40
+ def stdio(*args) rio(:stdio,*args) end
41
+ def stderr(*args) rio(:stderr,*args) end
42
+ def temp(*args) rio(:temp,*args) end
43
+ def tempfile(*args) rio(:tempfile,*args) end
44
+ def tempdir(*args) rio(:tempdir,*args) end
45
+ def tcp(*args) rio(:tcp,*args) end
46
+ def cmdio(*args) rio(:cmdio,*args) end
47
+ def sysio(*args) rio(:sysio,*args) end
48
+ def fd(*args) rio(:fd,*args) end
49
+
50
+ module_function :strio
51
+ module_function :stdio
52
+ module_function :stderr
53
+ module_function :temp
54
+ module_function :tempfile
55
+ module_function :tempdir
56
+ module_function :tcp
57
+ module_function :cmdio
58
+ module_function :sysio
59
+ module_function :fd
60
+ end
61
+
62
+ module RIO
63
+ class Rio
64
+ def self.strio(*args) rio(:strio,*args) end
65
+ def self.stdio(*args) rio(:stdio,*args) end
66
+ def self.stderr(*args) rio(:stderr,*args) end
67
+ def self.temp(*args) rio(:temp,*args) end
68
+ def self.tempfile(*args) rio(:tempfile,*args) end
69
+ def self.tempdir(*args) rio(:tempdir,*args) end
70
+ def self.tcp(*args) rio(:tcp,*args) end
71
+ def self.cmdio(*args) rio(:cmdio,*args) end
72
+ def self.sysio(*args) rio(:sysio,*args) end
73
+ def self.fd(*args) rio(:fd,*args) end
74
+ end
75
+ end
@@ -92,21 +92,31 @@ module RIO
92
92
  #
93
93
  # ==== Creating Rios that do not have a path
94
94
  #
95
- # To create a Rio without a path, the first argument to +rio+ is usually a single
96
- # character.
95
+ # To create a Rio without a path, the first argument to +rio+ is usually
96
+ # either a single character or a symbol.
97
97
  #
98
98
  # ===== Creating a Rio that refers to a clone of your programs stdin or stdout.
99
99
  #
100
100
  # <tt>rio(?-)</tt> (mnemonic: '-' is used by some Unix programs to specify stdin or stdout in place of a file)
101
+ #
102
+ # <tt>rio(:stdio)</tt>
101
103
  #
102
104
  # Just as a Rio that refers to a file, does not know whether that file will be opened for reading or
103
105
  # writing until an I/O operation is specified, a <tt>stdio:</tt> Rio does not know whether it will connect
104
106
  # to stdin or stdout until an I/O operation is specified.
105
107
  #
108
+ # Currently :stdin and :stdout are allowed as synonyms for :stdio. This allows one to write
109
+ # rio(:stdout).puts("Hello :stdout")
110
+ # which is reasonable. It also allows one to write
111
+ # rio(:stdin).puts("Hello :stdin")
112
+ # which is not reasonable and will be disallowed in future releases.
113
+ #
106
114
  # ===== Creating a Rio that refers to a clone of your programs stderr.
107
115
  #
108
116
  # <tt>rio(?=)</tt> (mnemonic: '-' refers to fileno 1, so '=' refers to fileno 2)
109
117
  #
118
+ # <tt>rio(:stderr)</tt>
119
+ #
110
120
  # ===== Creating a Rio that refers to an arbitrary IO object.
111
121
  #
112
122
  # an_io = ::File.new('afile')
@@ -114,7 +124,9 @@ module RIO
114
124
  #
115
125
  # ===== Creating a Rio that refers to a file descriptor
116
126
  #
117
- # <tt>rio(?#,fd)</tt> (mnemonic: a file descriptor is a number '#')
127
+ # <tt>rio(?#,file_descriptor)</tt> (mnemonic: a file descriptor is a number '#')
128
+ #
129
+ # <tt>rio(:fd,file_descriptor)</tt>
118
130
  #
119
131
  # an_io = ::File.new('afile')
120
132
  # fnum = an_io.fileno
@@ -123,15 +135,33 @@ module RIO
123
135
  # ===== Creating a Rio that refers to a StringIO object
124
136
  #
125
137
  # <tt>rio(?")</tt> (mnemonic: '"' surrounds strings)
138
+ #
139
+ # <tt>rio(:strio)</tt>
140
+ #
141
+ # Alpha note: Should :strio be changed to :stringio, or even :string.
142
+ # Should more than one be allowed? I am leaning toward :string
143
+ #
126
144
  # * create a Rio that refers to a string that it creates
127
145
  # rio(?")
128
146
  # * create a Rio that refers to a string of your choosing
129
147
  # astring = ""
130
148
  # rio(?",astring)
131
149
  #
132
- # ===== Creating a Rio that refers to a Tempfile object
150
+ # ===== Creating a Rio that refers to a temporary object
151
+ #
152
+ # To create a temporary object that will become a file (Tempfile)
153
+ # or a temporary directory, depending on how it is used.
133
154
  #
134
155
  # <tt>rio(??)</tt> (mnemonic: '?' you don't know its name)
156
+ #
157
+ # <tt>rio(:temp)</tt>
158
+ #
159
+ # The following are also supported, to specify file or directory
160
+ #
161
+ # <tt>rio(:tempfile)</tt>
162
+ #
163
+ # <tt>rio(:tempdir)</tt>
164
+ #
135
165
  # rio(??)
136
166
  # rio(??,basename='rio',tmpdir=Dir::tmpdir)
137
167
  #
@@ -145,8 +175,6 @@ module RIO
145
175
  # or just write to it.
146
176
  #
147
177
  # To force it to become a directory:
148
- # rio(??).dir
149
- # or
150
178
  # rio(??).mkdir
151
179
  # or
152
180
  # rio(??).chdir
@@ -154,19 +182,22 @@ module RIO
154
182
  #
155
183
  # ===== Creating a Rio that refers to an arbitrary TCPSocket
156
184
  #
157
- # rio('tcp:',hostname,port)
158
- # or
159
- # rio('tcp://hostname:port')
185
+ # <tt>rio('tcp:',hostname,port)</tt>
186
+ #
187
+ # <tt>rio('tcp://hostname:port')</tt>
188
+ #
189
+ # <tt>rio(:tcp,hostname,port)</tt>
160
190
  #
161
191
  # ===== Creating a Rio that runs an external program and connects to its stdin and stdout
162
192
  #
163
193
  # <tt>rio(?-,cmd)</tt> (mnemonic: '-' is used by some Unix programs to specify stdin or stdout in place of a file)
164
194
  #
165
- # or
166
- #
167
195
  # <tt>rio(?`,cmd)</tt> (mnemonic: '`' (backtick) runs an external program in ruby)
168
196
  #
197
+ # <tt>rio(:cmdio,cmd)</tt>
198
+ #
169
199
  # This is Rio's interface to IO#popen
200
+ #
170
201
  def rio(*args,&block) # :yields: self
171
202
  Rio.rio(*args,&block)
172
203
  end