Class: BackupRetentionPlan

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

Overview

This class is used by call all of the events of the retention

Constant Summary collapse

RETENTION_PERIODS =
{
  'Beginner' => [42],
  'Pro' => [42, 12],
  'Ultra' => [42, 12, 7 * 365]
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plan) ⇒ BackupRetentionPlan

Returns a new instance of BackupRetentionPlan.



13
14
15
16
# File 'lib/backup_retention_plan.rb', line 13

def initialize(plan)
  @plan = plan
  @retention_periods = RETENTION_PERIODS[plan]
end

Class Method Details

.should_retain(plan, date) ⇒ Object



18
19
20
21
# File 'lib/backup_retention_plan.rb', line 18

def self.should_retain(plan, date)
  retention_plan = new(plan)
  retention_plan.should_retain(date)
end

Instance Method Details

#should_retain(date) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/backup_retention_plan.rb', line 23

def should_retain(date)
  snapshot_date = Date.strptime(date, '%Y/%m/%d')
  today = Date.today

  return true if within_retention_period(snapshot_date, today)

  @retention_periods[1..].each do |period|
    return snapshot_date.month == today.month if snapshot_date.year == today.year - period
  end

  false
end