class OneshotCoverage::Logger::FileLogger

Public Class Methods

new(log_path) click to toggle source
# File lib/oneshot_coverage/logger/file_logger.rb, line 6
def initialize(log_path)
  @log_path = log_path
end

Public Instance Methods

post(new_logs) click to toggle source
# File lib/oneshot_coverage/logger/file_logger.rb, line 10
def post(new_logs)
  current_coverage = fetch

  new_logs.each do |new_log|
    key = "#{new_log.path}-#{new_log.md5_hash}"

    logged_lines = current_coverage.fetch(key, [])
    current_coverage[key] = logged_lines | new_log.lines
  end
  save(current_coverage)
end

Private Instance Methods

fetch() click to toggle source
# File lib/oneshot_coverage/logger/file_logger.rb, line 24
def fetch
  JSON.load(File.read(@log_path)) || {}
rescue Errno::ENOENT
  {}
end
save(data) click to toggle source
# File lib/oneshot_coverage/logger/file_logger.rb, line 30
def save(data)
  File.write(@log_path, JSON.dump(data))
end