class ProcessExecuter::Destinations::Tee

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.

@api private

Attributes

child_destinations[R]

An array of child destinations

@return [Array<ProcessExecuter::Destinations::DestinationBase>]

An array of the child destination handlers

Public Class Methods

handles?(destination) click to toggle source

Determines if this class can handle the given destination

@param destination [Object] the destination to check @return [Boolean] true if destination is an Array in the form [:tee, destination…]

# File lib/process_executer/destinations/tee.rb, line 62
def self.handles?(destination)
  destination.is_a?(Array) && destination.size > 1 && destination[0] == :tee
end
new(destination) click to toggle source

Initializes a destination handler for writing to multiple output destinations

@param destination [Array<Symbol, Object…>] array in the form [:tee, destination…]

@raise [ArgumentError] if a child destination is invalid or incompatible

# File lib/process_executer/destinations/tee.rb, line 20
def initialize(destination)
  super
  @child_destinations = destination[1..].map { |dest| ProcessExecuter::Destinations.factory(dest) }
end

Public Instance Methods

close() click to toggle source

Closes the child_destinations

@return [void]

# File lib/process_executer/destinations/tee.rb, line 54
def close
  child_destinations.each(&:close)
end
write(data) click to toggle source

Writes data each of the {child_destinations}

@example

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

@param data [String] the data to write

@return [Integer] the number of bytes in the input data (which is written to each destination)

@raise [IOError] if the file is closed

# File lib/process_executer/destinations/tee.rb, line 45
def write(data)
  super
  child_destinations.each { |dest| dest.write(data) }
  data.bytesize
end