akainaa 0.1.2 → 0.1.5

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: 6451f71725cda32349ab87402b32e6e132d8185274ba55a930fa2389fdd12279
4
- data.tar.gz: 2b40049516aa512d8a89b607d327b1a5571b3c4221e351248d4ac13bbdc31dfd
3
+ metadata.gz: a6602589d81aa7812d340812b17c6cc253356605aaf40fc3746aa1ab409b0d94
4
+ data.tar.gz: f4c7d56da714844abb1dc8f8a9977b3cb14065d2eec7c852e9b1aa902f212cff
5
5
  SHA512:
6
- metadata.gz: f3199e1047c1295040cf043154128fcef145da13815f1cf8b69c84ec4a3237e44c525107ccb97abcc115d9d12f810e40623685843e190bb07cb99f95e35b104d
7
- data.tar.gz: 74c12cf59e645eef87f2811d95d584a32ed5ec54b6f75019114c8f595fa206e0121cf7413c87a3b53fb4523f62cc7b45ee004aab467594f4dffd2153af00d045
6
+ metadata.gz: 21b88780fb3299dc630d3aa83dc0a7fa8cc94d486e908c54c3681c87d3ac619eef2cdf71c646f6aa71d01016b64573de338cbc09f8a8b3367f836902a74571b8
7
+ data.tar.gz: 7239bd4af6b74ee056ac78959b8220a2bebddadcc4b0bc6a21f58ad7bb5471c44f51810032b56912e3c3c4743baadaf530235b11f10930915fcdeed7bd27dc83
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.1.5] - 2024-09-10
4
+
5
+ - Bug fix: nested method call won't handled
6
+ - Bug fix: Empty 302 response body on /akainaa/reset
7
+ - Feature: Add `ignore_glob_patterns` option to `Akainaa.start` method
8
+ - Feature: Add `hide_not_executed_files` option to `Akainaa.start` method
9
+ - Feature: Add `online_emit` option to `Akainaa.start` method
10
+
3
11
  ## [0.1.2] - 2024-05-06
4
12
 
5
13
  - Coloring all line of the method which located on multiple lines
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Akainaa (赤いなぁ)
1
+ # Akainaa (赤いなぁ、 It's red...)
2
2
 
3
3
  ![page view](./img/webui-rev02.png)
4
4
 
@@ -28,7 +28,13 @@ Here is example:
28
28
  ```ruby
29
29
  require 'akainaa'
30
30
 
31
- Akainaa.start(project_dir: File.expand_path(__dir__))
31
+ Akainaa.start(
32
+ project_dir: File.expand_path(__dir__),
33
+ ignore_glob_patterns: %w[
34
+ config/application.rb
35
+ config/initializers/*_initializer.rb
36
+ ],
37
+ )
32
38
 
33
39
  require_relative 'app'
34
40
 
@@ -39,6 +45,26 @@ run App
39
45
  Boot up application, do something, and access `/akainaa`.
40
46
  It will show Web UI what and how many executed.
41
47
 
48
+ ### Enable online emit mode
49
+
50
+ Akainaa can emit coverage data which recorded in interval to the file.
51
+ This feature is intended to be used with vscode-akainaa extension.
52
+
53
+ ```ruby
54
+ Akainaa.start(
55
+ project_dir: File.expand_path(__dir__),
56
+ ignore_glob_patterns: %w[
57
+ config/application.rb
58
+ config/initializers/*_initializer.rb
59
+ ],
60
+ online_emit: {
61
+ mode: :file,
62
+ interval: 1, # seconds
63
+ output_path: '/tmp/akainaa.json',
64
+ },
65
+ )
66
+ ```
67
+
42
68
  ## Development
43
69
 
44
70
  After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
data/lib/akainaa/util.rb CHANGED
@@ -19,6 +19,7 @@ module Akainaa
19
19
 
20
20
  visitor.multiline_method_calls.each do |method_range|
21
21
  call_count = lines[method_range.start_line_as_idx]
22
+ next if call_count.nil?
22
23
 
23
24
  method_range.method_row_range_as_idx.each do |idx|
24
25
  if fullfilled_lines[idx].nil?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Akainaa
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.5"
5
5
  end
data/lib/akainaa.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'coverage'
4
+ require 'fileutils'
4
5
 
5
6
  require_relative 'akainaa/version'
6
7
  require_relative 'akainaa/call_node_visitor'
@@ -10,24 +11,90 @@ module Akainaa
10
11
  class Error < StandardError; end
11
12
 
12
13
  class << self
13
- attr_accessor :project_dir
14
-
15
- def start(project_dir:)
14
+ attr_accessor :project_dir, :ignore_files, :hide_not_executed_files
15
+
16
+ def start(
17
+ project_dir:,
18
+ ignore_glob_patterns: [],
19
+ hide_not_executed_files: false,
20
+ online_emit: nil
21
+ )
16
22
  @project_dir = project_dir
17
23
  @project_dir += '/' unless @project_dir.end_with?('/')
24
+ ignore_files = ignore_glob_patterns.flat_map do |pattern|
25
+ Dir["#{@project_dir}#{pattern}"].to_a
26
+ end
27
+ @ignore_files = Set.new(ignore_files)
28
+ @hide_not_executed_files = hide_not_executed_files
29
+ @monitor = Monitor.new
18
30
 
19
31
  Coverage.start(lines: true)
32
+
33
+ if online_emit.is_a?(Hash)
34
+ option = default_online_emit.merge(online_emit)
35
+ FileUtils.mkdir_p(File.dirname(option[:path]))
36
+ start_multipart_emit(option)
37
+ end
20
38
  end
21
39
 
22
40
  def peek_result
23
41
  Coverage
24
42
  .peek_result
25
43
  .select { |k, _v| k.start_with?(project_dir) }
44
+ .reject { |k, _v| ignore_files.member?(k) }
26
45
  .transform_keys { |k| k.sub(project_dir, '') }
27
46
  end
28
47
 
29
48
  def reset
30
- Coverage.result(stop: false, clear: true)
49
+ @monitor.synchronize do
50
+ Coverage.result(stop: false, clear: true)
51
+ @previous_result = {}
52
+ end
53
+ end
54
+
55
+ private def default_online_emit
56
+ {
57
+ mode: :file,
58
+ interval: 1,
59
+ path: 'tmp/coverage.json',
60
+ }
61
+ end
62
+
63
+ private def start_multipart_emit(option)
64
+ Thread.new do
65
+ @monitor.synchronize do
66
+ @previous_result = {}
67
+ end
68
+
69
+ loop do
70
+ sleep option[:interval]
71
+ current_result = peek_result
72
+
73
+ diff = {}
74
+ current_result.each do |path, path_coverage|
75
+ previous_path_coverage = @previous_result[path]
76
+
77
+ if previous_path_coverage.nil?
78
+ diff[path] = path_coverage
79
+ elsif previous_path_coverage[:lines].size != path_coverage[:lines].size
80
+ diff[path] = path_coverage
81
+ else
82
+ diff[path] = { lines: [] }
83
+
84
+ path_coverage[:lines].each_with_index do |count, index|
85
+ val = count ? count - previous_path_coverage[:lines][index] : nil
86
+
87
+ diff[path][:lines] << val
88
+ end
89
+ end
90
+ end
91
+
92
+ @monitor.synchronize do
93
+ @previous_result = current_result
94
+ end
95
+ File.write(option[:path], diff.to_json)
96
+ end
97
+ end
31
98
  end
32
99
  end
33
100
 
@@ -48,7 +115,7 @@ module Akainaa
48
115
  path = extract_path_from_query(env)
49
116
  Akainaa.reset
50
117
 
51
- [302, { 'Location' => "/akainaa?path=#{path}" }, [html]]
118
+ [302, { 'Location' => "/akainaa?path=#{path}" }, []]
52
119
  else
53
120
  @app.call(env)
54
121
  end
@@ -83,6 +150,8 @@ module Akainaa
83
150
 
84
151
  li_elements = files.sort.map do |file|
85
152
  total_count_on_file = coverage_result[file][:lines].reject(&:nil?).sum
153
+ next '' if Akainaa.hide_not_executed_files && total_count_on_file == 0
154
+
86
155
  count_top = (total_count_on_file * 10 / max_count_on_proj).to_i * 10
87
156
 
88
157
  class_suffix = file == current_path ? ' current' : ''
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: akainaa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shia
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-06 00:00:00.000000000 Z
11
+ date: 2024-09-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Minimum rack middleware for coverage
14
14
  email:
@@ -47,7 +47,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
47
47
  - !ruby/object:Gem::Version
48
48
  version: '0'
49
49
  requirements: []
50
- rubygems_version: 3.6.0.dev
50
+ rubygems_version: 3.5.11
51
51
  signing_key:
52
52
  specification_version: 4
53
53
  summary: Minimum rack middleware for coverage