Class: BunnyHair::Consumer

Inherits:
Object
  • Object
show all
Defined in:
lib/bunny_hair/consumer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(queue) ⇒ Consumer

Returns a new instance of Consumer.



13
14
15
16
17
# File 'lib/bunny_hair/consumer.rb', line 13

def initialize(queue)
  @queue = queue || raise(ArgumentError, "queue is nil")

  self.queue.consumers << self
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



9
10
11
# File 'lib/bunny_hair/consumer.rb', line 9

def arguments
  @arguments
end

#consumer_tagObject

Returns the value of attribute consumer_tag.



8
9
10
# File 'lib/bunny_hair/consumer.rb', line 8

def consumer_tag
  @consumer_tag
end

#exclusiveObject (readonly)

Returns the value of attribute exclusive.



11
12
13
# File 'lib/bunny_hair/consumer.rb', line 11

def exclusive
  @exclusive
end

#no_ackObject (readonly)

Returns the value of attribute no_ack.



10
11
12
# File 'lib/bunny_hair/consumer.rb', line 10

def no_ack
  @no_ack
end

#queueObject (readonly)



7
8
9
# File 'lib/bunny_hair/consumer.rb', line 7

def queue
  @queue
end

Instance Method Details

#call(*args) ⇒ Object Also known as: handle_delivery



28
29
30
# File 'lib/bunny_hair/consumer.rb', line 28

def call(*args)
  @on_delivery.call(*args) if @on_delivery
end

#cancelObject



24
25
26
# File 'lib/bunny_hair/consumer.rb', line 24

def cancel
  queue.consumers.delete(self)
end

#on_delivery(&block) ⇒ Object



19
20
21
22
# File 'lib/bunny_hair/consumer.rb', line 19

def on_delivery(&block)
  @on_delivery = block
  self
end