class Coverband::Adapters::FileStore

FileStore store a merged coverage file to local disk

Notes: Concurrency

Usage: config.store = Coverband::Adapters::FileStore.new('log/coverage.log')

View Reports: Using this assumes you are syncing the coverage files to some shared storage that is accessable outside of the production server download files to a system where you want to view the reports.. When viewing coverage from the filestore adapter it merges all coverage files matching the path pattern, in this case `log/coverage.log.*`

run: `bundle exec rake coverband:coverage_server` open localhost:9022/

one could also build a report via code, the output is suitable to feed into SimpleCov

“` coverband.configuration.store.merge_mode = true coverband.configuration.store.coverage “`

Attributes

merge_mode[RW]
path[RW]

Public Class Methods

new(path, _opts = {}) click to toggle source
Calls superclass method Coverband::Adapters::Base::new
# File lib/coverband/adapters/file_store.rb, line 34
def initialize(path, _opts = {})
  super()
  @path = "#{path}.#{::Process.pid}"
  @merge_mode = false

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

Public Instance Methods

clear!() click to toggle source
# File lib/coverband/adapters/file_store.rb, line 43
def clear!
  File.delete(path) if File.exist?(path)
end
coverage(_local_type = nil) click to toggle source
# File lib/coverband/adapters/file_store.rb, line 55
def coverage(_local_type = nil)
  if merge_mode
    data = {}
    Dir[path.sub(/\.\d+/, ".*")].each do |path|
      data = merge_reports(data, JSON.parse(File.read(path)), skip_expansion: true)
    end
    data
  elsif File.exist?(path)
    JSON.parse(File.read(path))
  else
    {}
  end
rescue Errno::ENOENT
  {}
end
migrate!() click to toggle source
# File lib/coverband/adapters/file_store.rb, line 51
def migrate!
  raise NotImplementedError, "FileStore doesn't support migrations"
end
raw_store() click to toggle source
# File lib/coverband/adapters/file_store.rb, line 77
def raw_store
  raise NotImplementedError, "FileStore doesn't support raw_store"
end
save_report(report) click to toggle source
# File lib/coverband/adapters/file_store.rb, line 71
def save_report(report)
  data = report.dup
  data = merge_reports(data, coverage)
  File.write(path, JSON.dump(data))
end
size() click to toggle source
# File lib/coverband/adapters/file_store.rb, line 47
def size
  File.size?(path).to_i
end