lib/dispatch-rider/queue_services/base.rb in dispatch-rider-1.0.3 vs lib/dispatch-rider/queue_services/base.rb in dispatch-rider-1.1.4

- old
+ new

@@ -3,10 +3,11 @@ # assign_storage, insert, raw_head, construct_message_from, delete and size. # The instances of this class or it's child classes are supposed to perform the following actions on the queue service : # initialize, push, pop and empty? module DispatchRider module QueueServices + require "dispatch-rider/queue_services/received_message" class Base attr_accessor :queue def initialize(options = {}) @queue = assign_storage(options.symbolize_keys) @@ -24,20 +25,26 @@ def insert(item) raise NotImplementedError end + + #If you pass a block into pop it will wrap the deletion of the message with it's handling def pop(&block) - obj = head - if obj - block.call(obj.message) && delete(obj.item) - obj.message + received = head + if received + block.call(received) && delete(received.item) + received end end def head raw_item = raw_head - raw_item && ::OpenStruct.new(:item => raw_item, :message => construct_message_from(raw_item)) + raw_item && received_message_for(raw_item) + end + + def received_message_for(raw_item) + QueueServices::ReceivedMessage.new(construct_message_from(raw_item), raw_item) end def raw_head raise NotImplementedError end