Class: ProcessExecuter::Destinations::Tee Private

Inherits:
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 a 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 DestinationBase

#destination

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from DestinationBase

compatible_with_monitored_pipe?, #compatible_with_monitored_pipe?

Constructor Details

#initialize(destination) ⇒ Tee

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 destination handler for writing to multiple output destinations

Parameters:

  • destination (Array<Symbol, Object...>)

    array in the form [:tee, destination...]

Raises:

  • (ArgumentError)

    if a child destination is invalid or incompatible



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_destinationsArray<ProcessExecuter::Destinations::DestinationBase> (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.

An array of child destinations

Returns:



30
31
32
# File 'lib/process_executer/destinations/tee.rb', line 30

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 in the form [:tee, destination...]



62
63
64
# File 'lib/process_executer/destinations/tee.rb', line 62

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 child_destinations



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

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 each of the #child_destinations

Examples:

tee = ProcessExecuter::Destinations::Tee.new([:tee, "output1.log", "output2.log"])
tee.write("Log entry with specific permissions")
tee.close # Important to close the tee to ensure all data is flushed

Parameters:

  • data (String)

    the data to write

Returns:

  • (Integer)

    the number of bytes in the input data (which is written to each destination)

Raises:

  • (IOError)

    if the file is closed



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

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