Class: Notification
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Notification
- Includes:
- HasOwner
- Defined in:
- app/models/notification.rb
Constant Summary collapse
- PER_PAGE =
10
Class Method Summary collapse
- .category_from_object(entity) ⇒ Object
- .notify(user, category, payload) ⇒ Object
- .page_for_owner(user, page) ⇒ Object
Instance Method Summary collapse
Class Method Details
.category_from_object(entity) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/models/notification.rb', line 35 def self.category_from_object(entity) case entity.class.to_s when UserMessage.to_s categories[:new_message] when UserLink.to_s categories[:new_follower] when Entry.to_s categories[:entry_comment] when Post.to_s categories[:post_comment] when News.to_s categories[:news_comment] else nil end end |
.notify(user, category, payload) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'app/models/notification.rb', line 24 def self.notify(user, category, payload) criteria = { user: user, category: category, payload: payload } instance = unread.find_by(criteria) if instance.nil? create!(criteria) else instance.increment! :repetition_count end end |
.page_for_owner(user, page) ⇒ Object
17 18 19 |
# File 'app/models/notification.rb', line 17 def self.page_for_owner(user, page) owned_by(user).recent.page(page).per(PER_PAGE) end |
Instance Method Details
#payload_object ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/models/notification.rb', line 52 def payload_object case category.to_sym when :entry_comment Entry.find_by(id: payload) when :post_comment Post.find_by(id: payload) when :news_comment News.find_by(id: payload) else User.find_by(id: payload) end end |