Module: Bugwatch::BreadcrumbCollector

Defined in:
lib/bugwatch/breadcrumb_collector.rb

Constant Summary collapse

THREAD_KEY =
:bugwatch_breadcrumbs
MAX_CRUMBS =
50

Class Method Summary collapse

Class Method Details

.add(message, type: "manual", metadata: {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/bugwatch/breadcrumb_collector.rb', line 6

def self.add(message, type: "manual", metadata: {})
  crumbs = Thread.current[THREAD_KEY] ||= []
  crumbs << {
    timestamp: Time.now.utc.iso8601(3),
    type:      type,
    message:   message.to_s,
    metadata:  
  }
  crumbs.shift if crumbs.size > MAX_CRUMBS
end

.allObject



17
18
19
# File 'lib/bugwatch/breadcrumb_collector.rb', line 17

def self.all
  Thread.current[THREAD_KEY] || []
end

.clearObject



21
22
23
# File 'lib/bugwatch/breadcrumb_collector.rb', line 21

def self.clear
  Thread.current[THREAD_KEY] = []
end