mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Encapsulate rake lines from ActiveRecord/ActionPack as CodeTools::LineStatistics
[ci skip]
This commit is contained in:
parent
3cbeb8d8ea
commit
91d199259b
3 changed files with 47 additions and 42 deletions
|
@ -40,27 +40,9 @@ task :release => :package do
|
|||
end
|
||||
|
||||
task :lines do
|
||||
lines, codelines, total_lines, total_codelines = 0, 0, 0, 0
|
||||
|
||||
FileList["lib/**/*.rb"].each do |file_name|
|
||||
next if file_name =~ /vendor/
|
||||
File.open(file_name, 'r') do |f|
|
||||
while line = f.gets
|
||||
lines += 1
|
||||
next if line =~ /^\s*$/
|
||||
next if line =~ /^\s*#/
|
||||
codelines += 1
|
||||
end
|
||||
end
|
||||
puts "L: #{sprintf("%4d", lines)}, LOC #{sprintf("%4d", codelines)} | #{file_name}"
|
||||
|
||||
total_lines += lines
|
||||
total_codelines += codelines
|
||||
|
||||
lines, codelines = 0, 0
|
||||
end
|
||||
|
||||
puts "Total: Lines #{total_lines}, LOC #{total_codelines}"
|
||||
load File.expand_path('..', File.dirname(__FILE__)) + '/tools/line_statistics'
|
||||
files = FileList["lib/**/*.rb"]
|
||||
CodeTools::LineStatistics.new(files).print_loc
|
||||
end
|
||||
|
||||
rule '.rb' => '.y' do |t|
|
||||
|
|
|
@ -146,27 +146,9 @@ task :drop_postgresql_databases => 'db:postgresql:drop'
|
|||
task :rebuild_postgresql_databases => 'db:postgresql:rebuild'
|
||||
|
||||
task :lines do
|
||||
lines, codelines, total_lines, total_codelines = 0, 0, 0, 0
|
||||
|
||||
FileList["lib/active_record/**/*.rb"].each do |file_name|
|
||||
next if file_name =~ /vendor/
|
||||
File.open(file_name, 'r') do |f|
|
||||
while line = f.gets
|
||||
lines += 1
|
||||
next if line =~ /^\s*$/
|
||||
next if line =~ /^\s*#/
|
||||
codelines += 1
|
||||
end
|
||||
end
|
||||
puts "L: #{sprintf("%4d", lines)}, LOC #{sprintf("%4d", codelines)} | #{file_name}"
|
||||
|
||||
total_lines += lines
|
||||
total_codelines += codelines
|
||||
|
||||
lines, codelines = 0, 0
|
||||
end
|
||||
|
||||
puts "Total: Lines #{total_lines}, LOC #{total_codelines}"
|
||||
load File.expand_path('..', File.dirname(__FILE__)) + '/tools/line_statistics'
|
||||
files = FileList["lib/active_record/**/*.rb"]
|
||||
CodeTools::LineStatistics.new(files).print_loc
|
||||
end
|
||||
|
||||
spec = eval(File.read('activerecord.gemspec'))
|
||||
|
|
41
tools/line_statistics
Executable file
41
tools/line_statistics
Executable file
|
@ -0,0 +1,41 @@
|
|||
#!/usr/bin/env ruby
|
||||
# Example:
|
||||
# files = FileList["lib/active_record/**/*.rb"]
|
||||
# CodeTools::LineStatistics.new(files).print_loc
|
||||
module CodeTools
|
||||
class LineStatistics
|
||||
|
||||
# @param files [Array, FileList, Enumerable]
|
||||
# e.g. FileList["lib/active_record/**/*.rb"]
|
||||
def initialize(files)
|
||||
@files = Array(files).compact
|
||||
end
|
||||
|
||||
# Calculates LOC for each file
|
||||
# Outputs each file and a total LOC
|
||||
def print_loc
|
||||
lines, codelines, total_lines, total_codelines = 0, 0, 0, 0
|
||||
|
||||
@files.each do |file_name|
|
||||
next if file_name =~ /vendor/
|
||||
File.open(file_name, 'r') do |f|
|
||||
while line = f.gets
|
||||
lines += 1
|
||||
next if line =~ /^\s*$/
|
||||
next if line =~ /^\s*#/
|
||||
codelines += 1
|
||||
end
|
||||
end
|
||||
puts "L: #{sprintf("%4d", lines)}, LOC #{sprintf("%4d", codelines)} | #{file_name}"
|
||||
|
||||
total_lines += lines
|
||||
total_codelines += codelines
|
||||
|
||||
lines, codelines = 0, 0
|
||||
end
|
||||
|
||||
puts "Total: Lines #{total_lines}, LOC #{total_codelines}"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue