aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorBenjamin Fleischer <github@benjaminfleischer.com>2013-06-27 23:18:30 -0500
committerBenjamin Fleischer <github@benjaminfleischer.com>2014-07-25 13:41:18 -0500
commit91d199259bc7a85763d487a1d0fbf8cd50fe29a0 (patch)
tree5ba172f9798dbc8e6b0edce7dd49436eb818ddef /tools
parent3cbeb8d8eaf217f8eb38f5ea26f766f5cd978ff3 (diff)
downloadrails-91d199259bc7a85763d487a1d0fbf8cd50fe29a0.tar.gz
rails-91d199259bc7a85763d487a1d0fbf8cd50fe29a0.tar.bz2
rails-91d199259bc7a85763d487a1d0fbf8cd50fe29a0.zip
Encapsulate rake lines from ActiveRecord/ActionPack as CodeTools::LineStatistics
[ci skip]
Diffstat (limited to 'tools')
-rwxr-xr-xtools/line_statistics41
1 files changed, 41 insertions, 0 deletions
diff --git a/tools/line_statistics b/tools/line_statistics
new file mode 100755
index 0000000000..5eb5cfdc3d
--- /dev/null
+++ b/tools/line_statistics
@@ -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