Class: Coverband::Adapters::FileStore
- Defined in:
- lib/coverband/adapters/file_store.rb
Overview
FileStore store a merged coverage file to local disk
Notes: Concurrency
-
threadsafe as the caller to save_report uses @semaphore.synchronize
-
file access process safe as each file written per process PID
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 accessible 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 “`
Constant Summary
Constants inherited from Base
Base::ABSTRACT_KEY, Base::DATA_KEY, Base::FILE_HASH, Base::FIRST_UPDATED_KEY, Base::LAST_UPDATED_KEY
Instance Attribute Summary collapse
-
#merge_mode ⇒ Object
Returns the value of attribute merge_mode.
Attributes inherited from Base
Instance Method Summary collapse
- #clear! ⇒ Object
- #coverage(_local_type = nil, opts = {}) ⇒ Object
-
#initialize(path, _opts = {}) ⇒ FileStore
constructor
A new instance of FileStore.
- #raw_store ⇒ Object
- #save_report(report) ⇒ Object
- #size ⇒ Object
Methods inherited from Base
#clear_file!, #covered_files, #get_coverage_report, #save_coverage, #size_in_mib
Constructor Details
#initialize(path, _opts = {}) ⇒ FileStore
Returns a new instance of FileStore.
34 35 36 37 38 39 40 41 |
# 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 |
Instance Attribute Details
#merge_mode ⇒ Object
Returns the value of attribute merge_mode.
33 34 35 |
# File 'lib/coverband/adapters/file_store.rb', line 33 def merge_mode @merge_mode end |
Instance Method Details
#clear! ⇒ Object
43 44 45 |
# File 'lib/coverband/adapters/file_store.rb', line 43 def clear! File.delete(path) if File.exist?(path) end |
#coverage(_local_type = nil, opts = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/coverband/adapters/file_store.rb', line 51 def coverage(_local_type = nil, opts = {}) 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 |
#raw_store ⇒ Object
73 74 75 |
# File 'lib/coverband/adapters/file_store.rb', line 73 def raw_store raise NotImplementedError, "FileStore doesn't support raw_store" end |
#save_report(report) ⇒ Object
67 68 69 70 71 |
# File 'lib/coverband/adapters/file_store.rb', line 67 def save_report(report) data = report.dup data = merge_reports(data, coverage) File.write(path, JSON.dump(data)) end |
#size ⇒ Object
47 48 49 |
# File 'lib/coverband/adapters/file_store.rb', line 47 def size File.size?(path).to_i end |