module Unread::Reader::InstanceMethods

Public Instance Methods

forget_memoized_read_mark_global() click to toggle source
# File lib/unread/reader.rb, line 22
def forget_memoized_read_mark_global
  @read_mark_global = nil
end
have_read?(readable) click to toggle source
# File lib/unread/reader.rb, line 26
def have_read?(readable)
  if self.respond_to?(:read_mark_id) && read_mark_id_belongs_to?(readable)
    # For use with scope "with_read_marks_for"
    !self.read_mark_id.nil?
  else
    !self.class.have_not_read(readable).exists?(self.id)
  end
end
read_mark_global(klass) click to toggle source
# File lib/unread/reader.rb, line 16
def read_mark_global(klass)
  @read_mark_global ||= {}
  readable_klass = klass.readable_parent
  @read_mark_global[readable_klass] ||= read_marks.where(readable_type: readable_klass.name).global.first
end

Private Instance Methods

read_mark_id_belongs_to?(readable) click to toggle source
# File lib/unread/reader.rb, line 37
def read_mark_id_belongs_to?(readable)
  self.read_mark_readable_type == readable.class.name &&
  (self.read_mark_readable_id.nil? || self.read_mark_readable_id.to_i == readable.id)
end
setup_new_reader() click to toggle source

We assume that a new reader should not be tackled by tons of old messages created BEFORE he signed up. Instead, the new reader should start with zero unread messages. If you don't want this, you can override this method in your reader class

# File lib/unread/reader.rb, line 45
def setup_new_reader
  (ReadMark.readable_classes || []).each do |klass|
    klass.mark_as_read! :all, for: self
  end
end