Rake stats – adding a custom folder

Rake stats is useful when you need to know the statistics of your project. However if you try to add custom folder to be listed – documentation is somewhat sparse.

Question is why would you need a custom folder? After all isn’t the Rails prescribed way to go… Well not everything is a model or a a lib. You can have complex domain models in Ruby that have nothing to do with the database or the general library utility classes. Those poor classes just scream for the folder of their own.

If you add code to new folder named FancyNewFolder “rake stats” is not picking it up.
Stats before adding custom folder
Here is what I did.

gvim lib/tasks/AppTasks.rake

And then I’ve added

STATS_DIRECTORIES = [
  %w(Controllers        app/controllers),
  %w(Helpers            app/helpers),
  %w(Models             app/models),
  %w(Libraries          lib/),
  %w(FancyNewFolder     app/fancy_new_folder),
  %w(Integration\ tests test/integration),
  %w(Functional\ tests  test/functional),
  %w(Unit\ tests        test/unit)

].collect {|name, dir| [name, "#{RAILS_ROOT}/#{dir}"]}.select {|name, dir| File.directory?(dir)}

desc "Report code statistics (KLOCs, etc) from the application"
task :stats do
  require 'code_statistics'
  CodeStatistics.new(*STATS_DIRECTORIES).to_s
end


VoilĂ  there is your custom folder, I’ll bet the stats are not so good as they used to be, but at least now you know the truth :)
Stats after adding custom folder