Class: Backup
Instance Attribute Summary collapse
-
#keep ⇒ Object
readonly
Returns the value of attribute keep.
-
#s3_object ⇒ Object
readonly
Returns the value of attribute s3_object.
-
#ts ⇒ Object
readonly
Returns the value of attribute ts.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #basename ⇒ Object
- #delete ⇒ Object
- #id ⇒ Object
-
#initialize(s3_object) ⇒ Backup
constructor
A new instance of Backup.
- #keep_on_day(date) ⇒ Object
- #on_day?(date) ⇒ Boolean
- #prune ⇒ Object
- #short_id ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(s3_object) ⇒ Backup
Returns a new instance of Backup.
15 16 17 18 19 |
# File 'lib/pg_s3_dumper/backup.rb', line 15 def initialize(s3_object) @s3_object = s3_object @ts = Time.parse(s3_object.key.split('/').last) @keep = false end |
Instance Attribute Details
#keep ⇒ Object (readonly)
Returns the value of attribute keep.
9 10 11 |
# File 'lib/pg_s3_dumper/backup.rb', line 9 def keep @keep end |
#s3_object ⇒ Object (readonly)
Returns the value of attribute s3_object.
9 10 11 |
# File 'lib/pg_s3_dumper/backup.rb', line 9 def s3_object @s3_object end |
#ts ⇒ Object (readonly)
Returns the value of attribute ts.
9 10 11 |
# File 'lib/pg_s3_dumper/backup.rb', line 9 def ts @ts end |
Class Method Details
.generate_id ⇒ Object
3 4 5 |
# File 'lib/pg_s3_dumper/backup.rb', line 3 def self.generate_id SecureRandom.hex(32) end |
Instance Method Details
#<=>(other) ⇒ Object
11 12 13 |
# File 'lib/pg_s3_dumper/backup.rb', line 11 def <=>(other) ts <=> other.ts end |
#basename ⇒ Object
54 55 56 |
# File 'lib/pg_s3_dumper/backup.rb', line 54 def basename File.basename(s3_object.key) end |
#delete ⇒ Object
41 42 43 44 |
# File 'lib/pg_s3_dumper/backup.rb', line 41 def delete puts "Deleting backup: #{self}" s3_object.delete end |
#id ⇒ Object
46 47 48 |
# File 'lib/pg_s3_dumper/backup.rb', line 46 def id @id ||= s3_object.['backup_id'] end |
#keep_on_day(date) ⇒ Object
29 30 31 |
# File 'lib/pg_s3_dumper/backup.rb', line 29 def keep_on_day(date) @keep = true if on_day?(date) end |
#on_day?(date) ⇒ Boolean
25 26 27 |
# File 'lib/pg_s3_dumper/backup.rb', line 25 def on_day?(date) ts.strftime('%F') == date.strftime('%F') end |
#prune ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/pg_s3_dumper/backup.rb', line 33 def prune if keep puts "Keeping backup: #{self}" else delete end end |
#short_id ⇒ Object
50 51 52 |
# File 'lib/pg_s3_dumper/backup.rb', line 50 def short_id id[0..8] end |
#to_s ⇒ Object
21 22 23 |
# File 'lib/pg_s3_dumper/backup.rb', line 21 def to_s "id: #{short_id}, key: #{basename}" end |