Class: Correspondent::Notification
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Correspondent::Notification
- Defined in:
- app/models/correspondent/notification.rb
Overview
Notification
Model to hold all notification logic.
Class Method Summary collapse
-
.create_for!(attrs, options = {}) ⇒ Object
create_for!.
Instance Method Summary collapse
Class Method Details
.create_for!(attrs, options = {}) ⇒ Object
create_for!
Creates notification(s) for the given instance
of the publisher and given entity
(subscriber).
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/models/correspondent/notification.rb', line 33 def create_for!(attrs, = {}) attributes = attrs[:instance].to_notification(entity: attrs[:entity], trigger: attrs[:trigger]) attributes[:publisher] = attrs[:instance] relation = attrs[:instance].send(attrs[:entity]) if relation.respond_to?(:each) create_many!(attributes, relation, ) else create_single!(attributes, relation, ) end end |
Instance Method Details
#as_json ⇒ Object
72 73 74 75 76 |
# File 'app/models/correspondent/notification.rb', line 72 def as_json(*) Rails.cache.fetch("correspondent_notification_#{id}") do attributes.except("updated_at", "subscriber_type", "subscriber_id") end end |
#dismiss! ⇒ Object
78 79 80 81 |
# File 'app/models/correspondent/notification.rb', line 78 def dismiss! delete_cache_entry update!(dismissed: true) end |