Class: Bugsnag::Utility::CircularBuffer Private

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/bugsnag/utility/circular_buffer.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A container class with a maximum size, that removes oldest items as required.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_items = 25) ⇒ CircularBuffer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of CircularBuffer.

Parameters:

  • max_items (Integer) (defaults to: 25)

    the initial maximum number of items



14
15
16
17
# File 'lib/bugsnag/utility/circular_buffer.rb', line 14

def initialize(max_items = 25)
  @max_items = max_items
  @buffer = []
end

Instance Attribute Details

#max_itemsInteger

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the current maximum allowable number of items.

Returns:

  • (Integer)

    the current maximum allowable number of items



10
11
12
# File 'lib/bugsnag/utility/circular_buffer.rb', line 10

def max_items
  @max_items
end

Instance Method Details

#<<(item) ⇒ self

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Adds an item to the circular buffer

If this causes the buffer to exceed its maximum items, the oldest item will be removed

Parameters:

  • item (Object)

    the item to add to the buffer

Returns:

  • (self)

    returns itself to allow method chaining



26
27
28
29
30
# File 'lib/bugsnag/utility/circular_buffer.rb', line 26

def <<(item)
  @buffer << item
  trim_buffer
  self
end

#each {|Object| ... } ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Iterates over the buffer

Yields:

  • (Object)

    sequentially gives stored items to the block



36
37
38
# File 'lib/bugsnag/utility/circular_buffer.rb', line 36

def each(&block)
  @buffer.each(&block)
end