public
Description: A process execution library which doesn't suck.
Clone URL: git://github.com/codahale/ropen.git
Search Repo:
Cleaned up Ropen::Pipe and added documentation.
codahale (author)
Thu May 15 16:42:16 -0700 2008
commit  386ba4504a20031f7308ed7a956a0287426abf4e
tree    590264bf3dbc230e0e4b12830b974bea4e208ea9
parent  949057c781d8444cc4d87c5dcf915b1a065d6e89
...
61
62
63
64
65
66
 
 
 
67
68
69
...
61
62
63
 
 
 
64
65
66
67
68
69
0
@@ -61,9 +61,9 @@
0
   end
0
   
0
   def redirect_streams
0
- @stdin.bind_input(STDIN)
0
- @stdout.bind_output(STDOUT)
0
- @stderr.bind_output(STDERR)
0
+ @stdin.bind_writer(STDIN)
0
+ @stdout.bind_reader(STDOUT)
0
+ @stderr.bind_reader(STDERR)
0
   end
0
   
0
   def process_streams(stdin, stdout, stderr, child_pid)
...
1
2
3
4
 
5
6
 
 
 
 
7
 
8
9
10
11
12
 
 
 
13
14
15
16
 
 
 
17
18
19
 
20
21
22
23
24
 
25
26
27
28
 
29
30
31
...
1
2
 
 
3
4
 
5
6
7
8
9
10
11
12
13
14
 
15
16
17
18
19
20
 
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
0
@@ -1,31 +1,41 @@
0
 require "ropen"
0
 
0
-# TODO: document me
0
-
0
+# A bidirectional IO pipe wrapper.
0
 class Ropen::Pipe
0
- attr_reader :reader, :writer
0
+ # An +IO+ instance from which the output of the pipe can be read.
0
+ attr_reader :reader
0
+ # An +IO+ instance to which the input of the pipe can be written.
0
+ attr_reader :writer
0
   
0
+ # Creates a new Ropen::Pipe with a unconnected +reader+ and +writer+.
0
   def initialize
0
     @reader, @writer = IO.pipe
0
   end
0
   
0
- def bind_output(stream)
0
+ # Binds the pipe's +reader+ to +stream+ and closes the +writer+ to make it a
0
+ # read-only pipe (e.g., +STDOUT+ or +STDERR+).
0
+ def bind_reader(stream)
0
     swap_streams(stream, @reader, @writer)
0
   end
0
   
0
- def bind_input(stream)
0
+ # Binds the pipe's +writer+ to +stream+ and closes the +reader+ to make it a
0
+ # write-only pipe (e.g., +STDIN+).
0
+ def bind_writer(stream)
0
     swap_streams(stream, @writer, @reader)
0
   end
0
   
0
+ # Closes both the +reader+ and +writer+, if either are open.
0
   def close
0
     close_reader
0
     close_writer
0
   end
0
   
0
+ # Closes the +reader+ if it is open.
0
   def close_reader
0
     @reader.close unless @reader.closed?
0
   end
0
   
0
+ # Closes the +writer+ if it is open.
0
   def close_writer
0
     @writer.close unless @writer.closed?
0
   end
...
22
23
24
25
 
26
27
28
...
30
31
32
33
 
34
35
36
...
22
23
24
 
25
26
27
28
...
30
31
32
 
33
34
35
36
0
@@ -22,7 +22,7 @@
0
     @pipe.reader.should_receive(:close)
0
     STDOUT.should_receive(:reopen).with(@pipe.writer)
0
     @pipe.writer.should_receive(:close)
0
- @pipe.bind_output(STDOUT)
0
+ @pipe.bind_reader(STDOUT)
0
   end
0
   
0
   it "should bind a reader to a stream" do
0
@@ -30,7 +30,7 @@
0
     STDIN.should_receive(:reopen).with(@pipe.reader)
0
     @pipe.reader.should_receive(:close)
0
     
0
- @pipe.bind_input(STDIN)
0
+ @pipe.bind_writer(STDIN)
0
   end
0
   
0
   it "should close the reader" do

Comments

    No one has commented yet.