aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArun Agrawal <arunagw@gmail.com>2012-05-31 16:15:35 +0530
committerArun Agrawal <arunagw@gmail.com>2012-05-31 16:18:29 +0530
commita48b3f1a6834df7f99fef74a62771d927d594cf1 (patch)
tree9be35c0c86f1b0399fd584b351b528b1eeabc1f7
parent08477a651648ba4417ded128aa37b9ae0dcbc9ce (diff)
downloadrails-a48b3f1a6834df7f99fef74a62771d927d594cf1.tar.gz
rails-a48b3f1a6834df7f99fef74a62771d927d594cf1.tar.bz2
rails-a48b3f1a6834df7f99fef74a62771d927d594cf1.zip
Add code statistics for Javascript and
CoffeeScript files to `rake stats` task Orignal PR was #2270 Thanks to @nfm
-rw-r--r--railties/lib/rails/code_statistics.rb11
-rw-r--r--railties/lib/rails/tasks/statistics.rake1
2 files changed, 10 insertions, 2 deletions
diff --git a/railties/lib/rails/code_statistics.rb b/railties/lib/rails/code_statistics.rb
index bcac0751d6..1aed2796c1 100644
--- a/railties/lib/rails/code_statistics.rb
+++ b/railties/lib/rails/code_statistics.rb
@@ -26,7 +26,7 @@ class CodeStatistics #:nodoc:
Hash[@pairs.map{|pair| [pair.first, calculate_directory_statistics(pair.last)]}]
end
- def calculate_directory_statistics(directory, pattern = /.*\.rb$/)
+ def calculate_directory_statistics(directory, pattern = /.*\.(rb|js|coffee)$/)
stats = { "lines" => 0, "codelines" => 0, "classes" => 0, "methods" => 0 }
Dir.foreach(directory) do |file_name|
@@ -39,6 +39,13 @@ class CodeStatistics #:nodoc:
comment_started = false
+ case file_name
+ when /.*\.js$/
+ comment_pattern = /^\s*\/\//
+ else
+ comment_pattern = /^\s*#/
+ end
+
File.open(directory + "/" + file_name) do |f|
while line = f.gets
stats["lines"] += 1
@@ -55,7 +62,7 @@ class CodeStatistics #:nodoc:
end
stats["classes"] += 1 if line =~ /^\s*class\s+[_A-Z]/
stats["methods"] += 1 if line =~ /^\s*def\s+[_a-z]/
- stats["codelines"] += 1 unless line =~ /^\s*$/ || line =~ /^\s*#/
+ stats["codelines"] += 1 unless line =~ /^\s*$/ || line =~ comment_pattern
end
end
end
diff --git a/railties/lib/rails/tasks/statistics.rake b/railties/lib/rails/tasks/statistics.rake
index f684e71267..67a6d2d2ac 100644
--- a/railties/lib/rails/tasks/statistics.rake
+++ b/railties/lib/rails/tasks/statistics.rake
@@ -3,6 +3,7 @@ STATS_DIRECTORIES = [
%w(Helpers app/helpers),
%w(Models app/models),
%w(Mailers app/mailers),
+ %w(Javascripts app/assets/javascripts),
%w(Libraries lib/),
%w(APIs app/apis),
%w(Integration\ tests test/integration),