Class: AbstractNotifier::NotificationDelivery

Inherits:
Object
  • Object
show all
Includes:
Testing::NotificationDelivery
Defined in:
lib/abstract_notifier/base.rb

Overview

NotificationDelivery payload wrapper which contains information about the current notifier class and knows how to trigger the delivery

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(notifier_class, action_name, params: {}, args: [], kwargs: {}) ⇒ NotificationDelivery

Returns a new instance of NotificationDelivery.



10
11
12
13
14
15
16
# File 'lib/abstract_notifier/base.rb', line 10

def initialize(notifier_class, action_name, params: {}, args: [], kwargs: {})
  @notifier_class = notifier_class
  @action_name = action_name
  @params = params
  @args = args
  @kwargs = kwargs
end

Instance Attribute Details

#action_nameObject (readonly)

Returns the value of attribute action_name.



8
9
10
# File 'lib/abstract_notifier/base.rb', line 8

def action_name
  @action_name
end

#notifier_classObject (readonly)

Returns the value of attribute notifier_class.



8
9
10
# File 'lib/abstract_notifier/base.rb', line 8

def notifier_class
  @notifier_class
end

Instance Method Details

#delivery_paramsObject



40
# File 'lib/abstract_notifier/base.rb', line 40

def delivery_params = {params:, args:, kwargs:}

#notify_laterObject



26
27
28
29
30
31
32
# File 'lib/abstract_notifier/base.rb', line 26

def notify_later(**)
  if notifier_class.async_adapter.respond_to?(:enqueue_delivery)
    notifier_class.async_adapter.enqueue_delivery(self, **)
  else
    notifier_class.async_adapter.enqueue(notifier_class.name, action_name, params:, args:, kwargs:)
  end
end

#notify_nowObject



34
35
36
37
38
# File 'lib/abstract_notifier/base.rb', line 34

def notify_now
  return unless notification.payload

  notifier.deliver!(notification)
end

#processedObject Also known as: notification



18
19
20
21
22
# File 'lib/abstract_notifier/base.rb', line 18

def processed
  return @processed if instance_variable_defined?(:@processed)

  @processed = notifier.process_action(action_name, *args, **kwargs) || Notification.new(nil)
end