Skip to content

Instantly share code, notes, and snippets.

@adamgotterer
Created February 6, 2013 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamgotterer/4725761 to your computer and use it in GitHub Desktop.
Save adamgotterer/4725761 to your computer and use it in GitHub Desktop.
Add folders and file types to rake stats.
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