class RSpec::Core::Bisect::Channel

Wraps a pipe to support sending objects between a child and parent process. Where supported, encoding is explicitly set to ensure binary data is able to pass from child to parent. @private

Constants

MARSHAL_DUMP_ENCODING

Public Class Methods

new() click to toggle source
# File lib/rspec/core/bisect/utilities.rb, line 41
def initialize
  @read_io, @write_io = IO.pipe

  if defined?(MARSHAL_DUMP_ENCODING) && IO.method_defined?(:set_encoding)
    # Ensure the pipe can send any content produced by Marshal.dump
    @write_io.set_encoding MARSHAL_DUMP_ENCODING
  end
end

Public Instance Methods

close() click to toggle source

rubocop:enable Security/MarshalLoad

# File lib/rspec/core/bisect/utilities.rb, line 62
def close
  @read_io.close
  @write_io.close
end
receive() click to toggle source

rubocop:disable Security/MarshalLoad

# File lib/rspec/core/bisect/utilities.rb, line 56
def receive
  packet_size = Integer(@read_io.gets)
  Marshal.load(@read_io.read(packet_size))
end
send(message) click to toggle source
# File lib/rspec/core/bisect/utilities.rb, line 50
def send(message)
  packet = Marshal.dump(message)
  @write_io.write("#{packet.bytesize}\n#{packet}")
end