Class: Sentry::BreadcrumbBuffer

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/sentry/breadcrumb_buffer.rb

Constant Summary collapse

DEFAULT_SIZE =
100

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(size = nil) ⇒ BreadcrumbBuffer

Returns a new instance of BreadcrumbBuffer.

Parameters:

  • size (Integer, nil) (defaults to: nil)

    If it’s not provided, it’ll fallback to DEFAULT_SIZE



14
15
16
# File 'lib/sentry/breadcrumb_buffer.rb', line 14

def initialize(size = nil)
  @buffer = Array.new(size || DEFAULT_SIZE)
end

Instance Attribute Details

#bufferArray

Returns:

  • (Array)


11
12
13
# File 'lib/sentry/breadcrumb_buffer.rb', line 11

def buffer
  @buffer
end

Instance Method Details

#dupBreadcrumbBuffer

Returns:



58
59
60
61
62
# File 'lib/sentry/breadcrumb_buffer.rb', line 58

def dup
  copy = super
  copy.buffer = buffer.deep_dup
  copy
end

#each(&block) {|crumb| ... } ⇒ Array

Iterates through all breadcrumbs.

Parameters:

  • block (Proc)

Yield Parameters:

Returns:

  • (Array)


41
42
43
# File 'lib/sentry/breadcrumb_buffer.rb', line 41

def each(&block)
  members.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/sentry/breadcrumb_buffer.rb', line 46

def empty?
  members.none?
end

#membersArray

Returns:

  • (Array)


27
28
29
# File 'lib/sentry/breadcrumb_buffer.rb', line 27

def members
  @buffer.compact
end

#peekBreadcrumb?

Returns the last breadcrumb stored in the buffer. If the buffer it’s empty, it returns nil.

Returns:



33
34
35
# File 'lib/sentry/breadcrumb_buffer.rb', line 33

def peek
  members.last
end

#record(crumb) {|crumb| ... } ⇒ void

This method returns an undefined value.

Parameters:

Yields:

  • (crumb)


20
21
22
23
24
# File 'lib/sentry/breadcrumb_buffer.rb', line 20

def record(crumb)
  yield(crumb) if block_given?
  @buffer.slice!(0)
  @buffer << crumb
end

#to_hashHash

Returns:

  • (Hash)


51
52
53
54
55
# File 'lib/sentry/breadcrumb_buffer.rb', line 51

def to_hash
  {
    values: members.map(&:to_hash)
  }
end