Class: ActionPushWeb::Notification
- Inherits:
-
Object
- Object
- ActionPushWeb::Notification
- Extended by:
- ActiveModel::Callbacks
- Defined in:
- lib/action_push_web/notification.rb
Instance Attribute Summary collapse
-
#badge ⇒ Object
Returns the value of attribute badge.
-
#body ⇒ Object
Returns the value of attribute body.
-
#context ⇒ Object
Returns the value of attribute context.
- #icon_path ⇒ Object
-
#path ⇒ Object
Returns the value of attribute path.
-
#silent ⇒ Object
Returns the value of attribute silent.
-
#title ⇒ Object
Returns the value of attribute title.
-
#urgency ⇒ Object
Returns the value of attribute urgency.
Class Method Summary collapse
Instance Method Summary collapse
- #as_json ⇒ Object
- #deliver_later_to(subscriptions) ⇒ Object
- #deliver_to(subscription) ⇒ Object
-
#initialize(title:, path: nil, body: nil, icon_path: nil, urgency: nil, badge: nil, silent: nil, **context) ⇒ Notification
constructor
A new instance of Notification.
Constructor Details
#initialize(title:, path: nil, body: nil, icon_path: nil, urgency: nil, badge: nil, silent: nil, **context) ⇒ Notification
Returns a new instance of Notification.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/action_push_web/notification.rb', line 20 def initialize(title:, path: nil, body: nil, icon_path: nil, urgency: nil, badge: nil, silent: nil, **context) @title = title @path = path @body = body.to_s @icon_path = icon_path @urgency = urgency @silent = silent @badge = badge @context = context end |
Instance Attribute Details
#badge ⇒ Object
Returns the value of attribute badge.
5 6 7 |
# File 'lib/action_push_web/notification.rb', line 5 def badge @badge end |
#body ⇒ Object
Returns the value of attribute body.
5 6 7 |
# File 'lib/action_push_web/notification.rb', line 5 def body @body end |
#context ⇒ Object
Returns the value of attribute context.
5 6 7 |
# File 'lib/action_push_web/notification.rb', line 5 def context @context end |
#icon_path ⇒ Object
44 45 46 |
# File 'lib/action_push_web/notification.rb', line 44 def icon_path @icon_path.presence || config.fetch(:icon_path, nil) end |
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/action_push_web/notification.rb', line 5 def path @path end |
#silent ⇒ Object
Returns the value of attribute silent.
5 6 7 |
# File 'lib/action_push_web/notification.rb', line 5 def silent @silent end |
#title ⇒ Object
Returns the value of attribute title.
5 6 7 |
# File 'lib/action_push_web/notification.rb', line 5 def title @title end |
#urgency ⇒ Object
Returns the value of attribute urgency.
5 6 7 |
# File 'lib/action_push_web/notification.rb', line 5 def urgency @urgency end |
Class Method Details
.queue_as(name) ⇒ Object
15 16 17 |
# File 'lib/action_push_web/notification.rb', line 15 def queue_as(name) self.queue_name = name end |
Instance Method Details
#as_json ⇒ Object
52 53 54 55 |
# File 'lib/action_push_web/notification.rb', line 52 def as_json { title:, body:, path:, icon_path:, urgency:, silent:, badge:, **context }.compact end |
#deliver_later_to(subscriptions) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/action_push_web/notification.rb', line 37 def deliver_later_to(subscriptions) Array(subscriptions).each do |subscription| ApplicationPushWebNotificationJob.set(queue: queue_name). perform_later(self.class.name, self.as_json, subscription) end end |
#deliver_to(subscription) ⇒ Object
31 32 33 34 35 |
# File 'lib/action_push_web/notification.rb', line 31 def deliver_to(subscription) if enabled run_callbacks(:delivery) { subscription.push(self) } end end |