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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f35c59a997f5fcc5544ad1c8e67e46e1d8fda47
4
- data.tar.gz: 16e6e142767e8a0c4ce0b57b1be521945c958d78
3
+ metadata.gz: ea6e417400284ac72f6bee76317c61e49bb9a283
4
+ data.tar.gz: 87455110a8b39f187265f81eaa77e04038021770
5
5
  SHA512:
6
- metadata.gz: ae820ea69f026dc1be7fcf43e9a91647856cb5798caabda62da9026cf82652f505628412d57aa6339a2b28f2988d2bfb9b22716247c22b61eb4631a550f96392
7
- data.tar.gz: 1086ea2c0e514b3a0e68aeb2a0faf46aa5a2384a6dde95f4e7ec2ff7e8feaebcb1cf53986a64f49aa494b04fcb54016feec6c12ae0c06b36a188e52c7a808bf1
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
- slack:
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
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ require "code_poetry/formatter/cl_formatter"
3
+ require "code_poetry/cli"
4
+
5
+ formatter = CodePoetry::Formatter::CLFormatter.new
6
+
7
+ CodePoetry::CLI.execute(ARGV[0], formatter)
@@ -5,9 +5,9 @@ require 'code_poetry/duplication_calculator'
5
5
  module CodePoetry
6
6
  class Calculator
7
7
  def initialize(path, files)
8
- @path = path
9
- @files = files
10
- @stats = []
8
+ @path = path || '.'
9
+ @files = files
10
+ @stats = []
11
11
  end
12
12
 
13
13
  def calculate
@@ -1,6 +1,6 @@
1
1
  class ChurnCalculator
2
- def initialize(repo_path)
3
- @repo_path = 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
 
@@ -1,29 +1,33 @@
1
- require 'code_poetry/calculator'
2
- require 'code_poetry/stat'
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 = 'app,lib'
9
- EXTENSIONS = 'rb,rake'
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
- private
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.expand_directories_to_files(path)
23
- if path
24
- Dir[File.join(path, "{#{DIRECOTRIES}}**", '**', "*.{#{EXTENSIONS}}")]
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
- FileList[File.join("{#{DIRECOTRIES}}**", '**', "*.{#{EXTENSIONS}}")]
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
@@ -1,11 +1,11 @@
1
- require 'rails'
1
+ require "rails"
2
2
 
3
3
  module CodePoetry
4
4
  class Railtie < Rails::Railtie
5
5
  railtie_name :code_poetry
6
6
 
7
7
  rake_tasks do
8
- load 'tasks/code_poetry.rake'
8
+ load "tasks/code_poetry.rake"
9
9
  end
10
10
  end
11
11
  end
@@ -1,3 +1,3 @@
1
1
  module CodePoetry
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/code_poetry.rb CHANGED
@@ -1,32 +1,27 @@
1
- require 'code_poetry/version'
2
- require 'fileutils'
1
+ require "code_poetry/version"
2
+ require "fileutils"
3
3
 
4
4
  module CodePoetry
5
5
  if defined?(Rails)
6
- require 'code_poetry/railtie'
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
- return @root if defined? @root
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('metrics', root)
19
- FileUtils.mkdir_p coverage_path
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
- return @project_name if defined? @project_name
25
- @project_name = File.basename(root.split('/').last).capitalize.gsub('_', ' ')
26
- end
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
@@ -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
- path = args.path || '.'
6
+ formatter = CodePoetry::Formatter::HTMLFormatter.new
6
7
 
7
- CodePoetry::CLI.excecute(path)
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.3.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-02-06 00:00:00.000000000 Z
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
@@ -1,4 +0,0 @@
1
- module CodePoetry
2
- module Formatter
3
- end
4
- end