Module: OyenCov::CoveragePeekDelta
- Defined in:
- lib/oyencov/coverage_peek_delta.rb
Constant Summary collapse
- PWD =
Dir.pwd
- @@previous_method_hits =
{}
Class Method Summary collapse
- .reset! ⇒ Object
-
.snapshot_delta ⇒ Hash
1.
-
.start ⇒ Object
We go a bit softer here.
Class Method Details
.reset! ⇒ Object
73 74 75 |
# File 'lib/oyencov/coverage_peek_delta.rb', line 73 def self.reset! @@previous_method_hits = {} end |
.snapshot_delta ⇒ Hash
-
Filter only the keys with PWD.
-
‘transform_keys` and remove the PWD
-
Use MRP to get the impt lines.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/oyencov/coverage_peek_delta.rb', line 29 def self.snapshot_delta current_peek = Coverage.peek_result # OyenCov::Logger.log "1st current_peek size = #{current_peek.size}, keys like: #{current_peek.keys[0, 3]}" # Filter into project filtered = current_peek.select do |k, _| /^#{PWD}/o.match?(k) end.transform_keys do |k| k.gsub(/#{PWD}\//o, "") end # OyenCov::Logger.log "2nd filtered size = #{filtered.size}, keys like: #{filtered.keys[0, 3]}" # Filter inside project to just the paths filtered = filtered.select do |k, _| /^(app|lib)/.match?(k) end # OyenCov::Logger.log "3rd filtered size = #{filtered.size}, keys like: #{filtered.keys[0, 3]}" # Find the method ranges, set current_method_hits = {} filtered.each_pair do |fpath, line_hits| MethodRangeParser[fpath]&.each_pair do |method_name, line_num| # puts [method_name, line_num, line_hits[line_num]] next if line_num.nil? || line_hits[line_num].nil? current_method_hits[method_name] = line_hits[line_num] end end # Compare and delta new_method_hits = {} current_method_hits.each_pair do |method_name, counter| new_hits = counter - (@@previous_method_hits[method_name] || 0) if new_hits > 0 new_method_hits[method_name] = new_hits end end @@previous_method_hits = current_method_hits new_method_hits end |
.start ⇒ Object
We go a bit softer here. If there are other libraries starting
coverage then don't throw exception.
16 17 18 19 20 21 22 |
# File 'lib/oyencov/coverage_peek_delta.rb', line 16 def self.start reset! unless Coverage.running? Coverage.start end end |