Class: ProcessExecuter::Destinations::FilePathMode Private

Inherits:
DestinationBase show all
Defined in:
lib/process_executer/destinations/file_path_mode.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 file paths with specific open modes

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) ⇒ FilePathMode

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 destination handler

Redirects to the file at destination via open(destination[0], destination[1], 0644)

Parameters:

  • destination (Array<String, String>)

    array with file path and mode

Raises:

  • (Errno::ENOENT)

    if the file path is invalid

  • (ArgumentError)

    if the mode is invalid



18
19
20
21
# File 'lib/process_executer/destinations/file_path_mode.rb', line 18

def initialize(destination)
  super
  @file = File.open(destination[0], destination[1], 0o644)
end

Instance Attribute Details

#fileFile (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



26
27
28
# File 'lib/process_executer/destinations/file_path_mode.rb', line 26

def file
  @file
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 and mode



56
57
58
59
60
61
# File 'lib/process_executer/destinations/file_path_mode.rb', line 56

def self.handles?(destination)
  destination.is_a?(Array) &&
    destination.size == 2 &&
    destination[0].is_a?(String) &&
    destination[1].is_a?(String)
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



48
49
50
# File 'lib/process_executer/destinations/file_path_mode.rb', line 48

def close
  file.close unless file.closed?
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:

mode_handler = ProcessExecuter::Destinations::FilePathMode.new(["output.log", "a"])
mode_handler.write("Appended log entry")

Parameters:

  • data (String)

    the data to write

Returns:

  • (Integer)

    the number of bytes written

Raises:

  • (IOError)

    if the file is closed



40
41
42
43
# File 'lib/process_executer/destinations/file_path_mode.rb', line 40

def write(data)
  super
  file.write data
end