Sha256: ad5df8f5ef610e4b585239ec98637a8dae30d4599b5b9ddb3f1ff70e388d2f26

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

module MessageDriver
  class Broker
    def in_memory_adapter
      MessageDriver::Adapters::InMemoryAdapter
    end
  end

  module Adapters
    class InMemoryAdapter < Base

      class Message < MessageDriver::Message::Base

      end

      class Destination < MessageDriver::Destination::Base
        def initialize(adapter, name, dest_options, message_props, message_store)
          super(adapter, name, dest_options, message_props)
          @message_store = message_store
        end
        def message_count
          @message_store[@name].size
        end
      end

      def initialize(config={})
        #does nothing
      end

      def publish(destination, body, headers={}, properties={})
        message_store[destination] << Message.new(body, headers, properties)
      end

      def pop_message(destination, options={})
        message_store[destination].shift
      end

      def stop
        message_store.clear
      end

      def create_destination(name, dest_options={}, message_props={})
        Destination.new(self, name, dest_options, message_props, message_store)
      end

      def reset_after_tests
        message_store.each do |destination, message_array|
          message_array.replace([])
        end
      end

      private

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
message-driver-0.1.0 lib/message_driver/adapters/in_memory_adapter.rb