Class: Chronos::Core::BreadcrumbBuffer

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

Overview

Fixed-size circular collection of execution breadcrumbs.

Examples:

buffer.add(:category => "custom", :message => "started")

Instance Method Summary collapse

Constructor Details

#initialize(capacity, max_bytes = 2048) ⇒ BreadcrumbBuffer

Returns a new instance of BreadcrumbBuffer.

Raises:

  • (ArgumentError)


103
104
105
106
107
108
109
# File 'lib/chronos/core/breadcrumb.rb', line 103

def initialize(capacity, max_bytes = 2048)
  raise ArgumentError, "capacity must be a positive integer" unless capacity.is_a?(Integer) && capacity > 0

  @capacity = capacity
  @max_bytes = max_bytes
  @items = []
end

Instance Method Details

#add(attributes) ⇒ Object



111
112
113
114
115
# File 'lib/chronos/core/breadcrumb.rb', line 111

def add(attributes)
  @items.shift if @items.length >= @capacity
  @items << Breadcrumb.new(attributes, nil, @max_bytes)
  true
end

#sizeObject



121
122
123
# File 'lib/chronos/core/breadcrumb.rb', line 121

def size
  @items.size
end

#to_aObject



117
118
119
# File 'lib/chronos/core/breadcrumb.rb', line 117

def to_a
  @items.map(&:to_h)
end