Class: Bard::Backup

Inherits:
Object
  • Object
show all
Defined in:
lib/bard/backup.rb,
lib/bard/backup/s3_dir.rb,
lib/bard/backup/deleter.rb,
lib/bard/backup/railtie.rb,
lib/bard/backup/version.rb,
lib/bard/backup/destination.rb,
lib/bard/backup/latest_finder.rb,
lib/bard/backup/local_backhoe.rb,
lib/bard/backup/cached_local_backhoe.rb,
lib/bard/backup/destination/s3_destination.rb,
lib/bard/backup/destination/upload_destination.rb

Defined Under Namespace

Classes: CachedLocalBackhoe, Deleter, Destination, Error, LatestFinder, LocalBackhoe, NotFound, Railtie, S3Destination, S3Dir, UploadDestination

Constant Summary collapse

VERSION =
"0.9.1"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(timestamp:, size: nil, destinations: []) ⇒ Backup

Returns a new instance of Backup.



32
33
34
35
36
# File 'lib/bard/backup.rb', line 32

def initialize(timestamp:, size: nil, destinations: [])
  @timestamp = timestamp
  @size = size
  @destinations = destinations
end

Instance Attribute Details

#destinationsObject (readonly)

Returns the value of attribute destinations.



30
31
32
# File 'lib/bard/backup.rb', line 30

def destinations
  @destinations
end

#sizeObject (readonly)

Returns the value of attribute size.



30
31
32
# File 'lib/bard/backup.rb', line 30

def size
  @size
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



30
31
32
# File 'lib/bard/backup.rb', line 30

def timestamp
  @timestamp
end

Class Method Details

.create!(destination_hashes = nil, **config) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/bard/backup.rb', line 7

def self.create!(destination_hashes = nil, **config)
  if destination_hashes.nil? && !config.empty?
    destination_hashes = [config]
  end
  destination_hashes ||= Bard::Config.current.backup.destinations

  destinations = if destination_hashes.is_a?(Hash)
    [destination_hashes]
  else
    Array(destination_hashes)
  end

  result = nil
  destinations.each do |hash|
    result = Destination.build(hash).call
  end
  result
end

.latestObject



26
27
28
# File 'lib/bard/backup.rb', line 26

def self.latest
  LatestFinder.new.call
end

Instance Method Details

#as_jsonObject



38
39
40
41
42
43
44
# File 'lib/bard/backup.rb', line 38

def as_json(*)
  {
    timestamp: timestamp&.iso8601,
    size: size,
    destinations: destinations
  }.compact
end