Sha256: 20e940f14bc1695fa8db5a2d770300bdcf2a2a69ac3329cb359298f01227eab9

Contents?: true

Size: 821 Bytes

Versions: 65

Compression:

Stored size: 821 Bytes

Contents

module Honeybadger
  module Breadcrumbs
    class RingBuffer
      # Simple ring buffer implementation that keeps item count constrained using
      # a rolling window. Items from the front of the buffer are dropped as more
      # are pushed on the end of the stack.
      include Enumerable

      attr_reader :buffer

      def initialize(buffer_size = 40)
        @buffer_size = buffer_size
        clear!
      end

      def add!(item)
        @buffer << item
        @ct += 1
        @buffer.shift(1) if @ct > @buffer_size
      end

      def clear!
        @buffer = []
        @ct = 0
      end

      def to_a
        @buffer
      end

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

      def previous
        @buffer.last
      end

      def drop
        @buffer.pop
      end
    end
  end
end

Version data entries

65 entries across 65 versions & 1 rubygems

Version Path
honeybadger-5.24.0 lib/honeybadger/breadcrumbs/ring_buffer.rb
honeybadger-5.23.0 lib/honeybadger/breadcrumbs/ring_buffer.rb
honeybadger-5.22.0 lib/honeybadger/breadcrumbs/ring_buffer.rb
honeybadger-5.21.0 lib/honeybadger/breadcrumbs/ring_buffer.rb
honeybadger-5.20.1 lib/honeybadger/breadcrumbs/ring_buffer.rb
honeybadger-5.20.0 lib/honeybadger/breadcrumbs/ring_buffer.rb
honeybadger-5.19.2 lib/honeybadger/breadcrumbs/ring_buffer.rb
honeybadger-5.19.1 lib/honeybadger/breadcrumbs/ring_buffer.rb
honeybadger-5.19.0 lib/honeybadger/breadcrumbs/ring_buffer.rb
honeybadger-5.18.0 lib/honeybadger/breadcrumbs/ring_buffer.rb
honeybadger-5.17.0 lib/honeybadger/breadcrumbs/ring_buffer.rb
honeybadger-5.16.0 lib/honeybadger/breadcrumbs/ring_buffer.rb
honeybadger-5.15.6 lib/honeybadger/breadcrumbs/ring_buffer.rb
honeybadger-5.15.5 lib/honeybadger/breadcrumbs/ring_buffer.rb
honeybadger-5.15.4 lib/honeybadger/breadcrumbs/ring_buffer.rb
honeybadger-5.15.3 lib/honeybadger/breadcrumbs/ring_buffer.rb
honeybadger-5.15.2 lib/honeybadger/breadcrumbs/ring_buffer.rb
honeybadger-5.15.1 lib/honeybadger/breadcrumbs/ring_buffer.rb
honeybadger-5.15.0 lib/honeybadger/breadcrumbs/ring_buffer.rb
honeybadger-5.14.2 lib/honeybadger/breadcrumbs/ring_buffer.rb