Class: Honeybadger::Breadcrumbs::RingBuffer

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/honeybadger/breadcrumbs/ring_buffer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bufferObject (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

#dropObject



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

#previousObject



35
36
37
# File 'lib/honeybadger/breadcrumbs/ring_buffer.rb', line 35

def previous
  @buffer.last
end

#to_aObject



27
28
29
# File 'lib/honeybadger/breadcrumbs/ring_buffer.rb', line 27

def to_a
  @buffer
end