code_keeper 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +8 -13
- data/lib/code_keeper/config.rb +2 -1
- data/lib/code_keeper/formatter.rb +11 -18
- data/lib/code_keeper/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36a68ad1540e4e6adb062bc85c1ab015c280bfe604ac5644cdfc21dd1df58c9d
|
4
|
+
data.tar.gz: 6850f00648efb8910be1eaf0125a3aa39a799a888a31e2c971946cab337dbdbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87718f55c24471bee5b26d21d108445103111b135e117872d8c0e709b20a21cdbd6b865d06db277e29722eb607ba3bb687f8eef6c509e68a47c1563052d7b2e3
|
7
|
+
data.tar.gz: 63938e0590f3c9faa32ef9f71d7a1b45cc3685d0a46d2a53aaa6d8c222eefaf3119cb2bb5aac2eeb618a0bf092999c4283f3b98fc36554218624c4a9027b9054
|
data/CHANGELOG.md
CHANGED
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
|
29
|
-
|
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 =
|
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
|
|
data/lib/code_keeper/config.rb
CHANGED
@@ -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
|
-
|
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
|
13
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
data/lib/code_keeper/version.rb
CHANGED