rails_stats_fb 2.1.0.pre1
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 +7 -0
- data/.github/workflows/test.yml +41 -0
- data/.gitignore +24 -0
- data/CHANGELOG.md +27 -0
- data/CODE_OF_CONDUCT.md +76 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +22 -0
- data/README.md +223 -0
- data/Rakefile +13 -0
- data/codecov.yml +2 -0
- data/lib/rails_stats/all.rb +14 -0
- data/lib/rails_stats/app_statistics.rb +62 -0
- data/lib/rails_stats/code_statistics.rb +24 -0
- data/lib/rails_stats/code_statistics_calculator.rb +93 -0
- data/lib/rails_stats/console_formatter.rb +73 -0
- data/lib/rails_stats/cucumber_statistics.rb +46 -0
- data/lib/rails_stats/gem_statistics.rb +31 -0
- data/lib/rails_stats/inflector.rb +605 -0
- data/lib/rails_stats/json_formatter.rb +81 -0
- data/lib/rails_stats/root_statistics.rb +42 -0
- data/lib/rails_stats/spec_statistics.rb +76 -0
- data/lib/rails_stats/stats_calculator.rb +169 -0
- data/lib/rails_stats/stats_formatter.rb +13 -0
- data/lib/rails_stats/tasks.rb +14 -0
- data/lib/rails_stats/test_statistics.rb +74 -0
- data/lib/rails_stats/util.rb +111 -0
- data/lib/rails_stats/version.rb +5 -0
- data/lib/rails_stats.rb +9 -0
- data/pull_request_template.md +9 -0
- data/rails_stats.gemspec +23 -0
- data/test/dummy/Gemfile +43 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/config/manifest.js +2 -0
- data/test/dummy/app/assets/images/.keep +0 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/channels/application_cable/channel.rb +4 -0
- data/test/dummy/app/channels/application_cable/connection.rb +4 -0
- data/test/dummy/app/controllers/application_controller.rb +7 -0
- data/test/dummy/app/controllers/concerns/.keep +0 -0
- data/test/dummy/app/helpers/application_helper.rb +3 -0
- data/test/dummy/app/javascript/channels/consumer.js +6 -0
- data/test/dummy/app/javascript/channels/index.js +5 -0
- data/test/dummy/app/javascript/packs/application.js +16 -0
- data/test/dummy/app/jobs/application_job.rb +7 -0
- data/test/dummy/app/mailers/application_mailer.rb +4 -0
- data/test/dummy/app/models/application_record.rb +3 -0
- data/test/dummy/app/models/comment.rb +3 -0
- data/test/dummy/app/models/concerns/.keep +0 -0
- data/test/dummy/app/models/pet.rb +2 -0
- data/test/dummy/app/models/user.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +15 -0
- data/test/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/test/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +36 -0
- data/test/dummy/bin/yarn +11 -0
- data/test/dummy/config/application.rb +35 -0
- data/test/dummy/config/boot.rb +4 -0
- data/test/dummy/config/cable.yml +10 -0
- data/test/dummy/config/credentials.yml.enc +1 -0
- data/test/dummy/config/database.yml +85 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +62 -0
- data/test/dummy/config/environments/production.rb +112 -0
- data/test/dummy/config/environments/test.rb +49 -0
- data/test/dummy/config/initializers/application_controller_renderer.rb +8 -0
- data/test/dummy/config/initializers/assets.rb +14 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/content_security_policy.rb +30 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +5 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/pagy.rb +1 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +33 -0
- data/test/dummy/config/master.key +1 -0
- data/test/dummy/config/puma.rb +38 -0
- data/test/dummy/config/routes.rb +3 -0
- data/test/dummy/config/spring.rb +6 -0
- data/test/dummy/config/storage.yml +34 -0
- data/test/dummy/config.ru +5 -0
- data/test/dummy/db/schema.rb +10 -0
- data/test/dummy/lib/monkeypatches.rb +1 -0
- data/test/dummy/package.json +10 -0
- data/test/dummy/spec/models/user_spec.rb +3 -0
- data/test/dummy/spec/support/support_file.rb +1 -0
- data/test/dummy/test/models/user_test.rb +2 -0
- data/test/dummy/test/support/test_helper.rb +1 -0
- data/test/fixtures/console-output.txt +43 -0
- data/test/lib/rails_stats/code_statistics_test.rb +23 -0
- data/test/lib/rails_stats/json_formatter_test.rb +293 -0
- data/test/test_helper.rb +27 -0
- metadata +228 -0
@@ -0,0 +1,93 @@
|
|
1
|
+
# railties/lib/rails/code_statistics_calculator.rb
|
2
|
+
|
3
|
+
module RailsStats
|
4
|
+
class CodeStatisticsCalculator #:nodoc:
|
5
|
+
attr_reader :files_total, :lines, :code_lines, :classes, :methods, :test
|
6
|
+
|
7
|
+
PATTERNS = {
|
8
|
+
rb: {
|
9
|
+
line_comment: /^\s*#/,
|
10
|
+
begin_block_comment: /^=begin/,
|
11
|
+
end_block_comment: /^=end/,
|
12
|
+
class: /^\s*class\s+[_A-Z]/,
|
13
|
+
method: /^\s*def\s+[_a-z]/,
|
14
|
+
},
|
15
|
+
js: {
|
16
|
+
line_comment: %r{^\s*//},
|
17
|
+
begin_block_comment: %r{^\s*/\*},
|
18
|
+
end_block_comment: %r{\*/},
|
19
|
+
method: /function(\s+[_a-zA-Z][\da-zA-Z]*)?\s*\(/,
|
20
|
+
},
|
21
|
+
coffee: {
|
22
|
+
line_comment: /^\s*#/,
|
23
|
+
begin_block_comment: /^\s*###/,
|
24
|
+
end_block_comment: /^\s*###/,
|
25
|
+
class: /^\s*class\s+[_A-Z]/,
|
26
|
+
method: /[-=]>/,
|
27
|
+
},
|
28
|
+
feature: {
|
29
|
+
class: /^\s*Feature:/,
|
30
|
+
method: /^\s*Scenario:/,
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
def initialize(test=false)
|
35
|
+
@test = test
|
36
|
+
@files_total = 0
|
37
|
+
@lines = 0
|
38
|
+
@code_lines = 0
|
39
|
+
@classes = 0
|
40
|
+
@methods = 0
|
41
|
+
end
|
42
|
+
|
43
|
+
def add(code_statistics_calculator)
|
44
|
+
@files_total += code_statistics_calculator.files_total
|
45
|
+
@lines += code_statistics_calculator.lines
|
46
|
+
@code_lines += code_statistics_calculator.code_lines
|
47
|
+
@classes += code_statistics_calculator.classes
|
48
|
+
@methods += code_statistics_calculator.methods
|
49
|
+
end
|
50
|
+
|
51
|
+
def add_by_file_path(file_path)
|
52
|
+
@files_total += 1
|
53
|
+
|
54
|
+
File.open(file_path) do |f|
|
55
|
+
self.add_by_io(f, file_type(file_path))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def add_by_io(io, file_type)
|
60
|
+
patterns = PATTERNS[file_type] || {}
|
61
|
+
|
62
|
+
comment_started = false
|
63
|
+
|
64
|
+
while line = io.gets
|
65
|
+
@lines += 1
|
66
|
+
|
67
|
+
if comment_started
|
68
|
+
if patterns[:end_block_comment] && line =~ patterns[:end_block_comment]
|
69
|
+
comment_started = false
|
70
|
+
end
|
71
|
+
next
|
72
|
+
else
|
73
|
+
if patterns[:begin_block_comment] && line =~ patterns[:begin_block_comment]
|
74
|
+
comment_started = true
|
75
|
+
next
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
@classes += 1 if patterns[:class] && line =~ patterns[:class]
|
80
|
+
@methods += 1 if patterns[:method] && line =~ patterns[:method]
|
81
|
+
if line !~ /^\s*$/ && (patterns[:line_comment].nil? || line !~ patterns[:line_comment])
|
82
|
+
@code_lines += 1
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
def file_type(file_path)
|
89
|
+
File.extname(file_path).sub(/\A\./, '').downcase.to_sym
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require "bundler/stats/cli"
|
2
|
+
|
3
|
+
module RailsStats
|
4
|
+
class ConsoleFormatter < StatsFormatter
|
5
|
+
def to_s
|
6
|
+
Bundler::Stats::CLI.start
|
7
|
+
|
8
|
+
print_header
|
9
|
+
sorted_keys = @statistics.keys.sort
|
10
|
+
sorted_keys.each { |key| print_line(key, @statistics[key]) }
|
11
|
+
print_splitter
|
12
|
+
|
13
|
+
if @grand_total
|
14
|
+
print_line("Code", @code_total)
|
15
|
+
print_line("Tests", @tests_total)
|
16
|
+
print_line("Total", @grand_total)
|
17
|
+
print_splitter
|
18
|
+
end
|
19
|
+
|
20
|
+
print_code_test_stats
|
21
|
+
print_polymorphic_stats
|
22
|
+
print_schema_stats
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def print_header
|
28
|
+
print_splitter
|
29
|
+
puts "| Name | Files | Lines | LOC | Classes | Methods | M/C | LOC/M |"
|
30
|
+
print_splitter
|
31
|
+
end
|
32
|
+
|
33
|
+
def print_splitter
|
34
|
+
puts "+----------------------+---------+---------+---------+---------+---------+-----+-------+"
|
35
|
+
end
|
36
|
+
|
37
|
+
def print_line(name, statistics)
|
38
|
+
m_over_c = (statistics.methods / statistics.classes) rescue m_over_c = 0
|
39
|
+
loc_over_m = (statistics.code_lines / statistics.methods) - 2 rescue loc_over_m = 0
|
40
|
+
|
41
|
+
puts "| #{name.ljust(20)} " \
|
42
|
+
"| #{statistics.files_total.to_s.rjust(7)} " \
|
43
|
+
"| #{statistics.lines.to_s.rjust(7)} " \
|
44
|
+
"| #{statistics.code_lines.to_s.rjust(7)} " \
|
45
|
+
"| #{statistics.classes.to_s.rjust(7)} " \
|
46
|
+
"| #{statistics.methods.to_s.rjust(7)} " \
|
47
|
+
"| #{m_over_c.to_s.rjust(3)} " \
|
48
|
+
"| #{loc_over_m.to_s.rjust(5)} |"
|
49
|
+
end
|
50
|
+
|
51
|
+
def print_code_test_stats
|
52
|
+
code = calculator.code_loc
|
53
|
+
tests = calculator.test_loc
|
54
|
+
|
55
|
+
puts " Code LOC: #{code} Test LOC: #{tests} Code to Test Ratio: 1:#{sprintf("%.1f", tests.to_f/code)} Files: #{calculator.files_total}"
|
56
|
+
puts ""
|
57
|
+
end
|
58
|
+
|
59
|
+
def print_polymorphic_stats
|
60
|
+
puts " Polymorphic models count: #{calculator.polymorphic} polymorphic associations"
|
61
|
+
end
|
62
|
+
|
63
|
+
def print_schema_stats
|
64
|
+
if File.exist?(calculator.schema_path)
|
65
|
+
puts " Schema Stats: #{calculator.schema} `create_table` calls in schema.rb"
|
66
|
+
elsif File.exist?(calculator.structure_path)
|
67
|
+
puts " Schema Stats: #{calculator.schema} `CREATE TABLE` calls in structure.sql"
|
68
|
+
else
|
69
|
+
puts " Schema Stats: No schema.rb or structure.sql file found"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module RailsStats
|
2
|
+
class CucumberStatistics
|
3
|
+
attr_reader :statistics, :total, :test
|
4
|
+
|
5
|
+
def initialize(directory)
|
6
|
+
@test = true
|
7
|
+
@directory = directory
|
8
|
+
@statistics = calculate_statistics
|
9
|
+
@total = calculate_total
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def calculate_total
|
15
|
+
out = CodeStatisticsCalculator.new(true)
|
16
|
+
@statistics.each do |key, stats|
|
17
|
+
out.add(stats)
|
18
|
+
end
|
19
|
+
out
|
20
|
+
end
|
21
|
+
|
22
|
+
def calculate_statistics
|
23
|
+
out = {}
|
24
|
+
categorize_files.each do |key, list|
|
25
|
+
out[key] = Util.calculate_file_statistics(list)
|
26
|
+
end
|
27
|
+
out
|
28
|
+
end
|
29
|
+
|
30
|
+
def categorize_files
|
31
|
+
out = {}
|
32
|
+
Dir[File.join(@directory, "**", "*.rb")].each do |file_path|
|
33
|
+
out["Cucumber Support"] ||= []
|
34
|
+
out["Cucumber Support"] << file_path
|
35
|
+
end
|
36
|
+
|
37
|
+
Dir[File.join(@directory, "**", "*.feature")].each do |file_path|
|
38
|
+
out["Cucumber Features"] ||= []
|
39
|
+
out["Cucumber Features"] << file_path
|
40
|
+
end
|
41
|
+
|
42
|
+
out
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module RailsStats
|
2
|
+
class GemStatistics
|
3
|
+
attr_reader :statistics, :total, :test
|
4
|
+
|
5
|
+
def initialize(directory)
|
6
|
+
@test = false
|
7
|
+
@directory = directory
|
8
|
+
@statistics = calculate_statistics
|
9
|
+
@total = calculate_total
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def calculate_total
|
15
|
+
out = CodeStatisticsCalculator.new
|
16
|
+
@statistics.each do |key, stats|
|
17
|
+
out.add(stats)
|
18
|
+
end
|
19
|
+
out
|
20
|
+
end
|
21
|
+
|
22
|
+
def calculate_statistics
|
23
|
+
# ignore gem/app so as to not double-count engines
|
24
|
+
lib = File.join(@directory, "lib")
|
25
|
+
Util.calculate_statistics([lib]) do |path|
|
26
|
+
"Gems"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|