Can I use Rakefile from another task?

I have some Rake tasks that I would like to use in my Rakefiles. Can I include tasks defined in one rake file from another rake file?

+3
source share
2 answers

Rake files are no different from ruby ​​files. So just upload file A containing other tasks to your file B, and they will be available when B. is completed.

For example, if you put the following code in your Rakefile

Dir['tasks/*.rake'].each { |file| load(file) }

You can create as many .rakefiles in a subfolder tasksand call them from the main one Rakefile.

+9
source

I just did something similar with the following:

task :master do
  `rake slave`
end

task :slave do
  puts "Hello World"
end

Perhaps a little rudimentary, but he does the job.

+2
source

Source: https://habr.com/ru/post/1734581/


All Articles