Class: IO::LikeHelpers::Pipeline

Inherits:
DelegatedIO show all
Defined in:
lib/io/like_helpers/pipeline.rb

Overview

This class creates a pipeline of streams necessary to satisfy the internal needs of IO::Like:

CharacterIO >> BufferedIO >> BlockingIO >> delegate

Each segment of the pipeline is directly accessible so that the methods of IO::Like may use them as necessary.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from DelegatedIO

#advise, #autoclose=, #autoclose?, #close, #close_on_exec=, #close_on_exec?, create_finalizer, #fcntl, #fdatasync, #fileno, #fsync, #inspect, #ioctl, #nonblock=, #nonblock?, #nread, #path, #pid, #pread, #pwrite, #read, #readable?, #ready?, #seek, #stat, #to_io, #tty?, #wait, #writable?, #write

Methods inherited from AbstractIO

#advise, #close, #close_on_exec=, #close_on_exec?, #closed?, #fcntl, #fdatasync, #fileno, #fsync, #ioctl, #nonblock, #nonblock=, #nonblock?, #nread, open, #path, #pid, #pread, #pwrite, #read, #readable?, #ready?, #seek, #stat, #to_io, #tty?, #wait, #writable?, #write

Constructor Details

#initialize(delegate, autoclose: true) ⇒ Pipeline

Creates a new intance of this class.

Parameters:

  • delegate (LikeHelpers::AbstractIO)

    a readable and/or writable stream

  • autoclose (Boolean) (defaults to: true)

    when ‘true` close the delegate when this stream is closed

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
32
33
# File 'lib/io/like_helpers/pipeline.rb', line 24

def initialize(
  delegate,
  autoclose: true
)
  raise ArgumentError, 'delegate cannot be nil' if delegate.nil?

  super(BufferedIO.new(BlockingIO.new(delegate, autoclose: autoclose)))

  @character_io = CharacterIO.new(buffered_io, blocking_io)
end

Instance Attribute Details

#character_ioObject (readonly)

A reference to the CharacterIO instance



49
50
51
# File 'lib/io/like_helpers/pipeline.rb', line 49

def character_io
  @character_io
end

Instance Method Details

#blocking_ioObject

Returns a reference to the BlockingIO delegate of the BufferedIO.

Returns:

  • a reference to the BlockingIO delegate of the BufferedIO



43
44
45
# File 'lib/io/like_helpers/pipeline.rb', line 43

def blocking_io
  buffered_io.delegate
end

#concrete_ioObject

Returns a reference to the original delegate given to the initializer of this stream.

Returns:

  • a reference to the original delegate given to the initializer of this stream



54
55
56
# File 'lib/io/like_helpers/pipeline.rb', line 54

def concrete_io
  blocking_io.delegate
end