Class: Expire::FromNowKeepAdjectiveForRuleBase
- Inherits:
-
KeepAdjectiveRuleBase
- Object
- RuleBase
- KeepAdjectiveRuleBase
- Expire::FromNowKeepAdjectiveForRuleBase
- Extended by:
- FromRangeValue
- Includes:
- NumerusUnit
- Defined in:
- lib/expire/from_now_keep_adjective_for_rule_base.rb
Overview
Base class for from-now rules
Direct Known Subclasses
FromNowKeepDailyForRule, FromNowKeepHourlyForRule, FromNowKeepMonthlyForRule, FromNowKeepWeeklyForRule, FromNowKeepYearlyForRule, KeepAdjectiveForRuleBase
Constant Summary collapse
- PRIMARY_RANK =
40
Constants included from FromRangeValue
Expire::FromRangeValue::FROM_VALUE_REGEX
Constants inherited from KeepAdjectiveRuleBase
KeepAdjectiveRuleBase::NOUN_FOR, KeepAdjectiveRuleBase::SECONDARY_RANK_FOR
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, reference_time) ⇒ Object
-
#initialize(unit:, **args) ⇒ FromNowKeepAdjectiveForRuleBase
constructor
A new instance of FromNowKeepAdjectiveForRuleBase.
- #primary_rank ⇒ Object
- #reason_to_keep ⇒ Object
Methods included from FromRangeValue
Methods included from NumerusUnit
Methods inherited from KeepAdjectiveRuleBase
#adjective, from_value, rank, #rank, secondary_rank, #secondary_rank, #spacing
Methods inherited from RuleBase
<=>, #<=>, camelized_name, #name, name, #numerus_backup, option_name, #option_name
Constructor Details
#initialize(unit:, **args) ⇒ FromNowKeepAdjectiveForRuleBase
Returns a new instance of FromNowKeepAdjectiveForRuleBase.
15 16 17 18 19 |
# File 'lib/expire/from_now_keep_adjective_for_rule_base.rb', line 15 def initialize(unit:, **args) super(**args) @unit = unit end |
Instance Attribute Details
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
21 22 23 |
# File 'lib/expire/from_now_keep_adjective_for_rule_base.rb', line 21 def unit @unit end |
Class Method Details
.primary_rank ⇒ Object
11 12 13 |
# File 'lib/expire/from_now_keep_adjective_for_rule_base.rb', line 11 def self.primary_rank PRIMARY_RANK end |
Instance Method Details
#apply(backups, reference_time) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/expire/from_now_keep_adjective_for_rule_base.rb', line 23 def apply(backups, reference_time) minimal_time = reference_time - amount.send(unit) kept = backups.one_per(spacing).not_older_than(minimal_time) kept.each { |backup| backup.add_reason_to_keep(reason_to_keep) } end |
#primary_rank ⇒ Object
30 31 32 |
# File 'lib/expire/from_now_keep_adjective_for_rule_base.rb', line 30 def primary_rank self.class.primary_rank end |
#reason_to_keep ⇒ Object
34 35 36 |
# File 'lib/expire/from_now_keep_adjective_for_rule_base.rb', line 34 def reason_to_keep "from now keep all backups for #{amount} #{numerus_unit}" end |