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
- #keep_on_month(date) ⇒ Object
- #keep_on_week(date) ⇒ Object
- #on_day?(date) ⇒ Boolean
- #on_month?(date) ⇒ Boolean
- #on_week?(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
70 71 72 |
# File 'lib/pg_s3_dumper/backup.rb', line 70 def basename File.basename(s3_object.key) end |
#delete ⇒ Object
57 58 59 60 |
# File 'lib/pg_s3_dumper/backup.rb', line 57 def delete puts "Deleting backup: #{self}" s3_object.delete end |
#id ⇒ Object
62 63 64 |
# File 'lib/pg_s3_dumper/backup.rb', line 62 def id @id ||= s3_object.['backup_id'] end |
#keep_on_day(date) ⇒ Object
37 38 39 |
# File 'lib/pg_s3_dumper/backup.rb', line 37 def keep_on_day(date) @keep = true if on_day?(date) end |
#keep_on_month(date) ⇒ Object
45 46 47 |
# File 'lib/pg_s3_dumper/backup.rb', line 45 def keep_on_month(date) @keep = true if on_month?(date) end |
#keep_on_week(date) ⇒ Object
41 42 43 |
# File 'lib/pg_s3_dumper/backup.rb', line 41 def keep_on_week(date) @keep = true if on_week?(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 |
#on_month?(date) ⇒ Boolean
33 34 35 |
# File 'lib/pg_s3_dumper/backup.rb', line 33 def on_month?(date) ts.strftime('%Y-%m') == date.strftime('%Y-%m') end |
#on_week?(date) ⇒ Boolean
29 30 31 |
# File 'lib/pg_s3_dumper/backup.rb', line 29 def on_week?(date) ts.strftime('%Y-%U') == date.strftime('%Y-%U') end |
#prune ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/pg_s3_dumper/backup.rb', line 49 def prune if keep puts "Keeping backup: #{self}" else delete end end |
#short_id ⇒ Object
66 67 68 |
# File 'lib/pg_s3_dumper/backup.rb', line 66 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 |