class ProcessExecuter::Destinations::FileDescriptor

Handles numeric file descriptors

@api private

Public Class Methods

handles?(destination) click to toggle source

Determines if this class can handle the given destination

@param destination [Object] the destination to check

@return [Boolean] true if destination is a file descriptor that’s not stdout or stderr

# File lib/process_executer/destinations/file_descriptor.rb, line 35
def self.handles?(destination)
  destination.is_a?(Integer) && ![1, 2].include?(destination)
end

Public Instance Methods

write(data) click to toggle source

Writes data to the file descriptor

@param data [String] the data to write

@return [Integer] the number of bytes written

@raise [SystemCallError] if the file descriptor is invalid

@example

fd_handler = ProcessExecuter::Destinations::FileDescriptor.new(3)
fd_handler.write("Hello world")
# File lib/process_executer/destinations/file_descriptor.rb, line 23
def write(data)
  super
  io = ::IO.open(destination, mode: 'a', autoclose: false)
  io.write(data).tap { io.close }
end