• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

payrollhero / dispatch-rider / #3015

02 Sep 2022 11:22PM UTC coverage: 0.409% (-84.7%) from 85.154%
#3015

push

web-flow
Layout/SpaceInsideStringInterpolation-20220901233630 (#89)

* :police_car: regenerate rubocop todo

* :police_car: Layout/SpaceInsideStringInterpolation

* :police_car: regenerate rubocop todo

Co-authored-by: Rubocop Challenger <rubocop@payrollhero.com>

0 of 1 new or added line in 1 file covered. (0.0%)

1529 existing lines in 63 files now uncovered.

7 of 1711 relevant lines covered (0.41%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lib/dispatch-rider/publisher.rb
UNCOV
1
require "active_support/core_ext/hash/indifferent_access"
×
UNCOV
2
require_relative "publisher/configuration_support"
×
3

UNCOV
4
module DispatchRider
×
5
  # This class takes care of the publishing side of the messaging system.
UNCOV
6
  class Publisher
×
UNCOV
7
    extend ConfigurationSupport
×
8

UNCOV
9
    include Callbacks::Support
×
10

UNCOV
11
    attr_reader :service_channel_mapper, :notification_service_registrar, :publishing_destination_registrar, :sns_channel_registrar
×
12

UNCOV
13
    def initialize(configuration = self.class.configuration)
×
UNCOV
14
      @notification_service_registrar = DispatchRider::Registrars::NotificationService.new
×
UNCOV
15
      @publishing_destination_registrar = DispatchRider::Registrars::PublishingDestination.new
×
UNCOV
16
      @service_channel_mapper = ServiceChannelMapper.new(publishing_destination_registrar)
×
17

UNCOV
18
      ConfigurationReader.load_config(configuration, self)
×
UNCOV
19
    end
×
20

UNCOV
21
    def register_notification_service(name, options = {})
×
UNCOV
22
      notification_service_registrar.register(name, options)
×
UNCOV
23
      self
×
UNCOV
24
    end
×
25

UNCOV
26
    def register_destination(name, service, channel, options = {})
×
UNCOV
27
      register_channel(service, channel, options)
×
UNCOV
28
      publishing_destination_registrar.register(name, :service => service, :channel => channel)
×
UNCOV
29
      self
×
UNCOV
30
    end
×
31

UNCOV
32
    def register_channel(service, name, options = {})
×
UNCOV
33
      notification_service = notification_service_registrar.fetch(service)
×
UNCOV
34
      notification_service.register(name, options)
×
UNCOV
35
      self
×
UNCOV
36
    end
×
37

38
    # @param [Hash] original_options should contain `:destinations` and `:message` keys
UNCOV
39
    def publish(original_options = {})
×
UNCOV
40
      options = build_publish_options(original_options)
×
41

UNCOV
42
      callbacks.invoke(:publish, options) do
×
UNCOV
43
        service_channel_mapper.map(options.delete(:destinations)).each do |(service, channels)|
×
UNCOV
44
          notification_service_registrar.fetch(service).publish(options.merge to: channels)
×
UNCOV
45
        end
×
UNCOV
46
      end
×
UNCOV
47
    end
×
48

UNCOV
49
    private
×
50

UNCOV
51
    def build_publish_options(message:, destinations:)
×
UNCOV
52
      { message: build_message(message), destinations: destinations }
×
UNCOV
53
    end
×
54

UNCOV
55
    def build_message(attributes)
×
UNCOV
56
      DispatchRider::Message.new(attributes).tap do |message|
×
UNCOV
57
        message.body[:guid] ||= generate_new_message_id
×
UNCOV
58
      end
×
UNCOV
59
    end
×
60

UNCOV
61
    def generate_new_message_id
×
UNCOV
62
      if DispatchRider.config.debug
×
UNCOV
63
        DispatchRider::Debug::PUBLISHER_MESSAGE_GUID
×
UNCOV
64
      else
×
65
        SecureRandom.uuid
×
UNCOV
66
      end
×
UNCOV
67
    end
×
68

UNCOV
69
    class ServiceChannelMapper
×
UNCOV
70
      attr_reader :destination_registrar
×
71

UNCOV
72
      def initialize(destination_registrar)
×
UNCOV
73
        @destination_registrar = destination_registrar
×
UNCOV
74
      end
×
75

UNCOV
76
      def map(names)
×
UNCOV
77
        services_and_channels_map(publishing_destinations(names))
×
UNCOV
78
      end
×
79

UNCOV
80
      private
×
81

UNCOV
82
      def publishing_destinations(names)
×
UNCOV
83
        Array(names).map { |name| destination_registrar.fetch(name) }
×
UNCOV
84
      end
×
85

UNCOV
86
      def services_and_channels_map(destinations)
×
UNCOV
87
        destinations.reduce({}) do |result, destination|
×
UNCOV
88
          if result.has_key?(destination.service)
×
89
            result[destination.service] << destination.channel
×
UNCOV
90
          else
×
UNCOV
91
            result[destination.service] = [destination.channel]
×
UNCOV
92
          end
×
UNCOV
93
          result
×
UNCOV
94
        end
×
UNCOV
95
      end
×
UNCOV
96
    end
×
UNCOV
97
  end
×
UNCOV
98
end
×
99

UNCOV
100
require_relative "publisher/configuration"
×
UNCOV
101
require_relative "publisher/configuration_reader"
×
UNCOV
102
require_relative "publisher/base"
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc