class Expire::BackupList

All Backups go here

Attributes

backups[R]

Public Class Methods

new(backups = []) click to toggle source
# File lib/expire/backup_list.rb, line 11
def initialize(backups = [])
  # @backups = backups.sort.reverse
  @backups = backups
end

Public Instance Methods

expired() click to toggle source
# File lib/expire/backup_list.rb, line 53
def expired
  self.class.new(backups.select(&:expired?))
end
expired_count() click to toggle source
# File lib/expire/backup_list.rb, line 57
def expired_count
  expired.length
end
keep() click to toggle source
# File lib/expire/backup_list.rb, line 61
def keep
  self.class.new(backups.select(&:keep?))
end
keep_count() click to toggle source
# File lib/expire/backup_list.rb, line 65
def keep_count
  keep.length
end
most_recent(amount = 1) click to toggle source
# File lib/expire/backup_list.rb, line 37
def most_recent(amount = 1)
  self.class.new(sort.reverse.first(amount))
end
newest() click to toggle source
# File lib/expire/backup_list.rb, line 41
def newest
  backups.max
end
not_older_than(reference_datetime) click to toggle source
# File lib/expire/backup_list.rb, line 49
def not_older_than(reference_datetime)
  sort.select { |backup| backup.datetime >= reference_datetime }
end
oldest() click to toggle source
# File lib/expire/backup_list.rb, line 45
def oldest
  backups.min
end
one_per(noun) click to toggle source
# File lib/expire/backup_list.rb, line 20
def one_per(noun)
  backups_per_noun = self.class.new
  return backups_per_noun unless any?

  reversed = sort.reverse

  backups_per_noun << reversed.first

  message = "same_#{noun}?"

  reversed.each do |backup|
    backups_per_noun << backup unless backup.send(message, backups_per_noun.last)
  end

  backups_per_noun
end