Class: DispatchRider::QueueServices::Base
- Inherits:
-
Object
- Object
- DispatchRider::QueueServices::Base
show all
- Defined in:
- lib/dispatch-rider/queue_services/base.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(options = {}) ⇒ Base
Returns a new instance of Base.
14
15
16
|
# File 'lib/dispatch-rider/queue_services/base.rb', line 14
def initialize(options = {})
@queue = assign_storage(options.symbolize_keys)
end
|
Instance Attribute Details
#queue ⇒ Object
Returns the value of attribute queue.
12
13
14
|
# File 'lib/dispatch-rider/queue_services/base.rb', line 12
def queue
@queue
end
|
Instance Method Details
#assign_storage(attrs) ⇒ Object
18
19
20
|
# File 'lib/dispatch-rider/queue_services/base.rb', line 18
def assign_storage(attrs)
raise NotImplementedError
end
|
#construct_message_from(item) ⇒ Object
54
55
56
|
# File 'lib/dispatch-rider/queue_services/base.rb', line 54
def construct_message_from(item)
raise NotImplementedError
end
|
#delete(item) ⇒ Object
58
59
60
|
# File 'lib/dispatch-rider/queue_services/base.rb', line 58
def delete(item)
raise NotImplementedError
end
|
#empty? ⇒ Boolean
62
63
64
|
# File 'lib/dispatch-rider/queue_services/base.rb', line 62
def empty?
size.zero?
end
|
#head ⇒ Object
41
42
43
44
|
# File 'lib/dispatch-rider/queue_services/base.rb', line 41
def head
raw_item = raw_head
raw_item && received_message_for(raw_item)
end
|
#insert(item) ⇒ Object
28
29
30
|
# File 'lib/dispatch-rider/queue_services/base.rb', line 28
def insert(item)
raise NotImplementedError
end
|
#pop ⇒ Object
If you pass a block into pop it will wrap the deletion of the message with it’s handling
33
34
35
36
37
38
39
|
# File 'lib/dispatch-rider/queue_services/base.rb', line 33
def pop
received = head
if received
yield(received) && delete(received.item)
received
end
end
|
#push(item) ⇒ Object
22
23
24
25
26
|
# File 'lib/dispatch-rider/queue_services/base.rb', line 22
def push(item)
message = serialize(item)
insert(message)
message
end
|
#raw_head ⇒ Object
50
51
52
|
# File 'lib/dispatch-rider/queue_services/base.rb', line 50
def raw_head
raise NotImplementedError
end
|
#received_message_for(raw_item) ⇒ Object
46
47
48
|
# File 'lib/dispatch-rider/queue_services/base.rb', line 46
def received_message_for(raw_item)
QueueServices::ReceivedMessage.new(construct_message_from(raw_item), raw_item)
end
|
#size ⇒ Object
66
67
68
|
# File 'lib/dispatch-rider/queue_services/base.rb', line 66
def size
raise NotImplementedError
end
|