Class: ServerBackups::OrderedBackupFileCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/server_backups/ordered_backup_file_collection.rb

Constant Summary collapse

INCREMENTAL =
/incremental/i

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s3_collection) ⇒ OrderedBackupFileCollection

Returns a new instance of OrderedBackupFileCollection.



6
7
8
# File 'lib/server_backups/ordered_backup_file_collection.rb', line 6

def initialize(s3_collection)
    @s3_collection = s3_collection
end

Instance Attribute Details

#s3_collectionObject (readonly)

Returns the value of attribute s3_collection.



5
6
7
# File 'lib/server_backups/ordered_backup_file_collection.rb', line 5

def s3_collection
  @s3_collection
end

Instance Method Details

#full_backup_for(restore_point) ⇒ Object



10
11
12
13
14
# File 'lib/server_backups/ordered_backup_file_collection.rb', line 10

def full_backup_for(restore_point)
    sorted(full_backups).reverse.find do |file|
        get_timestamp_from_s3_object(file) <= restore_point
    end
end

#full_backupsObject



21
22
23
# File 'lib/server_backups/ordered_backup_file_collection.rb', line 21

def full_backups
    s3_collection.reject { |file| INCREMENTAL =~ file.key }
end

#incremental_backupsObject



25
26
27
28
# File 'lib/server_backups/ordered_backup_file_collection.rb', line 25

def incremental_backups
    @incremental_backups ||=
        sorted(s3_collection.select { |file| INCREMENTAL =~ file.key }).to_a
end

#incremental_backups_for(restore_point) ⇒ Object



16
17
18
# File 'lib/server_backups/ordered_backup_file_collection.rb', line 16

def incremental_backups_for(restore_point)
    sorted eligible_incremental_backups(restore_point)
end