Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rake tasks in other files

Tags:

ruby

rake

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?

like image 276
Arcath Avatar asked May 23 '10 08:05

Arcath


People also ask

What is. Rake file?

Rake is a native tool for Ruby, similar to Unix's “make”. Written by Jim Weirich, It is used to handle administrative commands or tasks, which are stored either in a Rakefile or in a . rake file. One can write their own rake tasks, specific to their application.

How do I run a rake file?

Go to Websites & Domains and click Ruby. After gems installation you can try to run a Rake task by clicking Run rake task. In the opened dialog, you can provide some parameters and click OK - this will be equivalent to running the rake utility with the specified parameters in the command line.

What is the use of Rakefile?

Rake is Ruby Make, a standalone Ruby utility that replaces the Unix utility 'make', and uses a 'Rakefile' and . rake files to build up a list of tasks. In Rails, Rake is used for common administration tasks, especially sophisticated ones that build off of each other.

What is a Rakefile Ruby?

Rake is a tool you can use with Ruby projects. It allows you to use ruby code to define "tasks" that can be run in the command line. Rake can be downloaded and included in ruby projects as a ruby gem. Once installed, you define tasks in a file named "Rakefile" that you add to your project.


1 Answers

Needed to change the line in the rake file to

Dir.glob('lib/rake/*.rake').each { |r| import r }
like image 162
Arcath Avatar answered Sep 25 '22 04:09

Arcath