Class: Logtide::BreadcrumbBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/logtide/breadcrumb.rb

Overview

A ring buffer of breadcrumbs, oldest first, capped at max_breadcrumbs (spec 004 section 4).

Instance Method Summary collapse

Constructor Details

#initialize(max_breadcrumbs) ⇒ BreadcrumbBuffer

Returns a new instance of BreadcrumbBuffer.



37
38
39
40
# File 'lib/logtide/breadcrumb.rb', line 37

def initialize(max_breadcrumbs)
  @max = max_breadcrumbs
  @crumbs = []
end

Instance Method Details

#add(crumb) ⇒ Object



42
43
44
45
46
# File 'lib/logtide/breadcrumb.rb', line 42

def add(crumb)
  @crumbs << crumb
  @crumbs.shift while @crumbs.size > @max
  crumb
end

#clearObject



52
53
54
# File 'lib/logtide/breadcrumb.rb', line 52

def clear
  @crumbs.clear
end

#empty?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/logtide/breadcrumb.rb', line 56

def empty?
  @crumbs.empty?
end

#initialize_copy(other) ⇒ Object



60
61
62
63
# File 'lib/logtide/breadcrumb.rb', line 60

def initialize_copy(other)
  super
  @crumbs = other.to_a
end

#to_aObject



48
49
50
# File 'lib/logtide/breadcrumb.rb', line 48

def to_a
  @crumbs.dup
end