Sha256: d66fb36e6c002c08480ea7faf24f1607a9df53c229a068bc256c438740902d1e
Contents?: true
Size: 1.32 KB
Versions: 15
Compression:
Stored size: 1.32 KB
Contents
# This base class provides an interface that we can implement # to generate a wrapper around a notification service. # The expected usage is as follows : # notification_service = DispatchRider::NotificationServices::Base.new # notification_service.publish(:to => [:foo, :oof], :message => {:subject => "bar", :body => "baz"}) require 'forwardable' module DispatchRider module NotificationServices class Base extend Forwardable attr_reader :notifier, :channel_registrar def_delegators :channel_registrar, :register, :fetch, :unregister def initialize(options = {}) @notifier = notifier_builder.new(options) @channel_registrar = channel_registrar_builder.new end def notifier_builder raise NotImplementedError end def channel_registrar_builder raise NotImplementedError end def publish(to:, message:) channels(to).each { |channel| publish_to_channel channel, message: message } end def channels(names) Array(names).map { |name| channel(name) } end def channel(name) raise NotImplementedError end def publish_to_channel(channel, message:) channel.publish(serialize(message)) end private def serialize(item) item.to_json end end end end
Version data entries
15 entries across 15 versions & 1 rubygems