diff options
author | Akira Matsuda <ronnie@dio.jp> | 2016-02-04 18:12:28 +0900 |
---|---|---|
committer | Akira Matsuda <ronnie@dio.jp> | 2016-02-04 18:25:05 +0900 |
commit | dfa48f200cbc5c1ca18457a8cde14642e12af594 (patch) | |
tree | ba77fc64588d045af5f42b886dfae611cbb5658a /railties/lib/rails | |
parent | 2cd405f34077c2766eda9c3bea75989136eb5f13 (diff) | |
download | rails-dfa48f200cbc5c1ca18457a8cde14642e12af594.tar.gz rails-dfa48f200cbc5c1ca18457a8cde14642e12af594.tar.bz2 rails-dfa48f200cbc5c1ca18457a8cde14642e12af594.zip |
rake stats dynamically scales now
So it can properly show stats for an app with 1,000,000+ LOC
Diffstat (limited to 'railties/lib/rails')
-rw-r--r-- | railties/lib/rails/code_statistics.rb | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/railties/lib/rails/code_statistics.rb b/railties/lib/rails/code_statistics.rb index a4e22af45b..fc8717c752 100644 --- a/railties/lib/rails/code_statistics.rb +++ b/railties/lib/rails/code_statistics.rb @@ -9,6 +9,8 @@ class CodeStatistics #:nodoc: 'Job tests', 'Integration tests'] + HEADERS = {lines: ' Lines', code_lines: ' LOC', classes: 'Classes', methods: 'Methods'} + def initialize(*pairs) @pairs = pairs @statistics = calculate_statistics @@ -67,27 +69,37 @@ class CodeStatistics #:nodoc: test_loc end + def width_for(label) + [@statistics.values.sum {|s| s.send(label) }.to_s.size, HEADERS[label].length].max + end + def print_header print_splitter - puts "| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |" + print '| Name ' + HEADERS.each do |k, v| + print " | #{v.rjust(width_for(k))}" + end + puts ' | M/C | LOC/M |' print_splitter end def print_splitter - puts "+----------------------+-------+-------+---------+---------+-----+-------+" + print '+----------------------' + HEADERS.each_key do |k| + print "+#{'-' * (width_for(k) + 2)}" + end + puts '+-----+-------+' end def print_line(name, statistics) m_over_c = (statistics.methods / statistics.classes) rescue m_over_c = 0 loc_over_m = (statistics.code_lines / statistics.methods) - 2 rescue loc_over_m = 0 - puts "| #{name.ljust(20)} " \ - "| #{statistics.lines.to_s.rjust(5)} " \ - "| #{statistics.code_lines.to_s.rjust(5)} " \ - "| #{statistics.classes.to_s.rjust(7)} " \ - "| #{statistics.methods.to_s.rjust(7)} " \ - "| #{m_over_c.to_s.rjust(3)} " \ - "| #{loc_over_m.to_s.rjust(5)} |" + print "| #{name.ljust(20)} " + HEADERS.each_key do |k| + print "| #{statistics.send(k).to_s.rjust(width_for(k))} " + end + puts "| #{m_over_c.to_s.rjust(3)} | #{loc_over_m.to_s.rjust(5)} |" end def print_code_test_stats |