cover_rage 0.0.6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7bea62a74d8c6c9e2bbcd7918e28a2ee43f71f0548b43d4813438a02a3bffa32
4
- data.tar.gz: 47c5ef4df517fd22406db7dd4b93b10089a2d2b08bccd7a24b0e2ae23c76e55c
3
+ metadata.gz: 5475081d89068cc543f39035786796e346ca90364f30c525680f4458118c211c
4
+ data.tar.gz: 954ed2e2a6d4173e99b533c8914fd4c517730b53262bdbce0193c937644ad524
5
5
  SHA512:
6
- metadata.gz: d4fecf3fc7435ba7e96b171e864d2463d7256c4c2f987546c3d10ea13543da59e779530a38094dd45bde32aba6cefc9c4663ebdd0df52b0a178d4ca318c4b658
7
- data.tar.gz: f91e8dce7f3770d31547899baa4e5add2641af32596568b83bfc76525b1a44b82faa51064debc420c24535572dd9e89372a77f487054de15aea3b17a2d7043c7
6
+ metadata.gz: e73234c452933ed861dec4cde8735e455ed5ea36ccbc9fc682bd7f695f43573ebfc5f5fb723b57c490af2fdd56743480e5812efd67a521f3f8672169d2d7af7d
7
+ data.tar.gz: 36635a50188153c1f5d1df5b24eb024f12bcfc3b28496ec0deb2eaa918cd13cb571822945109b674f552b2f7fcad23519ef3347fc99d6e8f1ef91f85fdfdd179
@@ -3,13 +3,13 @@
3
3
  require 'uri'
4
4
  module CoverRage
5
5
  module Config
6
- def self.root_path
7
- @root_path ||= ENV.fetch('COVER_RAGE_ROOT_PATH', defined?(Rails) && Rails.root ? Rails.root.to_s : Dir.pwd)
6
+ def self.path_prefix
7
+ @path_prefix ||= ENV.fetch('COVER_RAGE_PATH_PREFIX', defined?(Rails) && Rails.root ? Rails.root.to_s : Dir.pwd)
8
8
  end
9
9
 
10
10
  def self.store
11
11
  @store ||= begin
12
- uri = URI.parse(ENV.fetch('COVER_RAGE_STORE_URL'))
12
+ uri = URI.parse(ENV.fetch('COVER_RAGE_STORE_URL', "pstore:#{File.join(Dir.pwd, 'cover_rage.pstore')}"))
13
13
  case uri.scheme
14
14
  when 'redis', 'rediss'
15
15
  require 'cover_rage/stores/redis'
@@ -17,14 +17,19 @@ module CoverRage
17
17
  when 'sqlite'
18
18
  require 'cover_rage/stores/sqlite'
19
19
  CoverRage::Stores::Sqlite.new(uri.path)
20
+ when 'pstore'
21
+ require 'cover_rage/stores/pstore'
22
+ CoverRage::Stores::Pstore.new(uri.path)
23
+ else
24
+ raise "Unsupported store: #{uri.scheme}"
20
25
  end
21
26
  end
22
27
  end
23
28
 
24
- def self.sleep_duration
25
- @sleep_duration ||= begin
29
+ def self.interval
30
+ @interval ||= begin
26
31
  args =
27
- ENV.fetch('COVER_RAGE_SLEEP_DURATION', '60:90').split(':').map!(&:to_i).first(2)
32
+ ENV.fetch('COVER_RAGE_INTERVAL', '60:90').split(':').map!(&:to_i).first(2)
28
33
  args.push(args.first.succ) if args.length < 2
29
34
  Range.new(*args, true)
30
35
  end
@@ -11,7 +11,7 @@ module CoverRage
11
11
  if @recorder.nil?
12
12
  @recorder = CoverRage::Recorder.new(
13
13
  store: CoverRage::Config.store,
14
- root_path: CoverRage::Config.root_path,
14
+ path_prefix: CoverRage::Config.path_prefix,
15
15
  **kwargs
16
16
  )
17
17
  end
@@ -6,13 +6,12 @@ require 'digest'
6
6
 
7
7
  module CoverRage
8
8
  class Recorder
9
- SLEEP_DURATION = Config.sleep_duration
10
- COVERAGE_STOP_STATES = %i[idle suspended].freeze
9
+ INTERVAL = Config.interval
11
10
  attr_reader :store
12
11
 
13
- def initialize(root_path:, store:)
12
+ def initialize(path_prefix:, store:)
14
13
  @store = store
15
- @root_path = root_path.end_with?('/') ? root_path : "#{root_path}/"
14
+ @path_prefix = path_prefix.end_with?('/') ? path_prefix : "#{path_prefix}/"
16
15
  @digest = Digest::MD5.new
17
16
  @file_cache = {}
18
17
  end
@@ -20,14 +19,15 @@ module CoverRage
20
19
  def start
21
20
  return if @thread&.alive?
22
21
 
23
- Coverage.start if COVERAGE_STOP_STATES.include?(Coverage.state)
22
+ unless Coverage.running?
23
+ Coverage.start
24
+ at_exit { save(Coverage.result) }
25
+ end
24
26
  @thread = Thread.new do
25
27
  loop do
26
- sleep(rand(SLEEP_DURATION))
28
+ sleep(rand(INTERVAL))
27
29
  save(Coverage.result(stop: false, clear: true))
28
30
  end
29
- ensure
30
- save(Coverage.result)
31
31
  end
32
32
  end
33
33
 
@@ -37,10 +37,10 @@ module CoverRage
37
37
  records = []
38
38
  coverage_result.map do |filepath, execution_count|
39
39
  filepath = File.expand_path(filepath) unless filepath.start_with?('/')
40
- next unless filepath.start_with?(@root_path)
40
+ next unless filepath.start_with?(@path_prefix)
41
41
  next if execution_count.all? { _1.nil? || _1.zero? }
42
42
 
43
- relative_path = filepath.delete_prefix(@root_path)
43
+ relative_path = filepath.delete_prefix(@path_prefix)
44
44
  revision, source = read_file_with_revision(filepath)
45
45
 
46
46
  records << Record.new(
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cover_rage/record'
4
+ require 'pstore'
5
+
6
+ module CoverRage
7
+ module Stores
8
+ class Pstore
9
+ def initialize(path)
10
+ @store = PStore.new(path, true)
11
+ end
12
+
13
+ def import(records)
14
+ @store.transaction do
15
+ persisted_records = @store.keys.map { @store[_1] }
16
+ records_to_save = Record.merge(persisted_records, records)
17
+ records_to_save.each { @store[_1.path] = _1 }
18
+ end
19
+ end
20
+
21
+ def find(path)
22
+ @store.transaction { @store[path] }
23
+ end
24
+
25
+ def list
26
+ @store.transaction do
27
+ @store.keys.map { @store[_1] }
28
+ end
29
+ end
30
+
31
+ def clear
32
+ @store.transaction do
33
+ @store.keys.each { @store.delete(_1) }
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cover_rage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Weihang Jian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-02 00:00:00.000000000 Z
11
+ date: 2024-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -41,9 +41,10 @@ dependencies:
41
41
  description: |
42
42
  A Ruby production code coverage tool designed to assist you in identifying unused code, offering the following features:
43
43
 
44
- 1. easy setup
45
- 2. minimal performance overhead
46
- 3. minimal external dependencies
44
+ 1. zero dependencies
45
+ 2. super easy setup
46
+ 3. support process forking without additional configuration
47
+ 4. minimal performance overhead
47
48
  email: tonytonyjan@gmail.com
48
49
  executables:
49
50
  - cover_rage
@@ -60,6 +61,7 @@ files:
60
61
  - lib/cover_rage/reporters/html_reporter.rb
61
62
  - lib/cover_rage/reporters/html_reporter/index.html.erb
62
63
  - lib/cover_rage/reporters/json_reporter.rb
64
+ - lib/cover_rage/stores/pstore.rb
63
65
  - lib/cover_rage/stores/redis.rb
64
66
  - lib/cover_rage/stores/sqlite.rb
65
67
  homepage: https://github.com/tonytonyjan/cover_rage
@@ -81,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
83
  - !ruby/object:Gem::Version
82
84
  version: '0'
83
85
  requirements: []
84
- rubygems_version: 3.4.13
86
+ rubygems_version: 3.5.23
85
87
  signing_key:
86
88
  specification_version: 4
87
89
  summary: A Ruby production code coverage tool