Class: RosettAi::Backup::Compressor

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/backup/compressor.rb

Overview

Factory and base for compression handlers

Direct Known Subclasses

TarGzCompressor, TarXzCompressor, ZipCompressor

Constant Summary collapse

ALGORITHMS =
['zip', 'tar.gz', 'tar.xz'].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for(algorithm) ⇒ Compressor

Returns a compressor instance for the given algorithm.

Parameters:

  • algorithm (String)

    one of 'zip', 'tar.gz', 'tar.xz'

Returns:

Raises:



21
22
23
24
25
26
27
28
29
30
# File 'lib/rosett_ai/backup/compressor.rb', line 21

def self.for(algorithm)
  case algorithm
  when 'zip' then ZipCompressor.new
  when 'tar.gz' then TarGzCompressor.new
  when 'tar.xz' then TarXzCompressor.new
  else
    raise RosettAi::BackupError,
          "Unknown compression algorithm: #{algorithm}. Supported: #{ALGORITHMS.join(', ')}"
  end
end

Instance Method Details

#available?Boolean

This method is abstract.

Subclasses must implement this method.

Whether the compression tool is available on this system.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


36
37
38
# File 'lib/rosett_ai/backup/compressor.rb', line 36

def available?
  raise NotImplementedError
end

#compress(files, base_dirs, output_path, level: nil) ⇒ String

This method is abstract.

Subclasses must implement this method.

Compresses files into an archive at +output_path+.

Parameters:

  • files (Array<Hash>)

    entries with :full_path and :archive_path keys

  • base_dirs (Array<String>)

    base directories for relative path resolution

  • output_path (String)

    destination path for the archive

  • level (Integer, nil) (defaults to: nil)

    compression level (algorithm-specific; nil for default)

Returns:

  • (String)

    the output path

Raises:

  • (NotImplementedError)


55
56
57
# File 'lib/rosett_ai/backup/compressor.rb', line 55

def compress(files, base_dirs, output_path, level: nil)
  raise NotImplementedError
end

#extensionString

File extension for archives produced by this compressor.

Returns:

  • (String)

    file extension including the leading dot

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/rosett_ai/backup/compressor.rb', line 43

def extension
  raise NotImplementedError
end