Class: Honeybadger::Breadcrumbs::RingBuffer
- Inherits:
-
Object
- Object
- Honeybadger::Breadcrumbs::RingBuffer
- Includes:
- Enumerable
- Defined in:
- lib/honeybadger/breadcrumbs/ring_buffer.rb
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
Instance Method Summary collapse
- #add!(item) ⇒ Object
- #clear! ⇒ Object
- #drop ⇒ Object
- #each(&blk) ⇒ Object
-
#initialize(buffer_size = 40) ⇒ RingBuffer
constructor
A new instance of RingBuffer.
- #previous ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(buffer_size = 40) ⇒ RingBuffer
Returns a new instance of RingBuffer.
11 12 13 14 |
# File 'lib/honeybadger/breadcrumbs/ring_buffer.rb', line 11 def initialize(buffer_size = 40) @buffer_size = buffer_size clear! end |
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
9 10 11 |
# File 'lib/honeybadger/breadcrumbs/ring_buffer.rb', line 9 def buffer @buffer end |
Instance Method Details
#add!(item) ⇒ Object
16 17 18 19 20 |
# File 'lib/honeybadger/breadcrumbs/ring_buffer.rb', line 16 def add!(item) @buffer << item @ct += 1 @buffer.shift(1) if @ct > @buffer_size end |
#clear! ⇒ Object
22 23 24 25 |
# File 'lib/honeybadger/breadcrumbs/ring_buffer.rb', line 22 def clear! @buffer = [] @ct = 0 end |
#drop ⇒ Object
39 40 41 |
# File 'lib/honeybadger/breadcrumbs/ring_buffer.rb', line 39 def drop @buffer.pop end |
#each(&blk) ⇒ Object
31 32 33 |
# File 'lib/honeybadger/breadcrumbs/ring_buffer.rb', line 31 def each(&blk) @buffer.each(&blk) end |
#previous ⇒ Object
35 36 37 |
# File 'lib/honeybadger/breadcrumbs/ring_buffer.rb', line 35 def previous @buffer.last end |
#to_a ⇒ Object
27 28 29 |
# File 'lib/honeybadger/breadcrumbs/ring_buffer.rb', line 27 def to_a @buffer end |