Class: DispatchRider::NotificationServices::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/dispatch-rider/notification_services/base.rb

Direct Known Subclasses

AwsSns, FileSystem

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.



18
19
20
21
# File 'lib/dispatch-rider/notification_services/base.rb', line 18

def initialize(options = {})
  @notifier = notifier_builder.new(options)
  @channel_registrar = channel_registrar_builder.new
end

Instance Attribute Details

#channel_registrarObject (readonly)

Returns the value of attribute channel_registrar.



14
15
16
# File 'lib/dispatch-rider/notification_services/base.rb', line 14

def channel_registrar
  @channel_registrar
end

#notifierObject (readonly)

Returns the value of attribute notifier.



14
15
16
# File 'lib/dispatch-rider/notification_services/base.rb', line 14

def notifier
  @notifier
end

Instance Method Details

#channel(name) ⇒ Object

Raises:

  • (NotImplementedError)


39
40
41
# File 'lib/dispatch-rider/notification_services/base.rb', line 39

def channel(name)
  raise NotImplementedError
end

#channel_registrar_builderObject

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/dispatch-rider/notification_services/base.rb', line 27

def channel_registrar_builder
  raise NotImplementedError
end

#channels(names) ⇒ Object



35
36
37
# File 'lib/dispatch-rider/notification_services/base.rb', line 35

def channels(names)
  Array(names).map { |name| channel(name) }
end

#notifier_builderObject

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/dispatch-rider/notification_services/base.rb', line 23

def notifier_builder
  raise NotImplementedError
end

#publish(to:, message:) ⇒ Object



31
32
33
# File 'lib/dispatch-rider/notification_services/base.rb', line 31

def publish(to:, message:)
  channels(to).each { |channel| publish_to_channel channel, message: message }
end

#publish_to_channel(channel, message:) ⇒ Object



43
44
45
# File 'lib/dispatch-rider/notification_services/base.rb', line 43

def publish_to_channel(channel, message:)
  channel.publish(serialize(message))
end