Sha256: 68a55c7e9bc4969a75bd888f529ed07fdeb9af71ee7b0d7961e9e0e934ca990c

Contents?: true

Size: 797 Bytes

Versions: 1

Compression:

Stored size: 797 Bytes

Contents

# frozen_string_literal: true

module Expire
  # Keep the most recent backups from now for a certain
  # period of time.
  class FromNowKeepMostRecentForRule < RuleBase
    extend FromRangeValue
    include NumerusUnit

    RULE_RANK = 12

    def self.rank
      RULE_RANK
    end

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

      @unit = unit
    end

    attr_reader :unit

    def apply(backups, datetime_now)
      reference_datetime = datetime_now - amount.send(unit)
      kept = backups.not_older_than(reference_datetime)

      kept.each do |backup|
        backup.add_reason_to_keep(reason_to_keep)
      end
    end

    def rank
      self.class.rank
    end

    def reason_to_keep
      "from now keep most recent 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_most_recent_for_rule.rb