Class: Backupsss::BackupBucket

Inherits:
Object
  • Object
show all
Defined in:
lib/backupsss/backup_bucket.rb

Overview

A class for listing and sorting files in an s3 bucket

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ BackupBucket

Returns a new instance of BackupBucket.



8
9
10
11
# File 'lib/backupsss/backup_bucket.rb', line 8

def initialize(opts = {})
  @dir    = opts[:dir]
  @region = opts[:region]
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



6
7
8
# File 'lib/backupsss/backup_bucket.rb', line 6

def dir
  @dir
end

#regionObject (readonly)

Returns the value of attribute region.



6
7
8
# File 'lib/backupsss/backup_bucket.rb', line 6

def region
  @region
end

Instance Method Details

#lsObject



13
14
15
# File 'lib/backupsss/backup_bucket.rb', line 13

def ls
  list_objects.map(&:key)
end

#ls_rtObject



21
22
23
# File 'lib/backupsss/backup_bucket.rb', line 21

def ls_rt
  ls_t.reverse
end

#ls_tObject



17
18
19
# File 'lib/backupsss/backup_bucket.rb', line 17

def ls_t
  list_objects.sort_by(&:last_modified).map(&:key)
end

#rm(file) ⇒ Object



25
26
27
28
# File 'lib/backupsss/backup_bucket.rb', line 25

def rm(file)
  s3_client.delete_object(bucket: bucket, key: file)
  file
end