class ProcessExecuter::Destinations::FilePathMode
Handles file paths with specific open modes
@api private
Attributes
The opened file object
@return [File] the opened file
Public Class Methods
Determines if this class can handle the given destination
@param destination [Object] the destination to check @return [Boolean] true if destination is an Array with path and mode
# 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
Initializes a new file path with mode destination handler
Redirects to the file at destination via ‘open(destination, destination, 0644)`
@param destination [Array<String, String>] array with file path and mode @raise [Errno::ENOENT] if the file path is invalid @raise [ArgumentError] if the mode is invalid
ProcessExecuter::Destinations::DestinationBase::new
# File lib/process_executer/destinations/file_path_mode.rb, line 18 def initialize(destination) super @file = File.open(destination[0], destination[1], 0o644) end
Public Instance Methods
Closes the file if it’s open
@return [void]
# File lib/process_executer/destinations/file_path_mode.rb, line 48 def close file.close unless file.closed? end
Writes data to the file
@example
mode_handler = ProcessExecuter::Destinations::FilePathMode.new(["output.log", "a"]) mode_handler.write("Appended log entry")
@param data [String] the data to write
@return [Integer] the number of bytes written
@raise [IOError] if the file is closed
ProcessExecuter::Destinations::DestinationBase#write
# File lib/process_executer/destinations/file_path_mode.rb, line 40 def write(data) super file.write data end