class ProcessExecuter::Destinations::FilePath

Handles file path destinations

@api private

Attributes

file[R]

The opened file object

@return [File] the opened file

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 a String

# File lib/process_executer/destinations/file_path.rb, line 57
def self.handles?(destination)
  destination.is_a? String
end
new(destination) click to toggle source

Initializes a new file path destination handler

Redirects to the file at destination via ‘open(destination, ’w’, 0644)‘

@param destination [String] the file path to write to

@raise [Errno::ENOENT] if the file path is invalid

# File lib/process_executer/destinations/file_path.rb, line 19
def initialize(destination)
  super
  @file = File.open(destination, 'w', 0o644)
end

Public Instance Methods

close() click to toggle source

Closes the file if it’s open

@return [void]

# File lib/process_executer/destinations/file_path.rb, line 49
def close
  file.close unless file.closed?
end
write(data) click to toggle source

Writes data to the file

@example

file_handler = ProcessExecuter::Destinations::FilePath.new("output.log")
file_handler.write("Log entry")

@param data [String] the data to write

@return [Integer] the number of bytes written

@raise [IOError] if the file is closed

# File lib/process_executer/destinations/file_path.rb, line 41
def write(data)
  super
  file.write data
end