Class: Expire::FromNowKeepMostRecentForRule
- 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
Constant Summary collapse
- RULE_RANK =
12
Constants included from FromRangeValue
Expire::FromRangeValue::FROM_VALUE_REGEX
Instance Attribute Summary collapse
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
Attributes inherited from RuleBase
Class Method Summary collapse
Instance Method Summary collapse
- #apply(backups, time_now) ⇒ Object
-
#initialize(unit:, **args) ⇒ FromNowKeepMostRecentForRule
constructor
A new instance of FromNowKeepMostRecentForRule.
- #rank ⇒ Object
- #reason_to_keep ⇒ Object
Methods included from FromRangeValue
Methods included from NumerusUnit
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
#unit ⇒ Object (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
.rank ⇒ Object
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 |
#rank ⇒ Object
33 34 35 |
# File 'lib/expire/from_now_keep_most_recent_for_rule.rb', line 33 def rank self.class.rank end |
#reason_to_keep ⇒ Object
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 |