Class: DispatchRider::Publisher

Inherits:
Object
  • Object
show all
Extended by:
ConfigurationSupport
Includes:
Callbacks::Support
Defined in:
lib/dispatch-rider/publisher.rb,
lib/dispatch-rider/publisher/configuration_reader.rb,
lib/dispatch-rider/publisher/configuration_support.rb

Overview

This class takes care of the publishing side of the messaging system.

Defined Under Namespace

Modules: ConfigurationReader, ConfigurationSupport Classes: Base, Configuration, ServiceChannelMapper

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ConfigurationSupport

configuration, configure

Constructor Details

#initialize(configuration = self.class.configuration) ⇒ Publisher

Returns a new instance of Publisher.



13
14
15
16
17
18
19
# File 'lib/dispatch-rider/publisher.rb', line 13

def initialize(configuration = self.class.configuration)
  @notification_service_registrar = DispatchRider::Registrars::NotificationService.new
  @publishing_destination_registrar = DispatchRider::Registrars::PublishingDestination.new
  @service_channel_mapper = ServiceChannelMapper.new(publishing_destination_registrar)

  ConfigurationReader.load_config(configuration, self)
end

Instance Attribute Details

#notification_service_registrarObject (readonly)

Returns the value of attribute notification_service_registrar.



11
12
13
# File 'lib/dispatch-rider/publisher.rb', line 11

def notification_service_registrar
  @notification_service_registrar
end

#publishing_destination_registrarObject (readonly)

Returns the value of attribute publishing_destination_registrar.



11
12
13
# File 'lib/dispatch-rider/publisher.rb', line 11

def publishing_destination_registrar
  @publishing_destination_registrar
end

#service_channel_mapperObject (readonly)

Returns the value of attribute service_channel_mapper.



11
12
13
# File 'lib/dispatch-rider/publisher.rb', line 11

def service_channel_mapper
  @service_channel_mapper
end

#sns_channel_registrarObject (readonly)

Returns the value of attribute sns_channel_registrar.



11
12
13
# File 'lib/dispatch-rider/publisher.rb', line 11

def sns_channel_registrar
  @sns_channel_registrar
end

Instance Method Details

#publish(original_options = {}) ⇒ Object

Parameters:

  • original_options (Hash) (defaults to: {})

    should contain ‘:destinations` and `:message` keys



39
40
41
42
43
44
45
46
47
# File 'lib/dispatch-rider/publisher.rb', line 39

def publish(original_options = {})
  options = build_publish_options(original_options)

  callbacks.invoke(:publish, options) do
    service_channel_mapper.map(options.delete(:destinations)).each do |(service, channels)|
      notification_service_registrar.fetch(service).publish(options.merge to: channels)
    end
  end
end

#register_channel(service, name, options = {}) ⇒ Object



32
33
34
35
36
# File 'lib/dispatch-rider/publisher.rb', line 32

def register_channel(service, name, options = {})
  notification_service = notification_service_registrar.fetch(service)
  notification_service.register(name, options)
  self
end

#register_destination(name, service, channel, options = {}) ⇒ Object



26
27
28
29
30
# File 'lib/dispatch-rider/publisher.rb', line 26

def register_destination(name, service, channel, options = {})
  register_channel(service, channel, options)
  publishing_destination_registrar.register(name, :service => service, :channel => channel)
  self
end

#register_notification_service(name, options = {}) ⇒ Object



21
22
23
24
# File 'lib/dispatch-rider/publisher.rb', line 21

def register_notification_service(name, options = {})
  notification_service_registrar.register(name, options)
  self
end