如何在rake统计信息中添加文件夹?

时间:2013-02-05 01:48:50

标签: ruby-on-rails ruby-on-rails-3 rake

我已经在我的Rails应用程序中添加了一些文件夹(lib,spec,cell等),并希望将它们添加到rake stats列表中。是否可以添加新文件夹?

3 个答案:

答案 0 :(得分:11)

我知道我迟到了,但由于我没有找到更多信息,我将我的答案添加到混合中。

我在项目中添加了一个rake-task,其内容类似于以下内容:

task :stats => "todolist:statsetup"

namespace :todolist do
  task :statsetup do
    require 'rails/code_statistics'
    ::STATS_DIRECTORIES << ["Policies", "app/policies"]
    ::STATS_DIRECTORIES << ["Services", "app/services"]

    # For test folders not defined in CodeStatistics::TEST_TYPES (ie: spec/)
    ::STATS_DIRECTORIES << ["Services specs", "specs/services"]
    CodeStatistics::TEST_TYPES << "Services specs"
  end
end

这会将两个文件夹添加到我的rake stats

答案 1 :(得分:3)

这是一个很好的答案,可以找到a specific rake task is defined的位置。

通过该提示,发现rake stats任务在gems/railties-3.2.11/lib/rails/tasks/statistics.rake文件中定义;所以它位于railties gemSTATS_DIRECTORIES

在文件的最顶部,要考虑的目录包含在my_stats变量中。

可能最好rails repository - 例如名为{{1}} - 使用相同的代码,并添加您要包含的新文件夹。

答案 2 :(得分:0)

我发现在列表中的合理位置插入新统计信息很有用。

这就是我正在使用的东西(使用rails 5.1):

# lib/stats.rake

require "rails/code_statistics"

task stats: :more_stats

task :more_stats do
  %w[Forms Policies Presenters Serializers Services].each_with_index do |type, i|
    STATS_DIRECTORIES.insert i + 5, [type, "app/#{type.downcase}"]
    STATS_DIRECTORIES.insert i * 2 + 13, ["#{type} tests", "test/#{type.downcase}"]
    CodeStatistics::TEST_TYPES << "#{type} tests"
  end
end