code_poetry 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/.travis.yml +4 -1
- data/README.md +15 -0
- data/bin/code_poetry +7 -0
- data/lib/code_poetry/calculator.rb +3 -3
- data/lib/code_poetry/churn_calculator.rb +10 -2
- data/lib/code_poetry/cli.rb +18 -14
- data/lib/code_poetry/formatter/cl_formatter.rb +62 -0
- data/lib/code_poetry/railtie.rb +2 -2
- data/lib/code_poetry/version.rb +1 -1
- data/lib/code_poetry.rb +10 -15
- data/lib/tasks/code_poetry.rake +3 -2
- metadata +6 -4
- data/lib/code_poetry/formatter.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea6e417400284ac72f6bee76317c61e49bb9a283
|
4
|
+
data.tar.gz: 87455110a8b39f187265f81eaa77e04038021770
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4e3b43fc5062d77356f025b26de306dd9304668b0e7c5f890c98ff28439ca97e4760d2db497b00e41deef93e8f7457c40d4cc74b119be83bfc8840732747436
|
7
|
+
data.tar.gz: 1ac55bdded39fe400b920aadc826de01aa7afbc22aec9a0b0faa287c202ead3ef3ef5ad2e6f3c3eb6942be4a719c6d1a444f49ac29764bd08cd08eabd219a6ab
|
data/.travis.yml
CHANGED
@@ -2,11 +2,14 @@ language: ruby
|
|
2
2
|
rvm:
|
3
3
|
- 1.9.3
|
4
4
|
- 2.0.0
|
5
|
+
- 2.1.0
|
6
|
+
- 2.2.0
|
5
7
|
addons:
|
6
8
|
code_climate:
|
7
9
|
repo_token:
|
8
10
|
secure: "JJb9iyhNuNNUpnjGMWjNNIjaPOST53+vAzb6RHdzNKRC6jKgWZMXZsJ3Tzb6xFe21l+FmdBk+mKWVFHoBvUOlK34++CeXwDek8PhFi6bp7lJASqUabB66o32WPdTYnWy4WV5BesXJyFeKRL2SyFGoOw8B8Cpx+DrOVLR71s5Ovs="
|
9
11
|
notifications:
|
10
|
-
|
12
|
+
email: false
|
13
|
+
slack:
|
11
14
|
rooms:
|
12
15
|
secure: "bXtxfw97KhPDFNiS402PghKK2fvcfF4diZUWPaJu2VhRzBabveD+j4F4XQW7glRXcGzypOuCYqyTqHFXjjItO52+PEz4gUwak42UnFjHcGQ3//OeQB9bqCkR7IgyjILfWOS57JJE9XHa34p+cWnYntQ/u10rTiyivC1vfmjiufs="
|
data/README.md
CHANGED
@@ -23,6 +23,10 @@ And then execute:
|
|
23
23
|
|
24
24
|
$ bundle
|
25
25
|
|
26
|
+
Or install it yourself:
|
27
|
+
|
28
|
+
$ gem install code-poetry
|
29
|
+
|
26
30
|
## Usage
|
27
31
|
|
28
32
|
Excecute from your application root:
|
@@ -31,6 +35,17 @@ Excecute from your application root:
|
|
31
35
|
|
32
36
|
This will generate a HTML report to ```metrics/index.html```.
|
33
37
|
|
38
|
+
Or if you installed the gem globally use:
|
39
|
+
|
40
|
+
$ code_poetry
|
41
|
+
|
42
|
+
This will display your smells in the command line.
|
43
|
+
|
44
|
+
You can also give a path to a file or subdirectory if you only want metrics for
|
45
|
+
those files:
|
46
|
+
|
47
|
+
$ code_poetry app/models
|
48
|
+
|
34
49
|
## Contributing
|
35
50
|
|
36
51
|
1. Fork it
|
data/bin/code_poetry
ADDED
@@ -1,6 +1,6 @@
|
|
1
1
|
class ChurnCalculator
|
2
|
-
def initialize(
|
3
|
-
@repo_path =
|
2
|
+
def initialize(path)
|
3
|
+
@repo_path = find_directory(path)
|
4
4
|
end
|
5
5
|
|
6
6
|
def calculate
|
@@ -9,6 +9,14 @@ class ChurnCalculator
|
|
9
9
|
|
10
10
|
private
|
11
11
|
|
12
|
+
def find_directory(path)
|
13
|
+
if File.file?(path)
|
14
|
+
File.dirname(path)
|
15
|
+
else
|
16
|
+
path
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
12
20
|
def parse_log_for_churns
|
13
21
|
churns = {}
|
14
22
|
|
data/lib/code_poetry/cli.rb
CHANGED
@@ -1,29 +1,33 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require 'code_poetry/formatter'
|
4
|
-
require 'code_poetry-html'
|
1
|
+
require "code_poetry/calculator"
|
2
|
+
require "code_poetry/stat"
|
5
3
|
|
6
4
|
module CodePoetry
|
7
5
|
class CLI
|
8
|
-
DIRECOTRIES =
|
9
|
-
|
6
|
+
DIRECOTRIES = "app,lib"
|
7
|
+
|
8
|
+
def self.execute(path, formatter)
|
9
|
+
files = find_files(path)
|
10
10
|
|
11
|
-
def self.excecute(path)
|
12
|
-
files = Array(expand_directories_to_files(path).sort).compact
|
13
11
|
calculator = Calculator.new(path, files)
|
14
12
|
stats = calculator.calculate
|
15
13
|
|
16
|
-
formatter = CodePoetry::Formatter::HTMLFormatter.new
|
17
14
|
formatter.format(stats)
|
18
15
|
end
|
19
16
|
|
20
|
-
|
17
|
+
private
|
18
|
+
|
19
|
+
def self.find_files(path)
|
20
|
+
paths = expand_path_to_files(path)
|
21
|
+
Array(paths).compact.sort
|
22
|
+
end
|
21
23
|
|
22
|
-
def self.
|
23
|
-
if path
|
24
|
-
Dir[File.join(
|
24
|
+
def self.expand_path_to_files(path)
|
25
|
+
if path.nil?
|
26
|
+
Dir[File.join(".", "{#{DIRECOTRIES}**}", "**", "*.rb")]
|
27
|
+
elsif File.file?(path)
|
28
|
+
path
|
25
29
|
else
|
26
|
-
|
30
|
+
Dir[File.join(path, "**", "*.rb")]
|
27
31
|
end
|
28
32
|
end
|
29
33
|
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module CodePoetry
|
2
|
+
module Formatter
|
3
|
+
class CLFormatter
|
4
|
+
def format(stats)
|
5
|
+
smelly_stats = stats.reject { |stat| stat.smells.empty? }
|
6
|
+
|
7
|
+
smelly_stats.each { |stat| print_smells_for(stat) }
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def print_smells_for(stat)
|
13
|
+
smells = stat.smells
|
14
|
+
return if smells.empty?
|
15
|
+
|
16
|
+
puts stat.name
|
17
|
+
|
18
|
+
smells.each do |smell|
|
19
|
+
print_smell(stat, smell)
|
20
|
+
end
|
21
|
+
|
22
|
+
puts
|
23
|
+
end
|
24
|
+
|
25
|
+
def print_smell(stat, smell)
|
26
|
+
send("print_#{smell.type}", stat, smell)
|
27
|
+
end
|
28
|
+
|
29
|
+
def print_duplication(stat, smell)
|
30
|
+
duplication = smell.object
|
31
|
+
|
32
|
+
puts <<-MESSAGE.gsub(/^ {8}/, '').gsub(/\n /, ' ')
|
33
|
+
#{duplication.severity} Code found in #{duplication.node} nodes
|
34
|
+
(mass = #{duplication.mass})
|
35
|
+
MESSAGE
|
36
|
+
|
37
|
+
duplication.methods.each do |method|
|
38
|
+
puts " #{method.pretty_location}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def print_complex_method(_, smell)
|
43
|
+
method = smell.object
|
44
|
+
|
45
|
+
puts <<-MESSAGE.gsub(/^ {8}/, '').gsub(/\n /, ' ')
|
46
|
+
Complex Method #{method.pretty_name} #{method.complexity}
|
47
|
+
(complexity = #{method.complexity})
|
48
|
+
MESSAGE
|
49
|
+
end
|
50
|
+
|
51
|
+
def print_complex_class(stat, _)
|
52
|
+
puts " Complex Class (complexity = #{stat.complexity})"
|
53
|
+
end
|
54
|
+
|
55
|
+
def print_complex_class_definition(stat, _)
|
56
|
+
puts <<-MESSAGE.gsub(/^ {8}/, '')
|
57
|
+
Complex Class Definition (complexity = #{stat.definition_complexity})
|
58
|
+
MESSAGE
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/code_poetry/railtie.rb
CHANGED
data/lib/code_poetry/version.rb
CHANGED
data/lib/code_poetry.rb
CHANGED
@@ -1,32 +1,27 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "code_poetry/version"
|
2
|
+
require "fileutils"
|
3
3
|
|
4
4
|
module CodePoetry
|
5
5
|
if defined?(Rails)
|
6
|
-
require
|
7
|
-
else
|
8
|
-
load 'tasks/code_poetry.rake'
|
6
|
+
require "code_poetry/railtie"
|
9
7
|
end
|
10
8
|
|
11
9
|
class << self
|
12
10
|
def root
|
13
|
-
|
14
|
-
@root = File.expand_path(Dir.getwd)
|
11
|
+
@root ||= File.expand_path(Dir.getwd)
|
15
12
|
end
|
16
13
|
|
17
14
|
def coverage_path
|
18
|
-
coverage_path = File.expand_path(
|
19
|
-
FileUtils.mkdir_p
|
15
|
+
coverage_path = File.expand_path("metrics", root)
|
16
|
+
FileUtils.mkdir_p(coverage_path)
|
20
17
|
coverage_path
|
21
18
|
end
|
22
19
|
|
23
20
|
def project_name
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
def project_name
|
29
|
-
File.basename(root.split('/').last).capitalize.gsub('_', ' ')
|
21
|
+
@project_name ||= File.basename(root)
|
22
|
+
.split(/[-_]/)
|
23
|
+
.map(&:capitalize)
|
24
|
+
.join(" ")
|
30
25
|
end
|
31
26
|
end
|
32
27
|
end
|
data/lib/tasks/code_poetry.rake
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
desc 'Generate code metrics'
|
2
2
|
task :metrics, :path do |t, args|
|
3
|
+
require 'code_poetry-html'
|
3
4
|
require 'code_poetry/cli'
|
4
5
|
|
5
|
-
|
6
|
+
formatter = CodePoetry::Formatter::HTMLFormatter.new
|
6
7
|
|
7
|
-
CodePoetry::CLI.
|
8
|
+
CodePoetry::CLI.execute(args.path, formatter)
|
8
9
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: code_poetry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bastian Bartmann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: code_poetry-html
|
@@ -112,7 +112,8 @@ description: Analyzes the code of your Rails app and generates a straightforward
|
|
112
112
|
report.
|
113
113
|
email:
|
114
114
|
- babartmann@gmail.com
|
115
|
-
executables:
|
115
|
+
executables:
|
116
|
+
- code_poetry
|
116
117
|
extensions: []
|
117
118
|
extra_rdoc_files: []
|
118
119
|
files:
|
@@ -124,6 +125,7 @@ files:
|
|
124
125
|
- LICENSE
|
125
126
|
- README.md
|
126
127
|
- Rakefile
|
128
|
+
- bin/code_poetry
|
127
129
|
- code_poetry.gemspec
|
128
130
|
- lib/code_poetry.rb
|
129
131
|
- lib/code_poetry/calculator.rb
|
@@ -131,7 +133,7 @@ files:
|
|
131
133
|
- lib/code_poetry/cli.rb
|
132
134
|
- lib/code_poetry/complexity_calculator.rb
|
133
135
|
- lib/code_poetry/duplication_calculator.rb
|
134
|
-
- lib/code_poetry/formatter.rb
|
136
|
+
- lib/code_poetry/formatter/cl_formatter.rb
|
135
137
|
- lib/code_poetry/method.rb
|
136
138
|
- lib/code_poetry/railtie.rb
|
137
139
|
- lib/code_poetry/stat.rb
|