Sha256: d19357bdc5d85c655dd847399f1771d28c76c68c8678199f104b8f7abc67cd68

Contents?: true

Size: 566 Bytes

Versions: 3

Compression:

Stored size: 566 Bytes

Contents

class ReadMark
  include Mongoid::Document

  field :timestamp, type: Time

  belongs_to :readable, :polymorphic => true
  belongs_to :user

  validates_presence_of :user_id, :readable_type

  scope :global, -> { where(:readable_id => nil) }
  scope :single, -> { ne(readable_id: nil) }
  scope :older_than, -> (timestamp) { lt(timestamp: timestamp) }

  # Returns the class defined by acts_as_reader
  def self.reader_class
    reflect_on_all_associations(:belongs_to).find { |assoc| assoc.name == :user }.try(:klass)
  end

  class_attribute :readable_classes
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
unread-mongoid-0.0.5 lib/unread_mongoid/read_mark.rb
unread-mongoid-0.0.4 lib/unread_mongoid/read_mark.rb
unread-mongoid-0.0.1 lib/unread_mongoid/read_mark.rb