Class: TarsnapPruner::Scheduler
- Inherits:
-
Object
- Object
- TarsnapPruner::Scheduler
- Defined in:
- lib/tarsnap_pruner/scheduler.rb
Instance Method Summary collapse
- #archives_to_prune ⇒ Object
- #dailies ⇒ Object
-
#initialize(archives, daily_boundary = 182, weekly_boundary = 730) ⇒ Scheduler
constructor
A new instance of Scheduler.
- #knowns ⇒ Object
- #monthlies ⇒ Object
- #monthlies_to_keep ⇒ Object
- #monthlies_to_prune ⇒ Object
- #unknowns ⇒ Object
- #weeklies ⇒ Object
- #weeklies_to_keep ⇒ Object
- #weeklies_to_prune ⇒ Object
Constructor Details
#initialize(archives, daily_boundary = 182, weekly_boundary = 730) ⇒ Scheduler
Returns a new instance of Scheduler.
5 6 7 8 9 |
# File 'lib/tarsnap_pruner/scheduler.rb', line 5 def initialize(archives, daily_boundary=182, weekly_boundary=730) @archives = archives @daily_boundary = daily_boundary @weekly_boundary = weekly_boundary end |
Instance Method Details
#archives_to_prune ⇒ Object
47 48 49 |
# File 'lib/tarsnap_pruner/scheduler.rb', line 47 def archives_to_prune unknowns + monthlies_to_prune + weeklies_to_prune end |
#dailies ⇒ Object
19 20 21 |
# File 'lib/tarsnap_pruner/scheduler.rb', line 19 def dailies knowns.select { |a| a.elapsed < @daily_boundary } end |
#knowns ⇒ Object
11 12 13 |
# File 'lib/tarsnap_pruner/scheduler.rb', line 11 def knowns @archives.select(&:date) end |
#monthlies ⇒ Object
27 28 29 |
# File 'lib/tarsnap_pruner/scheduler.rb', line 27 def monthlies knowns.select { |a| a.elapsed >= @weekly_boundary } end |
#monthlies_to_keep ⇒ Object
39 40 41 |
# File 'lib/tarsnap_pruner/scheduler.rb', line 39 def monthlies_to_keep monthlies.group_by { |a| a.date.month }.values.map(&:last) end |
#monthlies_to_prune ⇒ Object
43 44 45 |
# File 'lib/tarsnap_pruner/scheduler.rb', line 43 def monthlies_to_prune monthlies - monthlies_to_keep end |
#unknowns ⇒ Object
15 16 17 |
# File 'lib/tarsnap_pruner/scheduler.rb', line 15 def unknowns @archives.reject(&:date) end |
#weeklies ⇒ Object
23 24 25 |
# File 'lib/tarsnap_pruner/scheduler.rb', line 23 def weeklies knowns.select { |a| a.elapsed >= @daily_boundary && a.elapsed < @weekly_boundary } end |
#weeklies_to_keep ⇒ Object
31 32 33 |
# File 'lib/tarsnap_pruner/scheduler.rb', line 31 def weeklies_to_keep weeklies.group_by { |a| a.date.cweek }.values.map(&:last) end |
#weeklies_to_prune ⇒ Object
35 36 37 |
# File 'lib/tarsnap_pruner/scheduler.rb', line 35 def weeklies_to_prune weeklies - weeklies_to_keep end |