Class: Chronos::Core::BreadcrumbBuffer
- Inherits:
-
Object
- Object
- Chronos::Core::BreadcrumbBuffer
- Defined in:
- lib/chronos/core/breadcrumb.rb
Overview
Fixed-size circular collection of execution breadcrumbs.
Instance Method Summary collapse
- #add(attributes) ⇒ Object
-
#initialize(capacity, max_bytes = 2048) ⇒ BreadcrumbBuffer
constructor
A new instance of BreadcrumbBuffer.
- #size ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(capacity, max_bytes = 2048) ⇒ BreadcrumbBuffer
Returns a new instance of BreadcrumbBuffer.
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 |
#size ⇒ Object
121 122 123 |
# File 'lib/chronos/core/breadcrumb.rb', line 121 def size @items.size end |
#to_a ⇒ Object
117 118 119 |
# File 'lib/chronos/core/breadcrumb.rb', line 117 def to_a @items.map(&:to_h) end |