Sha256: 39de9878809e21aeef96171365d6bb66cb73776a021ef7afb1aee0d2bf45e350

Contents?: true

Size: 1.22 KB

Versions: 7

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

module HermesMessengerOfTheGods
  module Endpoints
    class Local < Base
      class << self
        attr_accessor :transmit_method

        def clear_queue!
          @received = nil
        end

        def received
          @received ||= Hash.new { |h, k| h[k] = [] }
        end
      end

      attr_accessor :on_receive

      def received
        self.class.received[endpoint]
      end

      def transmit(msg, raw_msg, opts = {})
        if self.class.transmit_method
          self.class.transmit_method.call(self, msg, raw_msg)
        else
          do_transmit(msg, opts, raw_msg)
        end
      end

      def do_transmit(msg, opts, raw_message = {})
        pub_opts = fetch_option(:publish_options, raw_message) || {}
        new_msg = { message: msg, options: opts.merge(pub_opts) }
        received << new_msg
        on_receive.call(new_msg) if on_receive
        "Recorded msg ##{self.class.received[endpoint].length} for #{endpoint}"
      end
    end
  end
end

if defined?(RSpec)
  RSpec.configure do |config|
    config.after(:each) do
      HermesMessengerOfTheGods::Endpoints::Local.clear_queue!
      HermesMessengerOfTheGods::Endpoints::Local.transmit_method = nil
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hermes_messenger_of_the_gods-2.4.0.pre2 lib/hermes_messenger_of_the_gods/testing/array_endpoint.rb
hermes_messenger_of_the_gods-2.4.0.pre1 lib/hermes_messenger_of_the_gods/testing/array_endpoint.rb
hermes_messenger_of_the_gods-2.3.4 lib/hermes_messenger_of_the_gods/testing/array_endpoint.rb
hermes_messenger_of_the_gods-2.3.3 lib/hermes_messenger_of_the_gods/testing/array_endpoint.rb
hermes_messenger_of_the_gods-2.3.2 lib/hermes_messenger_of_the_gods/testing/array_endpoint.rb
hermes_messenger_of_the_gods-2.3.1 lib/hermes_messenger_of_the_gods/testing/array_endpoint.rb
hermes_messenger_of_the_gods-2.3.0 lib/hermes_messenger_of_the_gods/testing/array_endpoint.rb