class ProcessExecuter::Destinations::FilePathModePerms
Handles file paths with specific open modes and permissions
@api private
Attributes
The opened file object
@return [File] the opened file
Public Class Methods
Source
# File lib/process_executer/destinations/file_path_mode_perms.rb, line 59 def self.handles?(destination) destination.is_a?(Array) && destination.size == 3 && destination[0].is_a?(String) && destination[1].is_a?(String) && destination[2].is_a?(Integer) end
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, mode, and permissions
Source
# File lib/process_executer/destinations/file_path_mode_perms.rb, line 21 def initialize(destination) super @file = File.open(destination[0], destination[1], destination[2]) end
Initializes a new file path with mode and permissions destination handler
Opens the file at the given path with the specified mode and permissions.
@param destination [Array<String, String, Integer>] array with file path, mode, and permissions
@raise [Errno::ENOENT] if the file path is invalid
@raise [ArgumentError] if the mode is invalid
ProcessExecuter::Destinations::DestinationBase::new
Public Instance Methods
Source
# File lib/process_executer/destinations/file_path_mode_perms.rb, line 51 def close file.close unless file.closed? end
Closes the file if it’s open
@return [void]
Source
# File lib/process_executer/destinations/file_path_mode_perms.rb, line 43 def write(data) super file.write data end
Writes data to the file
@example
perms_handler = ProcessExecuter::Destinations::FilePathModePerms.new(["output.log", "w", 0644]) perms_handler.write("Log entry with specific permissions")
@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