Class: Croaky::IO::IoStream

Inherits:
Object
  • Object
show all
Includes:
IoCapturable
Defined in:
lib/croaky/io/io_stream.rb

Overview

IO adapter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdout_stream, stderr_stream) ⇒ IoStream

Returns a new instance of IoStream.



13
14
15
16
# File 'lib/croaky/io/io_stream.rb', line 13

def initialize(stdout_stream, stderr_stream)
  @stdout_stream = stdout_stream
  @stderr_stream = stderr_stream
end

Instance Attribute Details

#stderr_streamObject (readonly)

Returns the value of attribute stderr_stream.



11
12
13
# File 'lib/croaky/io/io_stream.rb', line 11

def stderr_stream
  @stderr_stream
end

#stdout_streamObject (readonly)

Returns the value of attribute stdout_stream.



11
12
13
# File 'lib/croaky/io/io_stream.rb', line 11

def stdout_stream
  @stdout_stream
end

Instance Method Details

#capture_ioObject



18
19
20
21
# File 'lib/croaky/io/io_stream.rb', line 18

def capture_io
  stdout_stream.capture_io
  stderr_stream.capture_io
end

#read_captured_ioObject



28
29
30
31
# File 'lib/croaky/io/io_stream.rb', line 28

def read_captured_io
  captured = [stdout_stream.read_captured_io, stderr_stream.read_captured_io]
  captured.flatten.reject { |s| s.to_s.empty? }.join($INPUT_RECORD_SEPARATOR)
end

#restore_ioObject



23
24
25
26
# File 'lib/croaky/io/io_stream.rb', line 23

def restore_io
  stdout_stream.restore_io
  stderr_stream.restore_io
end