# File lib/expire/keep_adjective_rule_base.rb, line 35 def self.primary_rank PRIMARY_RANK end
class Expire::KeepAdjectiveRuleBase
Base class for rules with an adjective in their name
Constants
- NOUN_FOR
- PRIMARY_RANK
- SECONDARY_RANK_FOR
Public Class Methods
from_value(value)
click to toggle source
# File lib/expire/keep_adjective_rule_base.rb, line 25 def self.from_value(value) value = -1 if value.all? value = 0 if value.none? integer_value = Integer(value) raise ArgumentError, 'must be at least -1' if integer_value < -1 new(amount: integer_value) end
primary_rank()
click to toggle source
rank()
click to toggle source
# File lib/expire/keep_adjective_rule_base.rb, line 39 def self.rank primary_rank + secondary_rank end
secondary_rank()
click to toggle source
# File lib/expire/keep_adjective_rule_base.rb, line 43 def self.secondary_rank match = name.downcase.match(/(hourly|daily|weekly|monthly|yearly)/) return unless match SECONDARY_RANK_FOR[match[1]] end
Public Instance Methods
adjective()
click to toggle source
# File lib/expire/keep_adjective_rule_base.rb, line 50 def adjective @adjective ||= infer_adjective end
apply(backups, _)
click to toggle source
# File lib/expire/keep_adjective_rule_base.rb, line 54 def apply(backups, _) per_spacing = backups.one_per(spacing) kept = amount == -1 ? per_spacing : per_spacing.most_recent(amount) kept.each { |backup| backup.add_reason_to_keep(reason_to_keep) } end
primary_rank()
click to toggle source
# File lib/expire/keep_adjective_rule_base.rb, line 64 def primary_rank self.class.primary_rank end
rank()
click to toggle source
# File lib/expire/keep_adjective_rule_base.rb, line 60 def rank @rank ||= primary_rank + secondary_rank end
secondary_rank()
click to toggle source
# File lib/expire/keep_adjective_rule_base.rb, line 68 def secondary_rank self.class.secondary_rank end
spacing()
click to toggle source
# File lib/expire/keep_adjective_rule_base.rb, line 72 def spacing NOUN_FOR[adjective] end
Private Instance Methods
class_name()
click to toggle source
# File lib/expire/keep_adjective_rule_base.rb, line 78 def class_name self.class.to_s end
infer_adjective()
click to toggle source
# File lib/expire/keep_adjective_rule_base.rb, line 82 def infer_adjective match = class_name.downcase.match(/(hourly|daily|weekly|monthly|yearly)/) return unless match match[1] end
pretty_amount()
click to toggle source
# File lib/expire/keep_adjective_rule_base.rb, line 93 def pretty_amount amount == -1 ? 'all' : amount.to_s end
reason_to_keep()
click to toggle source
# File lib/expire/keep_adjective_rule_base.rb, line 89 def reason_to_keep "keep #{pretty_amount} #{adjective} #{numerus_backup}" end