class Expire::Backup
Representation of a single backup
Attributes
__getobj__[R]
datetime[R]
pathname[R]
reasons_to_keep[R]
Public Class Methods
new(datetime:, pathname:)
click to toggle source
# File lib/expire/backup.rb, line 8 def initialize(datetime:, pathname:) @datetime = datetime @pathname = pathname # @reasons_to_keep is a Set so a reason can added multiple times # but appears only once @reasons_to_keep = Set.new end
Public Instance Methods
<=>(other)
click to toggle source
The <=> method seems not to be delegated so we need to implement it Note that this Class includes the Comparable module
# File lib/expire/backup.rb, line 54 def <=>(other) datetime <=> other.datetime end
add_reason_to_keep(reason)
click to toggle source
# File lib/expire/backup.rb, line 58 def add_reason_to_keep(reason) reasons_to_keep << reason end
expired?()
click to toggle source
def datetime
backup.datetime
end
# File lib/expire/backup.rb, line 66 def expired? reasons_to_keep.empty? end
keep?()
click to toggle source
# File lib/expire/backup.rb, line 70 def keep? reasons_to_keep.any? end
same_day?(other)
click to toggle source
# File lib/expire/backup.rb, line 27 def same_day?(other) return false unless same_week?(other) return true if day == other.day false end
same_hour?(other)
click to toggle source
# File lib/expire/backup.rb, line 20 def same_hour?(other) return false unless same_day?(other) return true if hour == other.hour false end
same_month?(other)
click to toggle source
# File lib/expire/backup.rb, line 41 def same_month?(other) return false unless same_year?(other) return true if month == other.month false end
same_week?(other)
click to toggle source
# File lib/expire/backup.rb, line 34 def same_week?(other) return false unless same_year?(other) return true if cweek == other.cweek false end
same_year?(other)
click to toggle source
# File lib/expire/backup.rb, line 48 def same_year?(other) year == other.year end