Class: Unread::GarbageCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/unread/garbage_collector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(readable_class) ⇒ GarbageCollector

Returns a new instance of GarbageCollector.



3
4
5
# File 'lib/unread/garbage_collector.rb', line 3

def initialize(readable_class)
  @readable_class = readable_class.readable_parent
end

Instance Attribute Details

#readable_classObject (readonly)

Returns the value of attribute readable_class.



6
7
8
# File 'lib/unread/garbage_collector.rb', line 6

def readable_class
  @readable_class
end

Instance Method Details

#run!Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/unread/garbage_collector.rb', line 8

def run!
  ReadMark.reader_classes.each do |reader_class|
    readers_to_cleanup(reader_class).find_each do |reader|
      if oldest_timestamp = readable_class.read_scope(reader).
                              unread_by(reader).
                              minimum(readable_class.readable_options[:on])
        # There are unread items, so update the global read_mark for this reader to the oldest
        # unread item and delete older read_marks
        update_read_marks_for_user(reader, oldest_timestamp)
      else
        # There is no unread item, so deletes all markers and move global timestamp
        readable_class.reset_read_marks_for_user(reader)
      end
    end
  end
end