Class: Bard::Backup::LatestFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/bard/backup/latest_finder.rb

Instance Method Summary collapse

Instance Method Details

#callObject

Raises:



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bard/backup/latest_finder.rb', line 8

def call
  destinations = Bard::Config.current.backup.destinations.map do |hash|
    Destination.build(hash)
  end

  all_backups = destinations.flat_map do |dest|
    dest.s3_dir.files.filter_map do |filename|
      timestamp = parse_timestamp(filename)
      next unless timestamp

      { timestamp: timestamp, destination: dest, filename: filename }
    end
  end

  raise NotFound, "No backups found" if all_backups.empty?

  latest = all_backups.max_by { |b| b[:timestamp] }

  Bard::Backup.new(
    timestamp: latest[:timestamp],
    size: get_file_size(latest[:destination].s3_dir, latest[:filename]),
    destinations: all_backups
      .select { |b| b[:timestamp] == latest[:timestamp] }
      .map { |b| b[:destination].info }
  )
end