diff options
author | Arthur Nogueira Neves <github@arthurnn.com> | 2015-10-28 16:43:10 -0400 |
---|---|---|
committer | Arthur Nogueira Neves <github@arthurnn.com> | 2015-10-28 16:43:10 -0400 |
commit | 367e4832294c35091ab0928df52e700d9710af7e (patch) | |
tree | 88aa12d2af6af11123f61e9e8862a48e9777cd0d | |
parent | f7d0a3ba7e9e676d399e7aeed7485a8bf03992f8 (diff) | |
parent | 3e3f3563b826bc934448c9a6c25d940df4ba073a (diff) | |
download | rails-367e4832294c35091ab0928df52e700d9710af7e.tar.gz rails-367e4832294c35091ab0928df52e700d9710af7e.tar.bz2 rails-367e4832294c35091ab0928df52e700d9710af7e.zip |
Merge pull request #21998 from kddeisz/rake_task_statistics
Allow rake:stats to account for rake tasks
-rw-r--r-- | railties/CHANGELOG.md | 4 | ||||
-rw-r--r-- | railties/lib/rails/code_statistics.rb | 2 | ||||
-rw-r--r-- | railties/lib/rails/code_statistics_calculator.rb | 1 | ||||
-rw-r--r-- | railties/lib/rails/tasks/statistics.rake | 1 | ||||
-rw-r--r-- | railties/test/code_statistics_calculator_test.rb | 16 |
5 files changed, 23 insertions, 1 deletions
diff --git a/railties/CHANGELOG.md b/railties/CHANGELOG.md index 9337dd6407..f43b73cb9d 100644 --- a/railties/CHANGELOG.md +++ b/railties/CHANGELOG.md @@ -1,3 +1,7 @@ +* Allow rake:stats to account for rake tasks in lib/tasks + + *Kevin Deisz* + * Added javascript to update the URL on mailer previews with the currently selected email format. Reloading the page now keeps you on your selected format rather than going back to the default html version. diff --git a/railties/lib/rails/code_statistics.rb b/railties/lib/rails/code_statistics.rb index fd352dc9b7..8e9097e1ef 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)$/) + def calculate_directory_statistics(directory, pattern = /.*\.(rb|js|coffee|rake)$/) stats = CodeStatisticsCalculator.new Dir.foreach(directory) do |file_name| diff --git a/railties/lib/rails/code_statistics_calculator.rb b/railties/lib/rails/code_statistics_calculator.rb index a142236dbe..fad13e8517 100644 --- a/railties/lib/rails/code_statistics_calculator.rb +++ b/railties/lib/rails/code_statistics_calculator.rb @@ -25,6 +25,7 @@ class CodeStatisticsCalculator #:nodoc: } PATTERNS[:minitest] = PATTERNS[:rb].merge method: /^\s*(def|test)\s+['"_a-z]/ + PATTERNS[:rake] = PATTERNS[:rb] def initialize(lines = 0, code_lines = 0, classes = 0, methods = 0) @lines = lines diff --git a/railties/lib/rails/tasks/statistics.rake b/railties/lib/rails/tasks/statistics.rake index 735c36eb3a..a919d36939 100644 --- a/railties/lib/rails/tasks/statistics.rake +++ b/railties/lib/rails/tasks/statistics.rake @@ -9,6 +9,7 @@ STATS_DIRECTORIES = [ %w(Mailers app/mailers), %w(Javascripts app/assets/javascripts), %w(Libraries lib/), + %w(Tasks lib/tasks), %w(APIs app/apis), %w(Controller\ tests test/controllers), %w(Helper\ tests test/helpers), diff --git a/railties/test/code_statistics_calculator_test.rb b/railties/test/code_statistics_calculator_test.rb index 46445a001a..cecc3908b3 100644 --- a/railties/test/code_statistics_calculator_test.rb +++ b/railties/test/code_statistics_calculator_test.rb @@ -299,6 +299,22 @@ class Animal assert_equal 0, @code_statistics_calculator.methods end + test 'count rake tasks' do + code = <<-'CODE' + task :test_task do + puts 'foo' + end + + CODE + + @code_statistics_calculator.add_by_io(StringIO.new(code), :rake) + + assert_equal 4, @code_statistics_calculator.lines + assert_equal 3, @code_statistics_calculator.code_lines + assert_equal 0, @code_statistics_calculator.classes + assert_equal 0, @code_statistics_calculator.methods + end + private def temp_file(name, content) dir = File.expand_path '../fixtures/tmp', __FILE__ |