开发者

Rake tasks in other files

Im trying to use rake in a project, and if I put everything into Rakefile it will be huge and hard to read/find things, so I tried to stick each namesapce in its own file in lib/rake, i added this to the top of my rake file:

Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map { |f| require f }

it loads the file no problem, but doesn't have the tasks. I only have one .rake file as a test for now called "servers.rake" and it looks like this:

namespace :server do
    task :test do
        puts "test"
    end
end

so when I run rake server:test id expect to see one line appear saying "test", instead I get

rake aborted!
Don't know how to build task 'server:test'

at first I thought my codes wrong but i开发者_如何学Pythonf I copy the contents of lib/rake/servers.rake into Rakefile it works fine.

How do I get rake tasks to work that are in another file?


Needed to change the line in the rake file to

Dir.glob('lib/rake/*.rake').each { |r| import r }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜