Class: RosettAi::Backup::Destination

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

Overview

Base class for backup destinations

Direct Known Subclasses

FileDestination, UnsupportedDestination

Constant Summary collapse

SUPPORTED_SCHEMES =
['file', 's3', 'ssh', 'bup', 'https'].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Destination

Returns a new instance of Destination.



14
15
16
# File 'lib/rosett_ai/backup/destination.rb', line 14

def initialize(uri)
  @uri = uri
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



12
13
14
# File 'lib/rosett_ai/backup/destination.rb', line 12

def uri
  @uri
end

Class Method Details

.for(destination_string) ⇒ Destination

Returns a destination instance for the given URI string.

Parameters:

  • destination_string (String)

    URI (e.g. "file:///tmp/backup.zip")

Returns:

  • (Destination)

    a FileDestination or UnsupportedDestination



31
32
33
34
35
36
37
38
39
40
# File 'lib/rosett_ai/backup/destination.rb', line 31

def self.for(destination_string)
  scheme, path = parse_scheme(destination_string)

  case scheme
  when 'file'
    FileDestination.new(path)
  else
    UnsupportedDestination.new(scheme, path)
  end
end

.parse_scheme(destination_string) ⇒ Array(String, String)

Splits a destination string into scheme and path components.

Parameters:

  • destination_string (String)

    URI or bare path

Returns:

  • (Array(String, String))

    scheme and path (defaults to "file" scheme)



46
47
48
49
50
51
52
53
# File 'lib/rosett_ai/backup/destination.rb', line 46

def self.parse_scheme(destination_string)
  if destination_string.match?(%r{^[a-z][a-z0-9+\-.]*://})
    scheme, path = destination_string.split('://', 2)
    [scheme, path]
  else
    ['file', destination_string]
  end
end

Instance Method Details

#write(archive_path) ⇒ String

This method is abstract.

Subclasses must implement this method.

Writes the archive to this destination.

Parameters:

  • archive_path (String)

    path to the archive file to write

Returns:

  • (String)

    final destination path

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/rosett_ai/backup/destination.rb', line 23

def write(archive_path)
  raise NotImplementedError, "#{self.class}#write not implemented"
end