Class: RSpec::Rewind::FlakyReporter::JsonlReporter
- Inherits:
-
Object
- Object
- RSpec::Rewind::FlakyReporter::JsonlReporter
- Defined in:
- lib/rspec/rewind/flaky_reporter.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #close ⇒ Object
- #flush ⇒ Object
-
#initialize(path) ⇒ JsonlReporter
constructor
A new instance of JsonlReporter.
- #record(event) ⇒ Object
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
#path ⇒ Object (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
#close ⇒ Object
52 |
# File 'lib/rspec/rewind/flaky_reporter.rb', line 52 def close; end |
#flush ⇒ Object
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 |