Module: UserNotification::ORM::MongoMapper::Activist::ClassMethods

Defined in:
lib/user_notification/orm/mongo_mapper/activist.rb

Overview

Module extending classes that serve as owners

Instance Method Summary collapse

Instance Method Details

#acts_as_activistObject

Adds MongoMapper associations to model to simplify fetching so you can list notifications performed by the owner. It is completely optional. Any model can be an owner to an notification even without being an explicit acts_as_activist.

Usage:

In model:

class User
  include MongoMapper::Document
  include UserNotification::Model
  acts_as_activist
end

In controller:

User.first.notifications


38
39
40
41
42
43
44
45
# File 'lib/user_notification/orm/mongo_mapper/activist.rb', line 38

def acts_as_activist
  many :notifications_as_owner,      :class_name => "::UserNotification::Notification", :as => :owner
  many :notifications_as_recipient,  :class_name => "::UserNotification::Notification", :as => :recipient do
    def unread
      where(read: false)
    end
  end
end