Class: FIFO::Queue
- Inherits:
-
Object
- Object
- FIFO::Queue
- Defined in:
- lib/fifo/queue.rb
Instance Method Summary collapse
-
#clear ⇒ Object
Public: Clear all entries in the queue.
-
#initialize(name, visibility = 90) ⇒ Queue
constructor
Public.
-
#pop(options = {}) ⇒ Object
Public.
-
#push(*args) ⇒ Object
Push a new entry onto the queue.
Constructor Details
#initialize(name, visibility = 90) ⇒ Queue
Public. Constructor logic.
name - The String name of the queue. visibility - The Integer visibility of an item in the queue.
Returns nothing.
11 12 13 14 |
# File 'lib/fifo/queue.rb', line 11 def initialize(name,visibility=90) @name = name @visibility = visibility end |
Instance Method Details
#clear ⇒ Object
Public: Clear all entries in the queue.
Returns nothing.
62 63 64 |
# File 'lib/fifo/queue.rb', line 62 def clear queue.clear end |
#pop(options = {}) ⇒ Object
Public. Pop the first entry in the queue and create a payload object from it.
options - The Hash of options.
:raw - Return raw queue value instead of a payload.
Returns the Payload object if found or nil.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/fifo/queue.rb', line 23 def pop(={}) = queue.pop if if [:raw] payload = .body else payload = YAML.load(.body) payload.queue = self end end payload end |
#push(*args) ⇒ Object
Push a new entry onto the queue.
args - This can either be a Payload object or a Class or any ruby object including ActiveRecord::Base objects followed by a symbol for a method and optional method arguments. During processing ActiveRecord::Base objects are fetched again from the DB to avoid staleness.
Returns nothing.
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/fifo/queue.rb', line 46 def push(*args) payload = nil if args.first.class == Payload payload = args.first payload.queue = nil else payload = Payload.new(*args) end queue.push(payload.to_yaml) end |