Sha256: c77dad2a5d8d47804a7c4fcf24d5b6f1fdce935969fda1ab00b763deadc45cf6

Contents?: true

Size: 993 Bytes

Versions: 6

Compression:

Stored size: 993 Bytes

Contents

# frozen_string_literal: true

module Coverband
  module Adapters
    ###
    # FilesStore store a merged coverage file to local disk
    # Generally this is for testing and development
    # Not recommended for production deployment
    ###
    class FileStore < Base
      def initialize(path, _opts = {})
        super()
        @path = path

        config_dir = File.dirname(@path)
        Dir.mkdir config_dir unless File.exist?(config_dir)
      end

      def clear!
        File.delete(path) if File.exist?(path)
      end

      def size
        File.size?(path).to_i
      end

      def migrate!
        raise NotImplementedError, "FileStore doesn't support migrations"
      end

      private

      attr_accessor :path

      def save_coverage(report)
        File.open(path, 'w') { |f| f.write(report.to_json) }
      end

      def get_report
        if File.exist?(path)
          JSON.parse(File.read(path))
        else
          {}
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
coverband-4.2.0 lib/coverband/adapters/file_store.rb
coverband-4.2.0.rc3 lib/coverband/adapters/file_store.rb
coverband-4.2.0.rc2 lib/coverband/adapters/file_store.rb
coverband-4.1.1 lib/coverband/adapters/file_store.rb
coverband-4.2.0.rc1 lib/coverband/adapters/file_store.rb
coverband-4.1.0 lib/coverband/adapters/file_store.rb