Ragex.Editor.Backup (Ragex v0.12.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

cleanup(path, opts \\ [])

@spec cleanup(
  String.t(),
  keyword()
) :: {:ok, non_neg_integer()} | {:error, term()}

Cleans up old backups for a file.

Parameters

  • path: Path to the file
  • opts: Options
    • :backup_dir - Custom backup directory (optional)
    • :keep - Number of backups to keep (default: 10)

Returns

Number of backups deleted.

create(path, opts \\ [])

@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 backup
  • opts: 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", ...}}

list(path, opts \\ [])

@spec list(
  String.t(),
  keyword()
) :: {:ok, [Ragex.Editor.Types.backup_info()]} | {:error, term()}

Lists all backups for a file.

Parameters

  • path: Path to the file
  • opts: 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).

restore(path, backup_id \\ nil, opts \\ [])

@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 restore
  • backup_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

total_size(path, opts \\ [])

@spec total_size(
  String.t(),
  keyword()
) :: {:ok, non_neg_integer()} | {:error, term()}

Gets the total size of all backups for a file.