Class: LSQS::QueueList
- Inherits:
-
Object
- Object
- LSQS::QueueList
- Includes:
- MonitorMixin
- Defined in:
- lib/lsqs/queue_list.rb
Instance Attribute Summary collapse
-
#queues ⇒ Object
Returns the value of attribute queues.
Instance Method Summary collapse
-
#create(name, options = {}) ⇒ LSQS::Queue
Creates a new queue, if it doesn’t exist already.
-
#delete(name) ⇒ Object
Deletes a queue if it exists.
-
#find(name) ⇒ Queue
Searches for a queue in the list by name.
-
#initialize ⇒ QueueList
constructor
A new instance of QueueList.
-
#inspect(options = {}) ⇒ Array
Returns the names of the existing queues.
-
#purge ⇒ Hash
Purges the current queue list.
-
#query ⇒ Object
Queries the list of queues.
Constructor Details
#initialize ⇒ QueueList
Returns a new instance of QueueList.
7 8 9 10 |
# File 'lib/lsqs/queue_list.rb', line 7 def initialize super @queues = {} end |
Instance Attribute Details
#queues ⇒ Object
Returns the value of attribute queues.
5 6 7 |
# File 'lib/lsqs/queue_list.rb', line 5 def queues @queues end |
Instance Method Details
#create(name, options = {}) ⇒ LSQS::Queue
Creates a new queue, if it doesn’t exist already.
29 30 31 32 33 34 35 |
# File 'lib/lsqs/queue_list.rb', line 29 def create(name, = {}) unless queues[name] @queues[name] = Queue.new(name, ) else raise 'QueueNameExists' end end |
#delete(name) ⇒ Object
Deletes a queue if it exists.
73 74 75 76 77 78 79 |
# File 'lib/lsqs/queue_list.rb', line 73 def delete(name) if queues[name] queues.delete(name) else raise 'NonExistentQueue' end end |
#find(name) ⇒ Queue
Searches for a queue in the list by name. If it doesn’t find it, it creates it.
60 61 62 63 64 65 66 |
# File 'lib/lsqs/queue_list.rb', line 60 def find(name) if queue = queues[name] return queue else raise 'NonExistentQueue' end end |
#inspect(options = {}) ⇒ Array
Returns the names of the existing queues.
44 45 46 47 48 49 50 |
# File 'lib/lsqs/queue_list.rb', line 44 def inspect( = {}) if prefix = ['QueueNamePrefix'] queues.select { |name, queue| name.start_with?(prefix) }.values.map(&:name) else queues.values.map(&:name) end end |
#purge ⇒ Hash
Purges the current queue list.
17 18 19 |
# File 'lib/lsqs/queue_list.rb', line 17 def purge @queues = {} end |
#query ⇒ Object
Queries the list of queues.
84 85 86 87 88 |
# File 'lib/lsqs/queue_list.rb', line 84 def query synchronize do yield end end |