How do I find the source file for a rake task?

后端 未结 4 1010
名媛妹妹
名媛妹妹 2020-12-24 00:40

I know you can view all possible rake tasks by typing

rake -T

But I need to know what exactly a task does. From the output, how can I find

4条回答
  •  無奈伤痛
    2020-12-24 01:36

    There is no programmatic way to do this unfortunately. Rake tasks can be loaded either from rails itself, lib/tasks, or from any plugin with a tasks directory.

    This should nab most everything not within Rails itself:

    find . -name "*.rake" | xargs grep "whatever"
    

    As for db:schema:dump, here's the source:

    desc "Create a db/schema.rb file that can be portably used against any DB supported by AR"
    task :dump => :environment do
      require 'active_record/schema_dumper'
      File.open(ENV['SCHEMA'] || "#{RAILS_ROOT}/db/schema.rb", "w") do |file|
        ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
      end
    end
    

    It can be found on line 242 of lib/tasks/database.rake in the rails 2.2.2 gem. If you've got a different version of Rails, just search for "namespace :schema".

    You probably actually want the source of the ActiveRecord::SchemaDumper, but I think you should have no trouble figuring out where that is. :-)

提交回复
热议问题