Class: ProcessExecuter::Destinations::Tee Private

Inherits:
ProcessExecuter::DestinationBase show all
Defined in:
lib/process_executer/destinations/tee.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 destination for writing to multiple destinations

The destination is an array with the first element being :tee and the rest being the destinations.

Instance Attribute Summary collapse

Attributes inherited from ProcessExecuter::DestinationBase

#data_written, #destination

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ProcessExecuter::DestinationBase

#compatible_with_monitored_pipe?, compatible_with_monitored_pipe?, #string

Constructor Details

#initialize(destination) ⇒ FilePathModePerms

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.

Initializes a new file path with mode and permissions destination handler

Opens the file at the given path with the specified mode and permissions.

Parameters:

  • destination (Array<String, String, Integer>)

    array with file path, mode, and permissions

Raises:

  • (Errno::ENOENT)

    if the file path is invalid

  • (ArgumentError)

    if the mode is invalid



20
21
22
23
# File 'lib/process_executer/destinations/tee.rb', line 20

def initialize(destination)
  super
  @child_destinations = destination[1..].map { |dest| ProcessExecuter::Destinations.factory(dest) }
end

Instance Attribute Details

#child_destinationsFile (readonly)

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.

The opened file object

Returns:

  • (File)

    the opened file



28
29
30
# File 'lib/process_executer/destinations/tee.rb', line 28

def child_destinations
  @child_destinations
end

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 Array with path, mode, and permissions



55
56
57
# File 'lib/process_executer/destinations/tee.rb', line 55

def self.handles?(destination)
  destination.is_a?(Array) && destination.size > 1 && destination[0] == :tee
end

Instance Method Details

#close

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.

This method returns an undefined value.

Closes the file if it's open



47
48
49
# File 'lib/process_executer/destinations/tee.rb', line 47

def close
  child_destinations.each(&:close)
end

#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

Examples:

perms_handler = ProcessExecuter::Destinations::FilePathModePerms.new(["output.log", "w", 0644])
perms_handler.write("Log entry with specific permissions")

Parameters:

  • data (String)

    the data to write

Returns:

  • (Integer)

    the number of bytes written

Raises:

  • (IOError)

    if the file is closed



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

def write(data)
  super
  child_destinations.each { |dest| dest.write(data) }
end