aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2012-01-30 04:05:37 -0800
committerSantiago Pastorino <santiago@wyeworks.com>2012-01-30 04:05:37 -0800
commita0ff270ee1fa677a18c8532c3c5ae32c2f4ffa13 (patch)
tree01b80595c5cbacede4c7c7e4a93639fb21563307 /railties/lib
parent30327a00a0a809ca1c8d7dc0fe3261159346f066 (diff)
parent6831ab11106c582a67bb5109921629059e690610 (diff)
downloadrails-a0ff270ee1fa677a18c8532c3c5ae32c2f4ffa13.tar.gz
rails-a0ff270ee1fa677a18c8532c3c5ae32c2f4ffa13.tar.bz2
rails-a0ff270ee1fa677a18c8532c3c5ae32c2f4ffa13.zip
Merge pull request #4753 from rahul100885/rahul100885_work
Used block to make sure file get auto closed after use
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/rails/code_statistics.rb30
1 files changed, 16 insertions, 14 deletions
diff --git a/railties/lib/rails/code_statistics.rb b/railties/lib/rails/code_statistics.rb
index 435ea83ad8..03538b2422 100644
--- a/railties/lib/rails/code_statistics.rb
+++ b/railties/lib/rails/code_statistics.rb
@@ -37,24 +37,26 @@ class CodeStatistics #:nodoc:
next unless file_name =~ pattern
- f = File.open(directory + "/" + file_name)
comment_started = false
- while line = f.gets
- stats["lines"] += 1
- if(comment_started)
- if line =~ /^=end/
- comment_started = false
- end
- next
- else
- if line =~ /^=begin/
- comment_started = true
+
+ File.open(directory + "/" + file_name) do |f|
+ while line = f.gets
+ stats["lines"] += 1
+ if(comment_started)
+ if line =~ /^=end/
+ comment_started = false
+ end
next
+ else
+ if line =~ /^=begin/
+ comment_started = true
+ next
+ end
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*#/
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*#/
end
end