Class: Expire::KeepMostRecentRule

Inherits:
RuleBase
  • Object
show all
Defined in:
lib/expire/keep_most_recent_rule.rb

Overview

Keep the most recent Backups

Constant Summary collapse

RULE_RANK =
10

Instance Attribute Summary

Attributes inherited from RuleBase

#amount

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from RuleBase

<=>, #<=>, camelized_name, #initialize, name, #name, #numerus_backup, #option_name, option_name

Constructor Details

This class inherits a constructor from Expire::RuleBase

Class Method Details

.from_value(value) ⇒ Object



10
11
12
13
14
# File 'lib/expire/keep_most_recent_rule.rb', line 10

def self.from_value(value)
  return new(amount: 0) if value.none?

  new(amount: Integer(value))
end

.rankObject



16
17
18
# File 'lib/expire/keep_most_recent_rule.rb', line 16

def self.rank
  RULE_RANK
end

Instance Method Details

#apply(backups, _) ⇒ Object



24
25
26
27
28
# File 'lib/expire/keep_most_recent_rule.rb', line 24

def apply(backups, _)
  backups.most_recent(amount).each do |backup|
    backup.add_reason_to_keep(reason_to_keep)
  end
end

#rankObject



20
21
22
# File 'lib/expire/keep_most_recent_rule.rb', line 20

def rank
  self.class.rank
end