Class: Dontbugme::Store::Memory
- Defined in:
- lib/dontbugme/store/memory.rb
Instance Method Summary collapse
- #cleanup(before:) ⇒ Object
- #find_trace(trace_id) ⇒ Object
-
#initialize ⇒ Memory
constructor
A new instance of Memory.
- #save_trace(trace) ⇒ Object
- #search(filters = {}) ⇒ Object
Constructor Details
#initialize ⇒ Memory
Returns a new instance of Memory.
6 7 8 9 |
# File 'lib/dontbugme/store/memory.rb', line 6 def initialize @traces = {} @mutex = Mutex.new end |
Instance Method Details
#cleanup(before:) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/dontbugme/store/memory.rb', line 30 def cleanup(before:) cutoff = before.is_a?(Time) ? before : Time.parse(before.to_s) @mutex.synchronize do @traces.delete_if { |_, t| parse_time(t[:started_at]) < cutoff } end end |
#find_trace(trace_id) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/dontbugme/store/memory.rb', line 17 def find_trace(trace_id) data = @mutex.synchronize { @traces[trace_id] } return nil unless data Trace.from_h(data) end |
#save_trace(trace) ⇒ Object
11 12 13 14 15 |
# File 'lib/dontbugme/store/memory.rb', line 11 def save_trace(trace) @mutex.synchronize do @traces[trace.id] = trace.to_h end end |
#search(filters = {}) ⇒ Object
24 25 26 27 28 |
# File 'lib/dontbugme/store/memory.rb', line 24 def search(filters = {}) traces = @mutex.synchronize { @traces.values.dup } traces = apply_filters(traces, filters) traces.map { |h| Trace.from_h(h) } end |