code_keeper 0.3.0 → 0.4.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: 1d30fec72da618c4ce29c0c819fb0a912cb968d829182143337b537ec3a69dbc
4
- data.tar.gz: f24e1bc9e08780f4e6c2f1943b4620671da06d1ff71026d8e81a00300137b352
3
+ metadata.gz: 36a68ad1540e4e6adb062bc85c1ab015c280bfe604ac5644cdfc21dd1df58c9d
4
+ data.tar.gz: 6850f00648efb8910be1eaf0125a3aa39a799a888a31e2c971946cab337dbdbb
5
5
  SHA512:
6
- metadata.gz: ef7a1991ea72b93c1c47d6d07376008ca0d0e9b0da1156bdcedee4cd7efa96b9896912680c0520d8516a9a8486052d753b799fb836610787a794bc0b5001e5fe
7
- data.tar.gz: 1c66dd84f996a705b93513bcd45b342cf1d3fba28d4773b84c882489b860c86024293096a0285580e38bde529e4dc53feb84b5cb719afe4ec0c8735ff078b7d5
6
+ metadata.gz: 87718f55c24471bee5b26d21d108445103111b135e117872d8c0e709b20a21cdbd6b865d06db277e29722eb607ba3bb687f8eef6c509e68a47c1563052d7b2e3
7
+ data.tar.gz: 63938e0590f3c9faa32ef9f71d7a1b45cc3685d0a46d2a53aaa6d8c222eefaf3119cb2bb5aac2eeb618a0bf092999c4283f3b98fc36554218624c4a9027b9054
data/CHANGELOG.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  ## Unrelease
4
4
 
5
+ ## 0.4.0 (2021-09-15)
6
+ ### New features
7
+ - [#30](https://github.com/ebihara99999/code_keeper/pull/30): Support CSV and JSON format.
8
+
5
9
  ## 0.3.0 (2021-09-15)
6
10
 
7
11
  ### New features
data/README.md CHANGED
@@ -3,7 +3,7 @@ The CodeKeeper measures metrics especially about complexity and size of Ruby fil
3
3
 
4
4
  Mesuring metrics leads to keep codebase simple and clean, and I name the gem CodeKeeper.
5
5
 
6
- Now CodeKeeper supports the cyclomatic complexity of a file, the ABC software metric of a file, and class length. The scores are output to stdout.
6
+ Now CodeKeeper supports the cyclomatic complexity of a file, the ABC software metric of a file, and class length. The scores are output to stdout of a json or csv format.
7
7
 
8
8
  ## Installation
9
9
 
@@ -25,18 +25,11 @@ Or install it yourself as:
25
25
  Run CodeKeeper and you get scores of metrics from stdout like
26
26
 
27
27
  ```rb
28
- $ bundle exec code_keeper ./app/models
29
- Scores:
30
-
31
- Metric: cyclomatic_complexity
32
- Filename: app/models/admin.rb
33
- Score: 1
34
- ---
35
- Metric: cyclomatic_complexity
36
- Filename: app/models/user.rb
37
- Score: 23
38
- ---
28
+ $ bundle exec code_keeper app/models/user.rb app/models/admin.rb > metrics.json
29
+ $ cat metrics.json
30
+ {"cyclomatic_complexity":{"app/models/admin.rb":9,"app/models/user.rb":23},"class_length":{"Admin":86,"User":1475},"abc_metric":{"app/models/admin.rb":76.909,"app/models/user.rb":1546.4155}}
39
31
  ```
32
+ If you need a csv format, change the configuration as explained later.
40
33
 
41
34
  ### Run CodeKeeper
42
35
  To measure metrics of all the ruby files recursively in the current directory, run
@@ -55,9 +48,11 @@ CodeKeeper makes you configure the following way:
55
48
  ```rb
56
49
  CodeKeeper.configure do |config|
57
50
  # If you choose metrics, specify as follows:
58
- config.metrics = [:cyclomatic_complexity]
51
+ config.metrics = %i(cyclomatic_complexity abc_metric class_length)
59
52
  # The number of threads. The default is 2. Executed sequentially if you set 1.
60
53
  config.number_of_threads = 4
54
+ # The default is json
55
+ config.format = :json
61
56
  end
62
57
  ```
63
58
 
@@ -3,11 +3,12 @@
3
3
  module CodeKeeper
4
4
  # Provide configuration
5
5
  class Config
6
- attr_accessor :metrics, :number_of_threads
6
+ attr_accessor :metrics, :number_of_threads, :format
7
7
 
8
8
  def initialize
9
9
  @metrics = %i[cyclomatic_complexity class_length abc_metric]
10
10
  @number_of_threads = 2
11
+ @format = :json # json and csv are supported.
11
12
  end
12
13
  end
13
14
  end
@@ -1,32 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'csv'
4
+
3
5
  module CodeKeeper
4
6
  # Format a result and make it human-readable.
5
7
  class Formatter
6
8
  class << self
7
9
  def format(result)
8
- title = "Scores:\n\n"
9
- formatted_result = +title
10
+ return result.scores.to_json if CodeKeeper.config.format == :json
10
11
 
12
+ # csv is supported besides json
13
+ csv_array = []
11
14
  result.scores.each_key do |metric|
12
- result.scores[metric].each do |k, v|
13
- klass_or_file_key = if metric == :class_length
14
- 'Class'
15
- else
16
- 'Filename'
17
- end
15
+ result.scores[metric].each { |k, v| csv_array << [metric, k, v] }
16
+ end
18
17
 
19
- formatted_result.concat(
20
- <<~EOS
21
- Metric: #{metric}
22
- #{klass_or_file_key}: #{k}
23
- Score: #{v}
24
- ---
25
- EOS
26
- )
27
- end
18
+ headers = %w[metric file score]
19
+ CSV.generate(headers: true) do |csv|
20
+ csv << headers
21
+ csv_array.each { |array| csv << array }
28
22
  end
29
- formatted_result
30
23
  end
31
24
  end
32
25
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CodeKeeper
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_keeper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yusuke Ebihara