简体   繁体   English

如何在铁轨外的耙子任务中使用耙子?

[英]How to use rake with rake tasks outside rails?

I think Rails is very heavy and I'm taking pieces out of my projects and making them standalone. 我认为Rails非常繁重,我正在从项目中分拆出来并使其独立。 My library of tasks, I would like it to work outside Rails. 我的任务库,我希望它在Rails之外工作。 So there is no application and no config/application.rb, only the lib/ folder that defines tasks. 因此,没有应用程序,也没有config / application.rb,只有定义任务的lib /文件夹。 How should I structure my rakefile to include all the tasks defined in lib/tasks/*rake ? 我应该如何构造我的rakefile以包括lib/tasks/*rake定义的所有任务? My non-working attempt is below. 我的非工作尝试如下。

#!/usr/bin/env/rake
d = Dir["#{File.dirname(__FILE__)}/src/tasks/*.rake" ]
d.each do |file|
  require "tasks/"+ File.basename(file, File.extname(file))
end

The invocation is something like bundle exec rake -T -Isrc 调用类似于bundle exec rake -T -Isrc

把它放在你的耙文件中

Dir["#{File.dirname(__FILE__)}/src/tasks/*.rake" ].each{ |rake_file| load rake_file }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM