Class: Mercury::Fake::Queue
- Inherits:
-
Object
- Object
- Mercury::Fake::Queue
- Defined in:
- lib/mercury/fake/queue.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#worker ⇒ Object
readonly
Returns the value of attribute worker.
Instance Method Summary collapse
- #ack_or_reject_message(msg) ⇒ Object
- #add_subscriber(s) ⇒ Object
- #binds?(source_name, tag) ⇒ Boolean
- #enqueue(msg, tag, headers) ⇒ Object
-
#initialize(source, tag_filter, worker, require_ack) ⇒ Queue
constructor
A new instance of Queue.
- #nack(msg) ⇒ Object
Constructor Details
#initialize(source, tag_filter, worker, require_ack) ⇒ Queue
Returns a new instance of Queue.
9 10 11 12 13 14 15 16 |
# File 'lib/mercury/fake/queue.rb', line 9 def initialize(source, tag_filter, worker, require_ack) @source = source @tag_filter = tag_filter @worker = worker @require_ack = require_ack @msgs = [] @subscribers = [] end |
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the value of attribute source.
7 8 9 |
# File 'lib/mercury/fake/queue.rb', line 7 def source @source end |
#worker ⇒ Object (readonly)
Returns the value of attribute worker.
7 8 9 |
# File 'lib/mercury/fake/queue.rb', line 7 def worker @worker end |
Instance Method Details
#ack_or_reject_message(msg) ⇒ Object
28 29 30 31 32 |
# File 'lib/mercury/fake/queue.rb', line 28 def (msg) msgs.delete(msg) or raise 'tried to delete message that was not in queue!!' msg.subscriber.handle_capacity += 1 deliver # a subscriber just freed up end |
#add_subscriber(s) ⇒ Object
18 19 20 21 |
# File 'lib/mercury/fake/queue.rb', line 18 def add_subscriber(s) subscribers << s deliver # new subscriber probably wants a message end |
#binds?(source_name, tag) ⇒ Boolean
40 41 42 |
# File 'lib/mercury/fake/queue.rb', line 40 def binds?(source_name, tag) source_name == source && tag_match?(tag_filter, tag) end |
#enqueue(msg, tag, headers) ⇒ Object
23 24 25 26 |
# File 'lib/mercury/fake/queue.rb', line 23 def enqueue(msg, tag, headers) msgs.push(QueuedMessage.new(self, msg, tag, headers, @require_ack)) deliver # new message. someone probably wants it. end |
#nack(msg) ⇒ Object
34 35 36 37 38 |
# File 'lib/mercury/fake/queue.rb', line 34 def nack(msg) msg.delivered = false msg.subscriber.handle_capacity += 1 deliver end |