Class: Courier::Internal::Util::ReadIOAdapter Private

Inherits:
Object
  • Object
show all
Defined in:
lib/courier/internal/util.rb,
sig/courier/internal/util.rbs

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

An adapter that satisfies the IO interface required by ::IO.copy_stream

Instance Method Summary collapse

Constructor Details

#initialize(src, &blk) {|| ... } ⇒ ReadIOAdapter

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ReadIOAdapter.

Parameters:

  • src (String, Pathname, StringIO, Enumerable<String>)
  • blk (Proc)

Yield Parameters:

  • (String)


485
486
487
488
489
490
491
492
493
494
495
496
497
498
# File 'lib/courier/internal/util.rb', line 485

def initialize(src, &blk)
  @stream =
    case src
    in String
      StringIO.new(src)
    in Pathname
      @closing = true
      src.open(binmode: true)
    else
      src
    end
  @buf = String.new
  @blk = blk
end

Instance Method Details

#close ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.



427
428
429
430
431
432
433
434
435
# File 'lib/courier/internal/util.rb', line 427

def close
  case @stream
  in Enumerator
    Courier::Internal::Util.close_fused!(@stream)
  in IO if close?
    @stream.close
  else
  end
end

#close? ⇒ Boolean?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean, nil)


424
# File 'lib/courier/internal/util.rb', line 424

def close? = @closing

#read(max_len = nil, out_string = nil) ⇒ String?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • max_len (Integer, nil) (defaults to: nil)
  • out_string (String, nil) (defaults to: nil)

Returns:

  • (String, nil)


461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
# File 'lib/courier/internal/util.rb', line 461

def read(max_len = nil, out_string = nil)
  case @stream
  in nil
    nil
  in IO | StringIO
    @stream.read(max_len, out_string)
  in Enumerator
    read = read_enum(max_len)
    case out_string
    in String
      out_string.replace(read)
    in nil
      read
    end
  end
    .tap(&@blk)
end