Class: ProcessExecuter::Destinations::FileDescriptor Private

Inherits:
ProcessExecuter::DestinationBase show all
Defined in:
lib/process_executer/destinations/file_descriptor.rb

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.

Handles numeric file descriptors

Instance Attribute Summary

Attributes inherited from ProcessExecuter::DestinationBase

#data_written, #destination

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ProcessExecuter::DestinationBase

#close, #compatible_with_monitored_pipe?, compatible_with_monitored_pipe?, #initialize, #string

Constructor Details

This class inherits a constructor from ProcessExecuter::DestinationBase

Class Method Details

.handles?(destination) ⇒ 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.

Determines if this class can handle the given destination

Parameters:

  • destination (Object)

    the destination to check

Returns:

  • (Boolean)

    true if destination is an Integer that's not stdout/stderr



31
32
33
# File 'lib/process_executer/destinations/file_descriptor.rb', line 31

def self.handles?(destination)
  destination.is_a?(Integer) && ![:out, 1, :err, 2].include?(destination)
end

Instance Method Details

#write(data) ⇒ Integer

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.

Writes data to the file descriptor

Examples:

fd_handler = ProcessExecuter::Destinations::FileDescriptor.new(3)
fd_handler.write("Hello world")

Parameters:

  • data (String)

    the data to write

Returns:

  • (Integer)

    the number of bytes written

Raises:

  • (SystemCallError)

    if the file descriptor is invalid



20
21
22
23
24
25
# File 'lib/process_executer/destinations/file_descriptor.rb', line 20

def write(data)
  super
  io = ::IO.open(destination, mode: 'a', autoclose: false)
  io.write(data)
  io.close
end