Class: Basket::QueueCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/basket/queue_collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(backend = Basket.config.backend) ⇒ QueueCollection

Returns a new instance of QueueCollection.



3
4
5
# File 'lib/basket/queue_collection.rb', line 3

def initialize(backend = Basket.config.backend)
  @backend = backend.new
end

Instance Method Details

#clear(queue) ⇒ Object



35
36
37
# File 'lib/basket/queue_collection.rb', line 35

def clear(queue)
  @backend.clear(queue)
end

#dataObject



39
40
41
# File 'lib/basket/queue_collection.rb', line 39

def data
  @backend.data
end

#length(queue) ⇒ Object



12
13
14
# File 'lib/basket/queue_collection.rb', line 12

def length(queue)
  @backend.length(queue)
end

#push(queue, data) ⇒ Object



7
8
9
10
# File 'lib/basket/queue_collection.rb', line 7

def push(queue, data)
  @backend.push(queue, Element.new(data))
  length(queue)
end

#read(queue) ⇒ Object



16
17
18
19
20
# File 'lib/basket/queue_collection.rb', line 16

def read(queue)
  check_for_basket(queue)
  raw_queue = @backend.read(queue)
  raw_queue.map { |element| Element.from_queue(element).data }
end

#remove(queue, id) ⇒ Object



29
30
31
32
33
# File 'lib/basket/queue_collection.rb', line 29

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

#reset_backendObject



43
44
45
# File 'lib/basket/queue_collection.rb', line 43

def reset_backend
  @backend = Basket.config.backend.new
end

#search(queue, query) ⇒ Object



22
23
24
25
26
27
# File 'lib/basket/queue_collection.rb', line 22

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