Sha256: e72b9a27472bd716d806bc61f7c39db66c49b0561a58780dbcfd504b1087bd92
Contents?: true
Size: 1.39 KB
Versions: 39
Compression:
Stored size: 1.39 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(options) channels(options[:to]).each do |channel| channel.publish(serialize(message(options[:message]))) end end def channels(names) Array(names).map { |name| channel(name) } end def channel(name) raise NotImplementedError end def message_builder DispatchRider::Message end private def message(attrs) message_builder.new(attrs) end def serialize(item) item.to_json end end end end
Version data entries
39 entries across 39 versions & 1 rubygems