Created
February 6, 2013 20:58
-
-
Save adamgotterer/4725761 to your computer and use it in GitHub Desktop.
Add folders and file types to rake stats.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :app do | |
require 'rails/code_statistics' | |
APP_STATS_DIRECTORIES = STATS_DIRECTORIES + [ | |
['Javascripts', 'app/assets/javascripts', /.*\.(js|coffee)$/], | |
['Stylesheets', 'app/assets/stylesheets', /.*\.(css|scss|erb)$/], | |
].collect { |name, dir, pattern| [ name, "#{Rails.root}/#{dir}", pattern ] }.select { |name, dir| File.directory?(dir) } | |
class AppCodeStatistics < CodeStatistics | |
def initialize(*pairs) | |
@pairs = pairs | |
@statistics = calculate_statistics | |
@total = calculate_total if pairs.length > 1 | |
end | |
def calculate_statistics | |
stats = @pairs.map do |name, dir, pattern| | |
if pattern | |
row = calculate_directory_statistics(dir, pattern) | |
else | |
row = calculate_directory_statistics(dir) | |
end | |
[name, row] | |
end | |
Hash[stats] | |
end | |
end | |
desc "Report code statistics (KLOCs, etc) from the application" | |
task :stats do | |
AppCodeStatistics.new(*APP_STATS_DIRECTORIES).to_s | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment