Sha256: 3c6a96530b1b7e82316709d673f2d1af1f58bbcd21f18af2b6e4eef074dd2395

Contents?: true

Size: 815 Bytes

Versions: 1

Compression:

Stored size: 815 Bytes

Contents

class ReadMark < ActiveRecord::Base
  belongs_to :readable, :polymorphic => true
  if ActiveRecord::VERSION::MAJOR < 4
    attr_accessible :readable_id, :user_id, :readable_type, :timestamp
  end

  validates_presence_of :user_id, :readable_type

  scope :global, lambda { where(:readable_id => nil) }
  scope :single, lambda { where('readable_id IS NOT NULL') }
  scope :older_than, lambda { |timestamp| where([ 'timestamp < ?', timestamp ]) }

  # Returns the class defined by acts_as_reader
  class_attribute :reader_class
  class_attribute :reader_options

  # Returns the classes defined by acts_as_readable
  class_attribute :readable_classes

  def self.reader_scope
    result = reader_class

    Array(reader_options[:scopes]).each do |scope|
      result = result.send(scope)
    end
    result
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unread-0.5.0 lib/unread/read_mark.rb