Class: IOPipe

Inherits:
Object show all
Defined in:
lib/objective_command/datas/pipe.rb

Overview

Author

Nicolas Pouillard <[email protected]>.

Copyright

Copyright © 2005, 2006 Nicolas Pouillard. All rights reserved.

License

GNU General Public License (GPL).

Revision

$Id: /w/fey/cmd/trunk/lib/objective_command/datas/pipe.rb 24389 2006-07-09T20:37:31.813443Z ertai $

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeIOPipe

Returns a new instance of IOPipe.



8
9
10
11
# File 'lib/objective_command/datas/pipe.rb', line 8

def initialize
  @reader, @writer = IO.pipe
  @open_mode = :w
end

Instance Attribute Details

#open_modeObject

Returns the value of attribute open_mode.



7
8
9
# File 'lib/objective_command/datas/pipe.rb', line 7

def open_mode
  @open_mode
end

#readerObject

Returns the value of attribute reader.



7
8
9
# File 'lib/objective_command/datas/pipe.rb', line 7

def reader
  @reader
end

#writerObject

Returns the value of attribute writer.



7
8
9
# File 'lib/objective_command/datas/pipe.rb', line 7

def writer
  @writer
end

Instance Method Details

#closeObject Also known as: clean



23
24
25
26
# File 'lib/objective_command/datas/pipe.rb', line 23

def close
  @reader.close unless @reader.closed?
  @writer.close unless @writer.closed?
end

#each_line(&block) ⇒ Object



31
32
33
# File 'lib/objective_command/datas/pipe.rb', line 31

def each_line &block
  open.each_line(&block)
end

#open(mode = :r) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/objective_command/datas/pipe.rb', line 12

def open ( mode=:r )
  case mode.to_sym
    when :r
      @writer.close
      @reader
    when :w
      @reader.close
      @writer
    else raise ArgumentError, "Bad open mode: #{mode.inspect}"
  end
end

#readObject



34
35
36
# File 'lib/objective_command/datas/pipe.rb', line 34

def read
  open.read
end

#to_io_for_ocmdObject



28
29
30
# File 'lib/objective_command/datas/pipe.rb', line 28

def to_io_for_ocmd
  open(open_mode)
end