Ragex.Editor.Backup
(Ragex v0.8.0)
View Source
Backup management for file editing operations.
Creates, lists, and restores backups of files before editing. Backups are stored in a project-specific directory with timestamps.
Summary
Functions
Cleans up old backups for a file.
Creates a backup of a file.
Lists all backups for a file.
Restores a file from a backup.
Gets the total size of all backups for a file.
Functions
@spec cleanup( String.t(), keyword() ) :: {:ok, non_neg_integer()} | {:error, term()}
Cleans up old backups for a file.
Parameters
path: Path to the fileopts: Options:backup_dir- Custom backup directory (optional):keep- Number of backups to keep (default: 10)
Returns
Number of backups deleted.
@spec create( String.t(), keyword() ) :: {:ok, Ragex.Editor.Types.backup_info()} | {:error, term()}
Creates a backup of a file.
Parameters
path: Path to the file to backupopts: Options:backup_dir- Custom backup directory (optional):compress- Compress backup with gzip (default: false)
Returns
{:ok, backup_info}on success{:error, reason}on failure
Examples
iex> Backup.create("/path/to/file.ex")
{:ok, %{id: "20240101_120000_abc123", ...}}
@spec list( String.t(), keyword() ) :: {:ok, [Ragex.Editor.Types.backup_info()]} | {:error, term()}
Lists all backups for a file.
Parameters
path: Path to the fileopts: Options:backup_dir- Custom backup directory (optional):limit- Maximum number of backups to return (default: 10)
Returns
List of backup info structs, sorted by creation time (newest first).
@spec restore(String.t(), String.t() | nil, keyword()) :: {:ok, Ragex.Editor.Types.backup_info()} | {:error, term()}
Restores a file from a backup.
Parameters
path: Path to the file to restorebackup_id: ID of the backup to restore (if nil, restores most recent)opts: Options:backup_dir- Custom backup directory (optional):delete_backup- Delete backup after restore (default: false)
Returns
{:ok, backup_info}on success{:error, reason}on failure
@spec total_size( String.t(), keyword() ) :: {:ok, non_neg_integer()} | {:error, term()}
Gets the total size of all backups for a file.