Sha256: a7322dcb6e0ba682588e865d056c25520df5c5a32f07f62315098e7c9175a5f4

Contents?: true

Size: 675 Bytes

Versions: 4

Compression:

Stored size: 675 Bytes

Contents

# frozen_string_literal: true

module Expire
  # Keep the most recent Backups
  class KeepMostRecentRule < RuleBase
    using RefineAllAndNone

    RULE_RANK = 10

    def self.from_value(value)
      return new(amount: 0) if value.none?

      new(amount: Integer(value))
    end

    def self.rank
      RULE_RANK
    end

    def rank
      self.class.rank
    end

    def apply(backups, _)
      backups.most_recent(amount).each do |backup|
        backup.add_reason_to_keep(reason_to_keep)
      end
    end

    private

    def reason_to_keep
      return "keep the most recent backup" if amount == 1

      "keep the #{amount} most recent backups"
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
expire-0.2.6 lib/expire/keep_most_recent_rule.rb
expire-0.2.5 lib/expire/keep_most_recent_rule.rb
expire-0.2.4 lib/expire/keep_most_recent_rule.rb
expire-0.2.3 lib/expire/keep_most_recent_rule.rb