rails_stats 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,74 @@
1
+ module RailsStats
2
+ class SpecStatistics
3
+ attr_reader :statistics, :total, :test
4
+
5
+ SPEC_FOLDERS = ['controllers',
6
+ 'features',
7
+ 'helpers',
8
+ 'models',
9
+ 'requests',
10
+ 'routing',
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 =~ /.*_spec.rb$/
46
+ key = categorize_file(file_path)
47
+ else
48
+ key = "Spec 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
@@ -0,0 +1,97 @@
1
+ module RailsStats
2
+ module Util
3
+ extend self
4
+
5
+ def calculate_projects(*args)
6
+ projects = {}
7
+
8
+ children = [args.pop].flatten
9
+ parent = args.flatten
10
+ children.each do |dirname|
11
+ child_folder_pattern = File.join(*(parent.dup + [dirname]))
12
+ Dir[child_folder_pattern].each do |marker_path|
13
+ next if marker_path =~ /\/vendor\//
14
+
15
+ projects[File.absolute_path(File.dirname(marker_path))] = true
16
+ end
17
+ end
18
+
19
+ out = projects.keys
20
+
21
+ # TODO: make sure none are children of other ones in there
22
+ out
23
+ end
24
+
25
+ def calculate_file_statistics(file, type = :code, &block)
26
+ stats = CodeStatisticsCalculator.new
27
+
28
+ files = [file].flatten
29
+
30
+ files.each do |path|
31
+ stats.add_by_file_path(path)
32
+ end
33
+
34
+ stats
35
+ end
36
+
37
+ def calculate_statistics(directories, type = :code, &block)
38
+ out = {}
39
+
40
+ directories = [directories].flatten
41
+ is_test = (type.to_s == "test")
42
+
43
+ directories.each do |dir_path|
44
+ next unless File.directory?(dir_path)
45
+
46
+ key = nil
47
+ if block_given?
48
+ key = yield(dir_path)
49
+ end
50
+
51
+ key = path_to_name(dir_path, is_test) if !key || key.length == 0
52
+
53
+ out[key] ||= CodeStatisticsCalculator.new(is_test)
54
+ out[key].add(calculate_directory_statistics(dir_path))
55
+ end
56
+
57
+ out.keys.each do |key|
58
+ out.delete(key) if out[key].lines == 0
59
+ end
60
+
61
+ out
62
+ end
63
+
64
+ def calculate_directory_statistics(directory, pattern = /.*\.(rb|js|coffee|feature)$/)
65
+ stats = CodeStatisticsCalculator.new
66
+
67
+ Dir.foreach(directory) do |file_name|
68
+ path = "#{directory}/#{file_name}"
69
+
70
+ if File.directory?(path) && (/^\./ !~ file_name)
71
+ stats.add(calculate_directory_statistics(path, pattern))
72
+ end
73
+
74
+ next unless file_name =~ pattern
75
+
76
+ stats.add_by_file_path(path)
77
+ end
78
+
79
+ stats
80
+ end
81
+
82
+ def path_to_name(path, is_test)
83
+ folder = File.basename(path)
84
+ folder = Inflector.humanize(folder)
85
+ folder = Inflector.titleize(folder)
86
+
87
+ if is_test
88
+ folder = Inflector.singularize(folder)
89
+ folder = "#{folder} Tests"
90
+ else
91
+ folder = Inflector.pluralize(folder)
92
+ end
93
+
94
+ folder
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,3 @@
1
+ module RailsStats
2
+ VERSION = "0.0.4"
3
+ end
@@ -0,0 +1,20 @@
1
+ require "rails_stats/version"
2
+
3
+ module RailsStats
4
+
5
+ end
6
+
7
+ require 'debugger'
8
+
9
+ require 'rails_stats/inflector'
10
+ require 'rails_stats/code_statistics_calculator'
11
+ require 'rails_stats/util'
12
+ require 'rails_stats/app_statistics'
13
+ require 'rails_stats/spec_statistics'
14
+ require 'rails_stats/cucumber_statistics'
15
+ require 'rails_stats/root_statistics'
16
+ require 'rails_stats/gem_statistics'
17
+ require 'rails_stats/code_statistics'
18
+
19
+ require "rails_stats/rake"
20
+ RailsStats.extend RailsStats::Rake
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rails_stats/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rails_stats"
8
+ spec.version = RailsStats::VERSION
9
+ spec.authors = ["Brian Leonard"]
10
+ spec.email = ["brian@bleonard.com"]
11
+ spec.summary = %q{Analyze a Rails project}
12
+ spec.description = %q{Point it to a directory and see stuff about the app}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "thor"
22
+ spec.add_development_dependency "bundler", "~> 1.6"
23
+ spec.add_development_dependency "rake"
24
+ end
data/stats.thor ADDED
@@ -0,0 +1,8 @@
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
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_stats
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Brian Leonard
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
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
+ description: Point it to a directory and see stuff about the app
56
+ email:
57
+ - brian@bleonard.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/rails_stats.rb
68
+ - lib/rails_stats/app_statistics.rb
69
+ - lib/rails_stats/code_statistics.rb
70
+ - lib/rails_stats/code_statistics_calculator.rb
71
+ - lib/rails_stats/cucumber_statistics.rb
72
+ - lib/rails_stats/gem_statistics.rb
73
+ - lib/rails_stats/inflector.rb
74
+ - lib/rails_stats/rake.rb
75
+ - lib/rails_stats/root_statistics.rb
76
+ - lib/rails_stats/spec_statistics.rb
77
+ - lib/rails_stats/util.rb
78
+ - lib/rails_stats/version.rb
79
+ - rails_stats.gemspec
80
+ - stats.thor
81
+ homepage: ''
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.0.3
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Analyze a Rails project
105
+ test_files: []