Sha256: e9847476908c26385a3eae677940ec1022f4af02008a151f9cf7850ee25b3fc8

Contents?: true

Size: 801 Bytes

Versions: 1

Compression:

Stored size: 801 Bytes

Contents

# frozen_string_literal: true

module Expire
  # Base class for from-now rules
  class FromNowKeepAdjectiveForRuleBase < KeepAdjectiveRuleBase
    extend FromRangeValue
    include NumerusUnit

    PRIMARY_RANK = 40

    def self.primary_rank
      PRIMARY_RANK
    end

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

      @unit = unit
    end

    attr_reader :unit

    def apply(backups, reference_datetime)
      minimal_datetime = reference_datetime - amount.send(unit)
      kept = backups.one_per(spacing).not_older_than(minimal_datetime)

      kept.each { |backup| backup.add_reason_to_keep(reason_to_keep) }
    end

    def primary_rank
      self.class.primary_rank
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
expire-0.2.0 lib/expire/from_now_keep_adjective_for_rule_base.rb