Module: Audiences::Notifications
- Defined in:
- lib/audiences/notifications.rb
Overview
Handles notification of audience context changes. The notifications handled by this module are related to the membership composition of a context.
For instance, when a user leaves a group, the app will be notified of changes to the members of that context so it can react to that. When the audience configuration of a context changes, a notification will also be published through ‘Audiences::Notifications`.
Class Method Summary collapse
-
.publish(*contexts) ⇒ Object
Notifies that a given audience context was changed.
-
.subscribe(owner_type, job: nil) { ... } ⇒ Object
Subscribes to audience changes to a specific owner type, either with a background job or a callable block.
Class Method Details
.publish(*contexts) ⇒ Object
Notifies that a given audience context was changed
32 33 34 35 36 |
# File 'lib/audiences/notifications.rb', line 32 def publish(*contexts) contexts.each do |context| subscriptions[context.owner.class]&.call(context) end end |
.subscribe(owner_type, job: nil) { ... } ⇒ Object
Subscribes to audience changes to a specific owner type, either with a background job or a callable block
24 25 26 |
# File 'lib/audiences/notifications.rb', line 24 def subscribe(owner_type, job: nil, &cbk) subscriptions[owner_type] = job&.method(:perform_later) || cbk end |