Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you communicate between Rake tasks?

Tags:

ruby

rake

Let's say I have a target who needs to compile some files. That target has another target as a prerequisite, one that obtains the files. Let's say this:

task :obtain do
  # obtain files from somewhere
end

task :compile => :obtain do
  # do compilation
end

Let's say that the :obtain target doesn't always places the files in the same folder. How would I pass :compile the path that :obtain found? Environment variables?

like image 211
Geo Avatar asked Feb 26 '10 07:02

Geo


People also ask

How do you call a rake task?

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.

How do I see rake tasks?

You can get a list of Rake tasks available to you, which will often depend on your current directory, by typing rake --tasks . Each task has a description, and should help you find the thing you need.

What are rake tasks used for?

Rake is a popular task runner for Ruby and Rails applications. For example, Rails provides the predefined Rake tasks for creating databases, running migrations, and performing tests. You can also create custom tasks to automate specific actions - run code analysis tools, backup databases, and so on.


1 Answers

Using ENV['something'] is in my opinion preferable, because if you do it this way (as opposed to $global or @instance variables) you can treat those as task arguments, and use the sub task from commandline easily.

On the other hand if you keep your code in separate classes / modules / methods, you will not even have to deal with those sorts of hacks + your code will be more testable.

like image 63
psyho Avatar answered Nov 07 '22 05:11

psyho