Class: Arachni::Support::Buffer::Base
- Defined in:
- lib/arachni/support/buffer/base.rb
Overview
Base buffer class to be extended by more specialised implementation.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#max_size ⇒ Integer
readonly
Maximum buffer size.
Instance Method Summary collapse
-
#<<(obj) ⇒ Object
(also: #push)
Calls #on_push blocks with the given object and pushes an object to the buffer.
-
#batch_push(list) ⇒ Object
Calls #on_batch_push blocks with the given list and merges the buffer with the contents of a list.
-
#empty? ⇒ Bool
‘true` if the buffer is empty, `false` otherwise.
-
#flush ⇒ Object
Calls #on_flush blocks with the buffer and then empties it.
-
#full? ⇒ Bool
‘true` if the buffer is full, `false` otherwise.
-
#initialize(max_size = nil, type = Array) ⇒ Base
constructor
A new instance of Base.
- #on_batch_push(&block) ⇒ Object
- #on_flush(&block) ⇒ Object
- #on_push(&block) ⇒ Object
-
#size ⇒ Integer
Amount of object in the buffer.
Constructor Details
#initialize(max_size = nil, type = Array) ⇒ Base
Returns a new instance of Base.
34 35 36 37 38 39 40 41 |
# File 'lib/arachni/support/buffer/base.rb', line 34 def initialize( max_size = nil, type = Array ) @buffer = type.new @max_size = max_size @on_flush_blocks = [] @on_push_blocks = [] @on_batch_push_blocks = [] end |
Instance Attribute Details
#max_size ⇒ Integer (readonly)
Returns Maximum buffer size.
28 29 30 |
# File 'lib/arachni/support/buffer/base.rb', line 28 def max_size @max_size end |
Instance Method Details
#<<(obj) ⇒ Object Also known as: push
Calls #on_push blocks with the given object and pushes an object to the buffer.
48 49 50 51 52 |
# File 'lib/arachni/support/buffer/base.rb', line 48 def <<( obj ) call_on_push_blocks obj @buffer << obj self end |
#batch_push(list) ⇒ Object
Calls #on_batch_push blocks with the given list and merges the buffer with the contents of a list.
61 62 63 64 65 |
# File 'lib/arachni/support/buffer/base.rb', line 61 def batch_push( list ) call_on_batch_push_blocks list @buffer |= list self end |
#empty? ⇒ Bool
Returns ‘true` if the buffer is empty, `false` otherwise.
73 74 75 |
# File 'lib/arachni/support/buffer/base.rb', line 73 def empty? @buffer.empty? end |
#flush ⇒ Object
Calls #on_flush blocks with the buffer and then empties it.
87 88 89 90 91 92 93 |
# File 'lib/arachni/support/buffer/base.rb', line 87 def flush buffer = @buffer.dup call_on_flush_blocks buffer buffer ensure @buffer.clear end |
#full? ⇒ Bool
Returns ‘true` if the buffer is full, `false` otherwise.
78 79 80 |
# File 'lib/arachni/support/buffer/base.rb', line 78 def full? !!(max_size && size >= max_size) end |
#on_batch_push(&block) ⇒ Object
102 103 104 105 |
# File 'lib/arachni/support/buffer/base.rb', line 102 def on_batch_push( &block ) @on_batch_push_blocks << block self end |
#on_flush(&block) ⇒ Object
108 109 110 111 |
# File 'lib/arachni/support/buffer/base.rb', line 108 def on_flush( &block ) @on_flush_blocks << block self end |
#on_push(&block) ⇒ Object
96 97 98 99 |
# File 'lib/arachni/support/buffer/base.rb', line 96 def on_push( &block ) @on_push_blocks << block self end |
#size ⇒ Integer
Returns amount of object in the buffer.
68 69 70 |
# File 'lib/arachni/support/buffer/base.rb', line 68 def size @buffer.size end |