Class: DispatchRider::NotificationServices::Base
- Inherits:
-
Object
- Object
- DispatchRider::NotificationServices::Base
- Extended by:
- Forwardable
- Defined in:
- lib/dispatch-rider/notification_services/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#channel_registrar ⇒ Object
readonly
Returns the value of attribute channel_registrar.
-
#notifier ⇒ Object
readonly
Returns the value of attribute notifier.
Instance Method Summary collapse
- #channel(name) ⇒ Object
- #channel_registrar_builder ⇒ Object
- #channels(names) ⇒ Object
-
#initialize(options = {}) ⇒ Base
constructor
A new instance of Base.
- #notifier_builder ⇒ Object
- #publish(to:, message:) ⇒ Object
- #publish_to_channel(channel, message:) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
20 21 22 23 |
# File 'lib/dispatch-rider/notification_services/base.rb', line 20 def initialize( = {}) @notifier = notifier_builder.new() @channel_registrar = channel_registrar_builder.new end |
Instance Attribute Details
#channel_registrar ⇒ Object (readonly)
Returns the value of attribute channel_registrar.
16 17 18 |
# File 'lib/dispatch-rider/notification_services/base.rb', line 16 def channel_registrar @channel_registrar end |
#notifier ⇒ Object (readonly)
Returns the value of attribute notifier.
16 17 18 |
# File 'lib/dispatch-rider/notification_services/base.rb', line 16 def notifier @notifier end |
Instance Method Details
#channel(name) ⇒ Object
41 42 43 |
# File 'lib/dispatch-rider/notification_services/base.rb', line 41 def channel(name) raise NotImplementedError end |
#channel_registrar_builder ⇒ Object
29 30 31 |
# File 'lib/dispatch-rider/notification_services/base.rb', line 29 def channel_registrar_builder raise NotImplementedError end |
#channels(names) ⇒ Object
37 38 39 |
# File 'lib/dispatch-rider/notification_services/base.rb', line 37 def channels(names) Array(names).map { |name| channel(name) } end |
#notifier_builder ⇒ Object
25 26 27 |
# File 'lib/dispatch-rider/notification_services/base.rb', line 25 def notifier_builder raise NotImplementedError end |
#publish(to:, message:) ⇒ Object
33 34 35 |
# File 'lib/dispatch-rider/notification_services/base.rb', line 33 def publish(to:, message:) channels(to).each { |channel| publish_to_channel channel, message: } end |
#publish_to_channel(channel, message:) ⇒ Object
45 46 47 |
# File 'lib/dispatch-rider/notification_services/base.rb', line 45 def publish_to_channel(channel, message:) channel.publish(message: serialize()) end |