Class: Tracebin::Recorder
- Inherits:
-
Object
- Object
- Tracebin::Recorder
- Defined in:
- lib/tracebin/recorder.rb
Constant Summary collapse
- THREAD_LOCAL_KEY =
:_tracebin_current
- LOCK =
Mutex.new
Class Method Summary collapse
- .add_event(event) ⇒ Object (also: <<)
- .current ⇒ Object
- .current=(val) ⇒ Object
- .events ⇒ Object
- .recording? ⇒ Boolean
- .start_recording ⇒ Object
- .stop_recording ⇒ Object
Class Method Details
.add_event(event) ⇒ Object Also known as: <<
25 26 27 28 29 |
# File 'lib/tracebin/recorder.rb', line 25 def add_event(event) return unless self.recording? self.current[:events] ||= [] self.current[:events] << event.data_hash end |
.current ⇒ Object
7 8 9 10 11 |
# File 'lib/tracebin/recorder.rb', line 7 def current LOCK.synchronize do Thread.current[THREAD_LOCAL_KEY] end end |
.current=(val) ⇒ Object
13 14 15 |
# File 'lib/tracebin/recorder.rb', line 13 def current=(val) Thread.current[THREAD_LOCAL_KEY] = val end |
.events ⇒ Object
32 33 34 |
# File 'lib/tracebin/recorder.rb', line 32 def events self.current[:events] end |
.recording? ⇒ Boolean
21 22 23 |
# File 'lib/tracebin/recorder.rb', line 21 def recording? !self.current.nil? end |
.start_recording ⇒ Object
17 18 19 |
# File 'lib/tracebin/recorder.rb', line 17 def start_recording self.current = {} end |
.stop_recording ⇒ Object
36 37 38 39 40 |
# File 'lib/tracebin/recorder.rb', line 36 def stop_recording LOCK.synchronize do Thread.current[THREAD_LOCAL_KEY] = nil end end |