Class: Expire::Rules
- Inherits:
-
Object
- Object
- Expire::Rules
- Defined in:
- lib/expire/rules.rb
Overview
How backups are expired
Instance Attribute Summary collapse
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Class Method Summary collapse
Instance Method Summary collapse
- #any? ⇒ Boolean
- #apply(backups, reference_time) ⇒ Object
- #count ⇒ Object
-
#initialize(given = {}) ⇒ Rules
constructor
A new instance of Rules.
- #merge(prior_rules) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(given = {}) ⇒ Rules
Returns a new instance of Rules.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/expire/rules.rb', line 21 def initialize(given = {}) @rules = given.map do |rule_name, value| if value.respond_to? :rank value else rule_class = rule_class_for(rule_name) rule_class.from_value(value) end end end |
Instance Attribute Details
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
32 33 34 |
# File 'lib/expire/rules.rb', line 32 def rules @rules end |
Class Method Details
.from_options(options) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/expire/rules.rb', line 6 def self.() known_rules = RuleList.name_symbols = .select { |opt, _| known_rules.include?(opt) } new() end |
.from_yaml(file_name) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/expire/rules.rb', line 14 def self.from_yaml(file_name) pathname = Pathname.new(file_name) yaml_text = pathname.read yaml_rules = YAML.safe_load(yaml_text, symbolize_names: true) new(yaml_rules) end |
Instance Method Details
#any? ⇒ Boolean
34 35 36 |
# File 'lib/expire/rules.rb', line 34 def any? rules.any? end |
#apply(backups, reference_time) ⇒ Object
38 39 40 41 42 |
# File 'lib/expire/rules.rb', line 38 def apply(backups, reference_time) rules.sort.each { |rule| rule.apply(backups, reference_time) } backups end |
#count ⇒ Object
44 45 46 |
# File 'lib/expire/rules.rb', line 44 def count @rules.length end |
#merge(prior_rules) ⇒ Object
48 49 50 |
# File 'lib/expire/rules.rb', line 48 def merge(prior_rules) self.class.new(to_h.merge(prior_rules.to_h)) end |
#to_h ⇒ Object
52 53 54 |
# File 'lib/expire/rules.rb', line 52 def to_h rules.map { |rule| [rule.name.to_sym, rule] }.to_h end |