Class: Arachni::Database::Queue
- Defined in:
- lib/arachni/database/queue.rb
Overview
Flat-file Queue implementation
Behaves pretty much like a Ruby Queue however it transparently serializes and saves its values to the file-system under the OS’s temp directory.
It’s pretty useful when you want to reduce memory footprint without having to refactor any code since it behaves just like Ruby’s implementation.
@author: Tasos “Zapotek” Laskos
<[email protected]>
<[email protected]>
@version: 0.1
Instance Method Summary collapse
-
#<<(obj) ⇒ Object
(also: #push, #enq)
Adds an object to the queue.
-
#clear ⇒ Object
Removes all objects from the Queue.
-
#empty? ⇒ Bool
True if the Queue if empty, false otherwise.
-
#initialize(*args) ⇒ Queue
constructor
A new instance of Queue.
-
#pop ⇒ Object
(also: #deq, #shift)
Removes an object from the Queue and returns it.
-
#size ⇒ Integer
(also: #length)
Size of the Queue, the number of objects it currently holds.
Constructor Details
#initialize(*args) ⇒ Queue
Returns a new instance of Queue.
33 34 35 36 |
# File 'lib/arachni/database/queue.rb', line 33 def initialize( *args ) super( *args ) @q = ::Queue.new end |
Instance Method Details
#<<(obj) ⇒ Object Also known as: push, enq
Adds an object to the queue.
43 44 45 |
# File 'lib/arachni/database/queue.rb', line 43 def <<( obj ) @q << dump( obj ) end |
#clear ⇒ Object
Removes all objects from the Queue.
82 83 84 85 86 87 88 |
# File 'lib/arachni/database/queue.rb', line 82 def clear while( !@q.empty? ) path = @q.pop next if !path delete_file( filepath ) end end |
#empty? ⇒ Bool
True if the Queue if empty, false otherwise.
75 76 77 |
# File 'lib/arachni/database/queue.rb', line 75 def empty? @q.empty? end |
#pop ⇒ Object Also known as: deq, shift
Removes an object from the Queue and returns it.
54 55 56 |
# File 'lib/arachni/database/queue.rb', line 54 def pop return load_and_delete_file( @q.pop ) end |
#size ⇒ Integer Also known as: length
Size of the Queue, the number of objects it currently holds.
65 66 67 |
# File 'lib/arachni/database/queue.rb', line 65 def size @q.size end |