Sha256: 96b6acd4e4620d14ed72c7588c37da201ebb2b6404c7963df620f3dce866dc01

Contents?: true

Size: 867 Bytes

Versions: 1

Compression:

Stored size: 867 Bytes

Contents

class ReadMark < ActiveRecord::Base
  belongs_to :user
  belongs_to :readable, :polymorphic => true
  
  validates_presence_of :user_id, :readable_type
  
  scope_method = respond_to?(:scope) ? :scope : :named_scope
  
  send scope_method, :global, :conditions => { :readable_id => nil }
  send scope_method, :single, :conditions => 'readable_id IS NOT NULL'
  send scope_method, :readable_type, lambda { |readable_type | { :conditions => { :readable_type => readable_type }}}
  send scope_method, :user,          lambda { |user|           { :conditions => { :user_id => user.id }}}
  send scope_method, :older_than,    lambda { |timestamp|      { :conditions => [ 'timestamp < ?', timestamp] }}
  
  if respond_to?(:class_attribute)
    class_attribute :reader_class, :readable_classes
  else
    class_inheritable_accessor :reader_class, :readable_classes
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unread-0.0.1 lib/app/models/read_mark.rb