Class: RosettAi::Backup::Destination
- Inherits:
-
Object
- Object
- RosettAi::Backup::Destination
- Defined in:
- lib/rosett_ai/backup/destination.rb
Overview
Base class for backup destinations
Direct Known Subclasses
Constant Summary collapse
- SUPPORTED_SCHEMES =
['file', 's3', 'ssh', 'bup', 'https'].freeze
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Class Method Summary collapse
-
.for(destination_string) ⇒ Destination
Returns a destination instance for the given URI string.
-
.parse_scheme(destination_string) ⇒ Array(String, String)
Splits a destination string into scheme and path components.
Instance Method Summary collapse
-
#initialize(uri) ⇒ Destination
constructor
A new instance of Destination.
-
#write(archive_path) ⇒ String
abstract
Writes the archive to this destination.
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
#uri ⇒ Object (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.
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.
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.
23 24 25 |
# File 'lib/rosett_ai/backup/destination.rb', line 23 def write(archive_path) raise NotImplementedError, "#{self.class}#write not implemented" end |