Class: Expire::FromNowKeepMostRecentForRule

Inherits:
RuleBase
  • Object
show all
Extended by:
FromRangeValue
Includes:
NumerusUnit
Defined in:
lib/expire/from_now_keep_most_recent_for_rule.rb

Overview

Keep the most recent backups from now for a certain period of time.

Direct Known Subclasses

KeepMostRecentForRule

Constant Summary collapse

RULE_RANK =
12

Constants included from FromRangeValue

Expire::FromRangeValue::FROM_VALUE_REGEX

Instance Attribute Summary collapse

Attributes inherited from RuleBase

#amount

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FromRangeValue

from_value

Methods included from NumerusUnit

#numerus_unit

Methods inherited from RuleBase

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

Constructor Details

#initialize(unit:, **args) ⇒ FromNowKeepMostRecentForRule

Returns a new instance of FromNowKeepMostRecentForRule.



16
17
18
19
20
# File 'lib/expire/from_now_keep_most_recent_for_rule.rb', line 16

def initialize(unit:, **args)
  super(**args)

  @unit = unit
end

Instance Attribute Details

#unitObject (readonly)

Returns the value of attribute unit.



22
23
24
# File 'lib/expire/from_now_keep_most_recent_for_rule.rb', line 22

def unit
  @unit
end

Class Method Details

.rankObject



12
13
14
# File 'lib/expire/from_now_keep_most_recent_for_rule.rb', line 12

def self.rank
  RULE_RANK
end

Instance Method Details

#apply(backups, time_now) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/expire/from_now_keep_most_recent_for_rule.rb', line 24

def apply(backups, time_now)
  reference_time = time_now - amount.send(unit)
  kept = backups.not_older_than(reference_time)

  kept.each do |backup|
    backup.add_reason_to_keep(reason_to_keep)
  end
end

#rankObject



33
34
35
# File 'lib/expire/from_now_keep_most_recent_for_rule.rb', line 33

def rank
  self.class.rank
end

#reason_to_keepObject



37
38
39
# File 'lib/expire/from_now_keep_most_recent_for_rule.rb', line 37

def reason_to_keep
  "from now keep most recent backups for #{amount} #{numerus_unit}"
end