rails_stats 0.0.4 → 0.0.6

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
  SHA1:
3
- metadata.gz: 944d0c8334fdcb76cec1a8f46b4df162318e79a8
4
- data.tar.gz: 937553b382a844f1eaf2e7aade385ba8440ec1b6
3
+ metadata.gz: 49a95d6e3cccd65728bc591f5beacb216608d9a6
4
+ data.tar.gz: 14506184a365bc2af465fa3e927cf3cbdb8f8e75
5
5
  SHA512:
6
- metadata.gz: 8ab477ff73f0e87134f71761397358388fb10947f8afad91da6ddc828c235eaf872116097be0747273a3c40d441808528e507c6e7814a89b5ea9da9702db832d
7
- data.tar.gz: 5803869bde15c3d38e2e41b6f1f279dc4993187cfe77e2d4148f67093b6b82fceab9e966e895e2ce0a874b1e80dbeb43b0084c555e34f868808257d97e4d4b81
6
+ metadata.gz: c579583a0acdefaa7388cc5c60df668c39d586575396d89d2a97abe24e594533c06a196b62a8369c92e46bb5d3f86facd3fd56d7b141fa54e441dbbcc025d981
7
+ data.tar.gz: 8dca4a07de86d2be8e26ae13767a611fb1d348c1bfc744648af333fa931680e9d438f4dd5dc8ff206c445a8b7bd4871919379effeff7283279fb190103361c24
data/README.md CHANGED
@@ -3,9 +3,9 @@
3
3
  See stuff about a Rails app.
4
4
 
5
5
  ```bash
6
- $ bundle exec thor stats:calculate ~/path/to/app/
6
+ $ bundle exec rake:stats[/path/to/app/]
7
7
 
8
- Directory: ~/path/to/app/
8
+ Directory: /path/to/app/
9
9
 
10
10
  +----------------------+-------+-------+---------+---------+-----+-------+
11
11
  | Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
@@ -30,11 +30,20 @@ Directory: ~/path/to/app/
30
30
 
31
31
  ```
32
32
 
33
+ ### Things it knows about
34
+
35
+ * Any concepts you've added within an `app` directory
36
+ * Configuration files
37
+ * Library files
38
+ * Gems that you've embedded in the project
39
+ * Engines and their code
40
+ * RSpec/Unit/Cucumber Tests
41
+
33
42
  ### TODO
34
43
 
35
- * option to print out by app directory (stats per engine)
44
+ * Option to print out by app directory (stats per engine)
36
45
  * Add views (jbuilder, erb, haml) but don't count towards ratios
37
- * Support JS for projects that have it in public
38
- * Add css but don't count towards ratios
39
- * output other metrics like number of tables and columns
40
- * test unit support
46
+ * Support JS for projects that have it in public (but not compiled)
47
+ * Add CSS but don't count towards ratios
48
+ * Output other metrics like number of tables and columns
49
+ * Different output formatters
data/Rakefile CHANGED
@@ -1,2 +1,8 @@
1
- require "bundler/gem_tasks"
1
+ require "rails_stats"
2
2
 
3
+ desc "Calculates the statistsics for a given Rails project"
4
+ task :stats, [:path] do |t, args|
5
+ root_directory = File.absolute_path(args[:path])
6
+ puts "\nDirectory: #{root_directory}\n\n"
7
+ RailsStats::CodeStatistics.new(root_directory).to_s
8
+ end
@@ -69,7 +69,7 @@ module RailsStats
69
69
  end
70
70
 
71
71
  def calculate_gem_projects
72
- gems = Util.calculate_projects(@root_directory, "**", "*.gemspec")
72
+ gems = Util.calculate_projects(@root_directory, "*", "**", "*.gemspec")
73
73
  gems.collect do |root_path|
74
74
  GemStatistics.new(root_path)
75
75
  end
@@ -83,7 +83,10 @@ module RailsStats
83
83
  end
84
84
 
85
85
  def calculate_test_projects
86
- [] # TODO: test unit
86
+ specs = Util.calculate_projects(@root_directory, "**", "test", "test_helper.rb")
87
+ specs.collect do |root_path|
88
+ TestStatistics.new(root_path, @key_concepts)
89
+ end
87
90
  end
88
91
 
89
92
  def calculate_root_projects
@@ -0,0 +1,74 @@
1
+ module RailsStats
2
+ class TestStatistics
3
+ attr_reader :statistics, :total, :test
4
+
5
+ SPEC_FOLDERS = ['controllers',
6
+ 'functional',
7
+ 'helpers',
8
+ 'models',
9
+ 'requests',
10
+ 'unit',
11
+ 'integrations',
12
+ 'integration',
13
+ 'mailers',
14
+ 'lib']
15
+
16
+ def initialize(directory, key_concepts)
17
+ @test = true
18
+ @directory = directory
19
+ @key_concepts = key_concepts
20
+ @statistics = calculate_statistics
21
+ @total = calculate_total
22
+ end
23
+
24
+ private
25
+
26
+ def calculate_total
27
+ out = CodeStatisticsCalculator.new(true)
28
+ @statistics.each do |key, stats|
29
+ out.add(stats)
30
+ end
31
+ out
32
+ end
33
+
34
+ def calculate_statistics
35
+ out = {}
36
+ categorize_files.each do |key, list|
37
+ out[key] = Util.calculate_file_statistics(list)
38
+ end
39
+ out
40
+ end
41
+
42
+ def categorize_files
43
+ out = {}
44
+ Dir[File.join(@directory, "**", "*.rb")].each do |file_path|
45
+ if file_path =~ /.*_test.rb$/
46
+ key = categorize_file(file_path)
47
+ else
48
+ key = "Test Support"
49
+ end
50
+
51
+ out[key] ||= []
52
+ out[key] << file_path
53
+ end
54
+
55
+ out
56
+ end
57
+
58
+ def categorize_file(file_path)
59
+ types = (@key_concepts + SPEC_FOLDERS).uniq
60
+ types.each do |folder|
61
+ if file_path =~ /\/#{folder}\//
62
+ folder = Inflector.humanize(folder)
63
+ folder = Inflector.titleize(folder)
64
+ folder = Inflector.singularize(folder)
65
+ return "#{folder} Tests"
66
+ end
67
+ end
68
+
69
+ # something else
70
+ return "Other Tests"
71
+ end
72
+ end
73
+
74
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsStats
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/rails_stats.rb CHANGED
@@ -10,11 +10,9 @@ require 'rails_stats/inflector'
10
10
  require 'rails_stats/code_statistics_calculator'
11
11
  require 'rails_stats/util'
12
12
  require 'rails_stats/app_statistics'
13
+ require 'rails_stats/test_statistics'
13
14
  require 'rails_stats/spec_statistics'
14
15
  require 'rails_stats/cucumber_statistics'
15
16
  require 'rails_stats/root_statistics'
16
17
  require 'rails_stats/gem_statistics'
17
18
  require 'rails_stats/code_statistics'
18
-
19
- require "rails_stats/rake"
20
- RailsStats.extend RailsStats::Rake
data/rails_stats.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["brian@bleonard.com"]
11
11
  spec.summary = %q{Analyze a Rails project}
12
12
  spec.description = %q{Point it to a directory and see stuff about the app}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/bleonard/rails_stats"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -18,7 +18,6 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "thor"
21
+ spec.add_dependency "rake"
22
22
  spec.add_development_dependency "bundler", "~> 1.6"
23
- spec.add_development_dependency "rake"
24
23
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Leonard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-04 00:00:00.000000000 Z
11
+ date: 2014-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: thor
14
+ name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - '>='
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.6'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - '>='
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  description: Point it to a directory and see stuff about the app
56
42
  email:
57
43
  - brian@bleonard.com
@@ -71,14 +57,13 @@ files:
71
57
  - lib/rails_stats/cucumber_statistics.rb
72
58
  - lib/rails_stats/gem_statistics.rb
73
59
  - lib/rails_stats/inflector.rb
74
- - lib/rails_stats/rake.rb
75
60
  - lib/rails_stats/root_statistics.rb
76
61
  - lib/rails_stats/spec_statistics.rb
62
+ - lib/rails_stats/test_statistics.rb
77
63
  - lib/rails_stats/util.rb
78
64
  - lib/rails_stats/version.rb
79
65
  - rails_stats.gemspec
80
- - stats.thor
81
- homepage: ''
66
+ homepage: https://github.com/bleonard/rails_stats
82
67
  licenses:
83
68
  - MIT
84
69
  metadata: {}
@@ -1,37 +0,0 @@
1
- # railties/lib/rails/tasks/statistics.rake
2
-
3
- module RailsStats
4
- module Rake
5
- STATS_DIRECTORIES = [
6
- %w(Controllers app/controllers),
7
- %w(Helpers app/helpers),
8
- %w(Models app/models),
9
- %w(Mailers app/mailers),
10
- %w(Observers app/observers),
11
- %w(Javascripts app/assets/javascripts),
12
- %w(Libraries lib/),
13
- %w(APIs app/apis),
14
- %w(Controller\ tests test/controllers),
15
- %w(Helper\ tests test/helpers),
16
- %w(Model\ tests test/models),
17
- %w(Mailer\ tests test/mailers),
18
- %w(Integration\ tests test/integration),
19
- %w(Functional\ tests\ (old) test/functional),
20
- %w(Unit\ tests \ (old) test/unit),
21
- %w(Controller\ tests spec/controllers),
22
- %w(Helper\ tests spec/helpers),
23
- %w(Model\ tests spec/models),
24
- %w(Mailer\ tests spec/mailers),
25
- %w(Integration\ tests spec/integration),
26
- %w(Integration\ tests spec/integrations),
27
- %w(Request\ tests spec/requests),
28
- %w(Library\ tests spec/lib),
29
- %w(Cucumber\ tests features),
30
- ]
31
-
32
- def calculate(root_directory)
33
- puts "\nDirectory: #{root_directory}\n\n"
34
- CodeStatistics.new(root_directory).to_s
35
- end
36
- end
37
- end
data/stats.thor DELETED
@@ -1,8 +0,0 @@
1
- require "rails_stats"
2
-
3
- class Stats < Thor
4
- desc "calculate", "get details on a Rails project"
5
- def calculate(directory)
6
- RailsStats.calculate(directory)
7
- end
8
- end