Module: ProcessExecuter::Destinations Private

Defined in:
lib/process_executer/destinations.rb,
lib/process_executer/destinations/io.rb,
lib/process_executer/destinations/tee.rb,
lib/process_executer/destinations/close.rb,
lib/process_executer/destinations/stderr.rb,
lib/process_executer/destinations/stdout.rb,
lib/process_executer/destinations/writer.rb,
lib/process_executer/destinations/file_path.rb,
lib/process_executer/destinations/file_path_mode.rb,
lib/process_executer/destinations/monitored_pipe.rb,
lib/process_executer/destinations/file_descriptor.rb,
lib/process_executer/destinations/destination_base.rb,
lib/process_executer/destinations/child_redirection.rb,
lib/process_executer/destinations/file_path_mode_perms.rb

Overview

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

Collection of destination handler implementations

Defined Under Namespace

Classes: ChildRedirection, Close, DestinationBase, FileDescriptor, FilePath, FilePathMode, FilePathModePerms, IO, MonitoredPipe, Stderr, Stdout, Tee, Writer

Class Method Summary collapse

Class Method Details

.compatible_with_monitored_pipe?(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 the given destination type can be managed by a MonitoredPipe

Returns true if MonitoredPipe can forward data to this destination type.

Returns false otherwise (e.g., for destinations like :close or [:child, fd] which have special meaning to Process.spawn and are not simply data sinks for MonitoredPipe).

Examples:

ProcessExecuter::Destinations.compatible_with_monitored_pipe?(1)
  #=> true
ProcessExecuter::Destinations.compatible_with_monitored_pipe?([:child, 6])
  #=> false
ProcessExecuter::Destinations.compatible_with_monitored_pipe?(:close)
  #=> false

Parameters:

  • destination (Object)

    the destination to check

Returns:

  • (Boolean)

    true if MonitoredPipe can forward data to this destination type



64
65
66
67
# File 'lib/process_executer/destinations.rb', line 64

def self.compatible_with_monitored_pipe?(destination)
  matching_class = matching_destination_class(destination)
  matching_class&.compatible_with_monitored_pipe?
end

.factory(destination) ⇒ ProcessExecuter::Destinations::DestinationBase

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.

Creates appropriate destination objects based on the given destination

This factory method dynamically finds and instantiates the appropriate destination class for handling the provided destination.

Examples:

ProcessExecuter::Destinations.factory(1) #=> Returns a Stdout instance
ProcessExecuter::Destinations.factory("output.log") #=> Returns a FilePath instance

Parameters:

  • destination (Object)

    the destination to create a handler for

Returns:

Raises:



37
38
39
40
41
42
# File 'lib/process_executer/destinations.rb', line 37

def self.factory(destination)
  matching_class = matching_destination_class(destination)
  return matching_class.new(destination) if matching_class

  raise ProcessExecuter::ArgumentError, "Destination #{destination.inspect} is not compatible with MonitoredPipe"
end

.matching_destination_class(destination) ⇒ Class?

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 the destination class that can handle the given destination

Parameters:

  • destination (Object)

    the destination to check

Returns:

  • (Class, nil)

    the handler class for the given destination or nil if no match



75
76
77
78
79
80
81
82
83
# File 'lib/process_executer/destinations.rb', line 75

def self.matching_destination_class(destination)
  destination_classes =
    ProcessExecuter::Destinations.constants
                                 .map { |const| ProcessExecuter::Destinations.const_get(const) }
                                 .select { |const| const.is_a?(Class) }
                                 .reject { |klass| klass == ProcessExecuter::Destinations::DestinationBase }

  destination_classes.find { |klass| klass.handles?(destination) }
end