Including rake tasks in gems

后端 未结 3 465
终归单人心
终归单人心 2020-12-13 05:54

1) Is there a \'best\' place for rake tasks inside of gems? I\'ve seen them in /tasks, /lib/tasks, and I\'ve seen them written as *.rb

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-13 06:30

    for Rails 3 support, the top line of your lib/.rb file can be:

    Dir["tasks/**/*.rake"].each { |ext| load ext } if defined?(Rake)
    

    for Rails 2 support, the gem installer will have to edit their Rakefile and add:

    Dir["#{Gem.searcher.find('').full_gem_path}/lib/tasks/**/*.rake"].each { |ext| load ext }
    

    after the require statements.

    NOTES:

    • Be sure to replace with the name of your actual gem.
    • This assumes all Rails-visible rake tasks are in lib/tasks/

    I haven't found anything easier yet. Comments?

提交回复
热议问题