aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorEdouard CHIN <edouard.chin@shopify.com>2016-01-11 02:42:23 -0500
committerEdouard CHIN <edouard.chin@shopify.com>2016-01-18 12:56:20 -0500
commitef233bba9a0770ada1ebb45c804a319777bbff45 (patch)
tree5c0cea696d44b488b37006d4599ca89306ff864a /railties
parent5465224892281a088422df438e4fc0ce7f6c8f5e (diff)
downloadrails-ef233bba9a0770ada1ebb45c804a319777bbff45.tar.gz
rails-ef233bba9a0770ada1ebb45c804a319777bbff45.tar.bz2
rails-ef233bba9a0770ada1ebb45c804a319777bbff45.zip
CodeStatistic will now ignore hidden files:
- Modify the default regex to not match hidden files
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/code_statistics.rb2
-rw-r--r--railties/test/code_statistics_test.rb15
2 files changed, 15 insertions, 2 deletions
diff --git a/railties/lib/rails/code_statistics.rb b/railties/lib/rails/code_statistics.rb
index 8e9097e1ef..0997414482 100644
--- a/railties/lib/rails/code_statistics.rb
+++ b/railties/lib/rails/code_statistics.rb
@@ -33,7 +33,7 @@ class CodeStatistics #:nodoc:
Hash[@pairs.map{|pair| [pair.first, calculate_directory_statistics(pair.last)]}]
end
- def calculate_directory_statistics(directory, pattern = /.*\.(rb|js|coffee|rake)$/)
+ def calculate_directory_statistics(directory, pattern = /^(?!\.).*?\.(rb|js|coffee|rake)$/)
stats = CodeStatisticsCalculator.new
Dir.foreach(directory) do |file_name|
diff --git a/railties/test/code_statistics_test.rb b/railties/test/code_statistics_test.rb
index 1b1ff80bc1..4d80901217 100644
--- a/railties/test/code_statistics_test.rb
+++ b/railties/test/code_statistics_test.rb
@@ -4,7 +4,7 @@ require 'rails/code_statistics'
class CodeStatisticsTest < ActiveSupport::TestCase
def setup
@tmp_path = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'tmp'))
- @dir_js = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'tmp', 'lib.js'))
+ @dir_js = File.join(@tmp_path, 'lib.js')
FileUtils.mkdir_p(@dir_js)
end
@@ -17,4 +17,17 @@ class CodeStatisticsTest < ActiveSupport::TestCase
@code_statistics = CodeStatistics.new(['tmp dir', @tmp_path])
end
end
+
+ test 'ignores hidden files' do
+ File.write File.join(@tmp_path, '.example.rb'), <<-CODE
+ def foo
+ puts 'foo'
+ end
+ CODE
+
+ assert_nothing_raised do
+ CodeStatistics.new(['hidden file', @tmp_path])
+ end
+ end
+
end