Sha256: a07851fa97cee70a124547e85ea33fc480ba960b494f452ca1f5dd2ce5956da2

Contents?: true

Size: 692 Bytes

Versions: 2

Compression:

Stored size: 692 Bytes

Contents

require 'json'

module OneshotCoverage
  module Logger
    class FileLogger
      def initialize(log_path)
        @log_path = log_path
      end

      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

      def fetch
        JSON.load(File.read(@log_path)) || {}
      rescue Errno::ENOENT
        {}
      end

      def save(data)
        File.write(@log_path, JSON.dump(data))
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
oneshot_coverage-0.4.1 lib/oneshot_coverage/logger/file_logger.rb
oneshot_coverage-0.4.0 lib/oneshot_coverage/logger/file_logger.rb