Module: EasyCov
- Includes:
- Filters
- Defined in:
- lib/easycov.rb,
lib/easycov/filters.rb
Defined Under Namespace
Modules: Filters
Constant Summary collapse
- TOP_PID =
self
Process.pid
Constants included from Filters
Filters::IGNORE_GEMS, Filters::IGNORE_OUTSIDE_ROOT, Filters::IGNORE_STDLIB, Filters::IGNORE_TESTS, Filters::IGNORE_VENDOR
Class Attribute Summary collapse
-
.path ⇒ Object
Returns the value of attribute path.
-
.resolve_symlinks ⇒ Object
Returns the value of attribute resolve_symlinks.
-
.root ⇒ Object
Returns the value of attribute root.
Class Method Summary collapse
-
.checkpoint ⇒ Object
Write coverage to disk and restart.
-
.detect_path! ⇒ Object
Detect the coverage path.
-
.dump ⇒ Object
Dump coverage to disk in a thread-safe way.
-
.filter(&block) ⇒ Object
Add filter block.
-
.filters ⇒ Object
List of filters.
- .install_exit_hook ⇒ Object
-
.lock(lockfile, &block) ⇒ Object
Create a flock on the given file.
-
.merge! ⇒ Object
Merge all temporary coverage files into main file.
-
.start ⇒ Object
Start coverage engine Can be run multiple times without side-effect.
Methods included from Filters
Class Attribute Details
.path ⇒ Object
Returns the value of attribute path.
15 16 17 |
# File 'lib/easycov.rb', line 15 def path @path end |
.resolve_symlinks ⇒ Object
Returns the value of attribute resolve_symlinks.
15 16 17 |
# File 'lib/easycov.rb', line 15 def resolve_symlinks @resolve_symlinks end |
.root ⇒ Object
Returns the value of attribute root.
15 16 17 |
# File 'lib/easycov.rb', line 15 def root @root end |
Class Method Details
.checkpoint ⇒ Object
Write coverage to disk and restart
50 51 52 53 |
# File 'lib/easycov.rb', line 50 def checkpoint dump() start() end |
.detect_path! ⇒ Object
Detect the coverage path
Uses the first of Dir.pwd/.coverage or Dir.pwd/coverage
73 74 75 76 77 78 79 80 81 |
# File 'lib/easycov.rb', line 73 def detect_path! %w{.coverage coverage}.each { |c| cov_dir = File.join(Dir.pwd, c) if File.directory?(cov_dir) then EasyCov.path = cov_dir return end } end |
.dump ⇒ Object
Dump coverage to disk in a thread-safe way
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/easycov.rb', line 28 def dump return if ENV["DISABLE_EASYCOV"] == "1" Coverage.start # always make sure we are started FileUtils.mkdir_p(@path) if ENV["PARALLEL_EASYCOV"] == "1" then # in parallel mode, write output to separate files for each process # to be merged later, via #merge write_json(File.join(@path, ".tmp.#{$$}.resultset.json")) return end # default is to lock the output file output = File.join(@path, ".resultset.json") EasyCov.lock(output) do write_json(output) end end |
.filter(&block) ⇒ Object
Add filter block
61 62 63 |
# File 'lib/easycov.rb', line 61 def filter(&block) filters << block end |
.filters ⇒ Object
List of filters
56 57 58 |
# File 'lib/easycov.rb', line 56 def filters @filters ||= [] end |
.install_exit_hook ⇒ Object
83 84 85 86 87 88 |
# File 'lib/easycov.rb', line 83 def install_exit_hook return if ENV["DISABLE_EASYCOV"] == "1" Kernel.at_exit do EasyCov.checkpoint end end |
.lock(lockfile, &block) ⇒ Object
Create a flock on the given file
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/easycov.rb', line 118 def lock(lockfile, &block) lockfile = "#{lockfile}.lock" FileUtils.touch(lockfile) lock = File.new(lockfile) lock.flock(File::LOCK_EX) block.call() begin lock.flock(File::LOCK_UN) rescue end begin File.delete(lockfile) rescue end end |
.merge! ⇒ Object
Merge all temporary coverage files into main file
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/easycov.rb', line 91 def merge! output = File.join(@path, ".resultset.json") files = [ output ] + Dir.glob(File.join(@path, ".tmp.*.resultset.json")) data = {} files.each do |f| begin next if !File.size? f data.merge!(MultiJson.load(File.read(f))) rescue Oj::ParseError ensure File.delete(f) if File.exists? f end end prune(data) # write to final dest File.open(output+".tmp", 'w'){ |f| f.write(MultiJson.dump(data)) } File.rename(output+".tmp", output) end |
.start ⇒ Object
Start coverage engine Can be run multiple times without side-effect.
19 20 21 22 23 24 25 |
# File 'lib/easycov.rb', line 19 def start return if ENV["DISABLE_EASYCOV"] == "1" @resolve_symlinks = true if @resolve_symlinks.nil? @path ||= File.("coverage") @root ||= Dir.pwd # only set first time Coverage.start end |