Class: Sqreen::CappedQueue
- Inherits:
-
Queue
- Object
- Queue
- Sqreen::CappedQueue
- Defined in:
- lib/sqreen/capped_queue.rb
Overview
A simple size limited queue. When trying to enqueue more than the capacity the older elements will get thrown
Instance Attribute Summary collapse
-
#capacity ⇒ Object
readonly
Returns the value of attribute capacity.
Instance Method Summary collapse
-
#initialize(capacity) ⇒ CappedQueue
constructor
A new instance of CappedQueue.
- #original_push ⇒ Object
- #push(value) ⇒ Object
Constructor Details
#initialize(capacity) ⇒ CappedQueue
Returns a new instance of CappedQueue.
15 16 17 18 |
# File 'lib/sqreen/capped_queue.rb', line 15 def initialize(capacity) @capacity = capacity super() end |
Instance Attribute Details
#capacity ⇒ Object (readonly)
Returns the value of attribute capacity.
13 14 15 |
# File 'lib/sqreen/capped_queue.rb', line 13 def capacity @capacity end |
Instance Method Details
#original_push ⇒ Object
20 |
# File 'lib/sqreen/capped_queue.rb', line 20 alias original_push push |
#push(value) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/sqreen/capped_queue.rb', line 22 def push(value) until size < @capacity discarded = pop Sqreen.log.debug { "Discarded from queue: #{discarded}" } end Sqreen.log.debug { "Pushed to the queue: #{value}" } original_push(value) end |