Class: Noticed::DeliveryMethods::Base

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Callbacks
Defined in:
lib/noticed/delivery_methods/base.rb

Direct Known Subclasses

ActionCable, Database, Email, Slack, Test, Twilio, Vonage

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#notificationObject (readonly)

Returns the value of attribute notification.



7
8
9
# File 'lib/noticed/delivery_methods/base.rb', line 7

def notification
  @notification
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/noticed/delivery_methods/base.rb', line 7

def options
  @options
end

#recipientObject (readonly)

Returns the value of attribute recipient.



7
8
9
# File 'lib/noticed/delivery_methods/base.rb', line 7

def recipient
  @recipient
end

#recordObject (readonly)

Returns the value of attribute record.



7
8
9
# File 'lib/noticed/delivery_methods/base.rb', line 7

def record
  @record
end

Instance Method Details

#deliverObject

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/noticed/delivery_methods/base.rb', line 24

def deliver
  raise NotImplementedError, "Delivery methods must implement a deliver method"
end

#perform(notification_class:, options:, params:, recipient:, record:) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/noticed/delivery_methods/base.rb', line 9

def perform(notification_class:, options:, params:, recipient:, record:)
  @notification = notification_class.constantize.new(params)
  @options = options
  @recipient = recipient
  @record = record

  # Make notification aware of database record and recipient during delivery
  @notification.record = record
  @notification.recipient = recipient

  run_callbacks :deliver do
    deliver
  end
end