Class: Expire::Backup
- Inherits:
-
Delegator
- Object
- Delegator
- Expire::Backup
- Includes:
- Comparable
- Defined in:
- lib/expire/backup.rb
Overview
Representation of a single backup
Instance Attribute Summary collapse
-
#pathname ⇒ Object
readonly
Returns the value of attribute pathname.
-
#reasons_to_keep ⇒ Object
readonly
Returns the value of attribute reasons_to_keep.
-
#time ⇒ Object
(also: #__getobj__)
readonly
Returns the value of attribute time.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
The <=> method seems not to be delegated so we need to implement it Note that this Class includes the Comparable module.
- #add_reason_to_keep(reason) ⇒ Object
-
#cweek ⇒ Object
def time backup.time end.
- #expired? ⇒ Boolean
-
#initialize(time:, pathname:) ⇒ Backup
constructor
A new instance of Backup.
- #keep? ⇒ Boolean
- #same_day?(other) ⇒ Boolean
- #same_hour?(other) ⇒ Boolean
- #same_month?(other) ⇒ Boolean
- #same_week?(other) ⇒ Boolean
- #same_year?(other) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(time:, pathname:) ⇒ Backup
Returns a new instance of Backup.
8 9 10 11 12 13 14 15 |
# File 'lib/expire/backup.rb', line 8 def initialize(time:, pathname:) @time = time @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 |
Instance Attribute Details
#pathname ⇒ Object (readonly)
Returns the value of attribute pathname.
17 18 19 |
# File 'lib/expire/backup.rb', line 17 def pathname @pathname end |
#reasons_to_keep ⇒ Object (readonly)
Returns the value of attribute reasons_to_keep.
17 18 19 |
# File 'lib/expire/backup.rb', line 17 def reasons_to_keep @reasons_to_keep end |
#time ⇒ Object (readonly) Also known as: __getobj__
Returns the value of attribute time.
17 18 19 |
# File 'lib/expire/backup.rb', line 17 def time @time end |
Instance Method Details
#<=>(other) ⇒ Object
The <=> method seems not to be delegated so we need to implement it Note that this Class includes the Comparable module
54 55 56 |
# File 'lib/expire/backup.rb', line 54 def <=>(other) time <=> other.time end |
#add_reason_to_keep(reason) ⇒ Object
58 59 60 |
# File 'lib/expire/backup.rb', line 58 def add_reason_to_keep(reason) reasons_to_keep << reason end |
#cweek ⇒ Object
def time
backup.time
end
66 67 68 |
# File 'lib/expire/backup.rb', line 66 def cweek time&.strftime("%V").to_i end |
#expired? ⇒ Boolean
70 71 72 |
# File 'lib/expire/backup.rb', line 70 def expired? reasons_to_keep.empty? end |
#keep? ⇒ Boolean
74 75 76 |
# File 'lib/expire/backup.rb', line 74 def keep? reasons_to_keep.any? end |
#same_day?(other) ⇒ Boolean
27 28 29 30 31 32 |
# 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) ⇒ Boolean
20 21 22 23 24 25 |
# 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) ⇒ Boolean
41 42 43 44 45 46 |
# 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) ⇒ Boolean
34 35 36 37 38 39 |
# 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) ⇒ Boolean
48 49 50 |
# File 'lib/expire/backup.rb', line 48 def same_year?(other) year == other.year end |
#to_s ⇒ Object
78 79 80 |
# File 'lib/expire/backup.rb', line 78 def to_s time.strftime("%Y-%m-%dT%H:%M") end |