Class: RSpec::Rewind::FlakyReporter::JsonlReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/rewind/flaky_reporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ JsonlReporter

Returns a new instance of JsonlReporter.



30
31
32
33
# File 'lib/rspec/rewind/flaky_reporter.rb', line 30

def initialize(path)
  @path = path
  @mutex = Mutex.new
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



28
29
30
# File 'lib/rspec/rewind/flaky_reporter.rb', line 28

def path
  @path
end

Instance Method Details

#closeObject



52
# File 'lib/rspec/rewind/flaky_reporter.rb', line 52

def close; end

#flushObject



50
# File 'lib/rspec/rewind/flaky_reporter.rb', line 50

def flush; end

#record(event) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rspec/rewind/flaky_reporter.rb', line 35

def record(event)
  payload = event.respond_to?(:to_h) ? event.to_h : {}

  @mutex.synchronize do
    FileUtils.mkdir_p(File.dirname(@path))
    File.open(@path, 'a') do |file|
      file.flock(File::LOCK_EX)
      file.puts(JSON.generate(payload))
      file.flush
    ensure
      file&.flock(File::LOCK_UN)
    end
  end
end