Class: Vizsla::Recorder

Inherits:
Object
  • Object
show all
Defined in:
lib/vizsla/recorder.rb

Constant Summary collapse

THREAD_LOCAL_KEY =
:_vizsla_current
LOCK =
Mutex.new

Class Method Summary collapse

Class Method Details

.add_event(event) ⇒ Object Also known as: <<



25
26
27
28
29
# File 'lib/vizsla/recorder.rb', line 25

def add_event(event)
  return unless self.recording?
  self.current[event.recorder_type] ||= []
  self.current[event.recorder_type] << event.prettify_data
end

.currentObject



7
8
9
10
11
# File 'lib/vizsla/recorder.rb', line 7

def current
  LOCK.synchronize do
    Thread.current[THREAD_LOCAL_KEY]
  end
end

.current=(val) ⇒ Object



13
14
15
# File 'lib/vizsla/recorder.rb', line 13

def current=(val)
  Thread.current[THREAD_LOCAL_KEY] = val
end

.eventsObject



32
33
34
# File 'lib/vizsla/recorder.rb', line 32

def events
  self.current
end

.recording?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/vizsla/recorder.rb', line 21

def recording?
  !self.current.nil?
end

.start_recordingObject



17
18
19
# File 'lib/vizsla/recorder.rb', line 17

def start_recording
  self.current = {}
end

.stop_recordingObject



36
37
38
39
40
# File 'lib/vizsla/recorder.rb', line 36

def stop_recording
  LOCK.synchronize do
    Thread.current[THREAD_LOCAL_KEY] = nil
  end
end