Rake tasks in other files

Posted by Arcath on Stack Overflow See other posts from Stack Overflow or by Arcath
Published on 2010-05-23T08:32:40Z Indexed on 2010/05/23 8:40 UTC
Read the original article Hit count: 386

Filed under:
|

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 if 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?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about rake