Class: Expire::BackupList
- Inherits:
-
Object
- Object
- Expire::BackupList
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/expire/backup_list.rb
Overview
All Backups go here
Instance Attribute Summary collapse
-
#backups ⇒ Object
readonly
Returns the value of attribute backups.
Instance Method Summary collapse
- #expired ⇒ Object
- #expired_count ⇒ Object
-
#initialize(backups = []) ⇒ BackupList
constructor
A new instance of BackupList.
- #keep ⇒ Object
- #keep_count ⇒ Object
- #most_recent(amount = 1) ⇒ Object
- #newest ⇒ Object
- #not_older_than(reference_time) ⇒ Object
- #oldest ⇒ Object
- #one_per(noun) ⇒ Object
Constructor Details
#initialize(backups = []) ⇒ BackupList
Returns a new instance of BackupList.
11 12 13 14 |
# File 'lib/expire/backup_list.rb', line 11 def initialize(backups = []) # @backups = backups.sort.reverse @backups = backups end |
Instance Attribute Details
#backups ⇒ Object (readonly)
Returns the value of attribute backups.
16 17 18 |
# File 'lib/expire/backup_list.rb', line 16 def backups @backups end |
Instance Method Details
#expired ⇒ Object
53 54 55 |
# File 'lib/expire/backup_list.rb', line 53 def expired self.class.new(backups.select(&:expired?)) end |
#expired_count ⇒ Object
57 58 59 |
# File 'lib/expire/backup_list.rb', line 57 def expired_count expired.length end |
#keep ⇒ Object
61 62 63 |
# File 'lib/expire/backup_list.rb', line 61 def keep self.class.new(backups.select(&:keep?)) end |
#keep_count ⇒ Object
65 66 67 |
# File 'lib/expire/backup_list.rb', line 65 def keep_count keep.length end |
#most_recent(amount = 1) ⇒ Object
37 38 39 |
# File 'lib/expire/backup_list.rb', line 37 def most_recent(amount = 1) self.class.new(sort.reverse.first(amount)) end |
#newest ⇒ Object
41 42 43 |
# File 'lib/expire/backup_list.rb', line 41 def newest backups.max end |
#not_older_than(reference_time) ⇒ Object
49 50 51 |
# File 'lib/expire/backup_list.rb', line 49 def not_older_than(reference_time) sort.select { |backup| backup.time >= reference_time } end |
#oldest ⇒ Object
45 46 47 |
# File 'lib/expire/backup_list.rb', line 45 def oldest backups.min end |
#one_per(noun) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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 = "same_#{noun}?" reversed.each do |backup| backups_per_noun << backup unless backup.send(, backups_per_noun.last) end backups_per_noun end |