Class: RaceGuard::Reporters::FileReporter
- Inherits:
-
Object
- Object
- RaceGuard::Reporters::FileReporter
- Defined in:
- lib/race_guard/reporters/file_reporter.rb
Overview
Appends one JSON line per event to a file.
Instance Method Summary collapse
-
#initialize(path, append: true) ⇒ FileReporter
constructor
A new instance of FileReporter.
- #report(event) ⇒ Object
Constructor Details
#initialize(path, append: true) ⇒ FileReporter
Returns a new instance of FileReporter.
9 10 11 12 13 |
# File 'lib/race_guard/reporters/file_reporter.rb', line 9 def initialize(path, append: true) @path = path @append = append @mutex = Mutex.new end |
Instance Method Details
#report(event) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/race_guard/reporters/file_reporter.rb', line 15 def report(event) line = JSON.generate(event.to_h) mode = @append ? 'a' : 'w' @mutex.synchronize do File.open(@path, mode) { |f| f.puts(line) } end end |