Sha256: 00ba2aedd935be893cc644d6e50f1a96c9346fb7f61a983b8ee3cae81c3df15c
Contents?: true
Size: 1.46 KB
Versions: 1
Compression:
Stored size: 1.46 KB
Contents
module Basket class QueueCollection def initialize(backend = Basket.config.backend) @backend = backend.new end def push(queue, data) @backend.push(queue, Element.new(data)) length(queue) end def length(queue) @backend.length(queue) end def read(queue) check_for_basket(queue) raw_queue = @backend.read(queue) raw_queue.map { |element| Element.from_queue(element).data } end def search(queue, query) check_for_basket(queue) check_for_zero_length(queue) raw_search_results = @backend.search(queue, &query) raw_search_results.map { |raw_search_result| Element.from_queue(raw_search_result) } end def remove(queue, id) raw_removed_element = @backend.remove(queue, id) check_for_raw_removed_element(raw_removed_element) Element.from_queue(raw_removed_element).data end def clear(queue) @backend.clear(queue) end def data @backend.data end def reset_backend @backend = Basket.config.backend.new end private def check_for_basket(queue) raise Basket::BasketNotFoundError unless Object.const_defined?(queue) end def check_for_zero_length(queue) raise Basket::EmptyBasketError, "The basket #{queue} is empty." if length(queue).zero? end def check_for_raw_removed_element(raw_removed_element) raise Basket::ElementNotFoundError if raw_removed_element.nil? end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
basket-0.0.7 | lib/basket/queue_collection.rb |