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
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.
-
.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 |
.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
70 71 72 73 74 75 |
# File 'lib/easycov.rb', line 70 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
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/easycov.rb', line 101 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
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/easycov.rb', line 78 def merge! output = File.join(@path, ".resultset.json") files = [ output ] + Dir.glob(File.join(@path, ".tmp.*.resultset.json")) data = {} files.each do |f| next if !File.exists? f data.merge!(MultiJson.load(File.read(f))) File.delete(f) 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 |