mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
rake stats dynamically scales now
So it can properly show stats for an app with 1,000,000+ LOC
This commit is contained in:
parent
2cd405f340
commit
dfa48f200c
1 changed files with 21 additions and 9 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue