Sha256: 1ff058110b452c0091390898b177b8da8e57a77d72ed3361173fc185869df9a0

Contents?: true

Size: 831 Bytes

Versions: 1

Compression:

Stored size: 831 Bytes

Contents

module Basket
  class BackendAdapter
    class MemoryBackend < Basket::BackendAdapter
      def initialize
        @data = {}
      end

      attr_reader :data

      def push(queue, data)
        @data[queue] = [] if @data[queue].nil?
        @data[queue] <<= data
      end

      def length(queue)
        return 0 if @data[queue].nil?

        @data[queue].length
      end

      def read(queue)
        @data[queue]
      end

      def search(queue, &block)
        @data[queue].select { |element| block.call(element.data) }
      end

      def remove(queue, id)
        index_of_element_to_delete = @data[queue].index { |element| element.id == id }
        @data[queue].delete_at(index_of_element_to_delete)
      rescue
        nil
      end

      def clear(queue)
        @data[queue] = []
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
basket-0.0.7 lib/basket/backend_adapter/memory_backend.rb