Class: Queight::Queue

Inherits:
Object
  • Object
show all
Defined in:
lib/queight/queue.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Queue

Returns a new instance of Queue.



3
4
5
6
7
# File 'lib/queight/queue.rb', line 3

def initialize(name, options = {})
  @name = name
  @routing_patterns = Array(options.delete(:routing))
  @queue_options = options
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/queight/queue.rb', line 9

def name
  @name
end

#routing_patternsObject (readonly)

Returns the value of attribute routing_patterns.



9
10
11
# File 'lib/queight/queue.rb', line 9

def routing_patterns
  @routing_patterns
end

Instance Method Details

#declare(channel) ⇒ Object



11
12
13
# File 'lib/queight/queue.rb', line 11

def declare(channel)
  queue(channel)
end

#delete(channel) ⇒ Object



22
23
24
# File 'lib/queight/queue.rb', line 22

def delete(channel)
  channel.queue(@name).delete
end

#message_count(channel) ⇒ Object



30
31
32
# File 'lib/queight/queue.rb', line 30

def message_count(channel)
  queue(channel).message_count
end

#purge(channel) ⇒ Object



34
35
36
# File 'lib/queight/queue.rb', line 34

def purge(channel)
  queue(channel).purge
end

#queue(channel) ⇒ Object



26
27
28
# File 'lib/queight/queue.rb', line 26

def queue(channel)
  channel.queue(@name, queue_options)
end

#subscribe(channel, options = {}) ⇒ Object



15
16
17
18
19
20
# File 'lib/queight/queue.rb', line 15

def subscribe(channel, options = {})
  queue = queue(channel)
  queue.subscribe(subscribe_options(options)) do |*args|
    yield(channel, *args)
  end
end