Module: ProcessExecuter::Destinations

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/child_redirection.rb,
lib/process_executer/destinations/file_path_mode_perms.rb

Overview

Collection of destination handler implementations

Defined Under Namespace

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

Class Method Summary collapse

Class Method Details

.compatible_with_monitored_pipe?(destination) ⇒ Boolean?

Determines if the given destination is compatible with a monitored pipe

If true, this destination should not be wrapped in a monitored pipe.

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, nil)

    true if the destination is compatible with a monitored pipe

Raises:

  • (ArgumentError)

    if no matching destination class is found



52
53
54
55
# File 'lib/process_executer/destinations.rb', line 52

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

.factory(destination) ⇒ DestinationBase

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.destination_factory(1) #=> Returns a Stdout instance
ProcessExecuter.destination_factory("output.log") #=> Returns a FilePath instance

Parameters:

  • destination (Object)

    the destination to create a handler for

Returns:

Raises:

  • (ArgumentError)

    if no matching destination class is found



32
33
34
35
36
37
# File 'lib/process_executer/destinations.rb', line 32

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

  raise ArgumentError, 'wrong exec redirect action'
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)

    the destination class that can handle the given destination



61
62
63
64
65
66
67
68
# File 'lib/process_executer/destinations.rb', line 61

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

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