Is it possible to call a task that is defined in Rakefile - not in somefile.rake - from another Ruby script?
I was hoping that creating a new Rake::Application would automatically load the Rakefile from the same directory, but it seems like it is not. Here is what I came up with so far:
$LOAD_PATH.unshift File.dirname(__FILE__) require 'rake' require 'pp' rake = Rake::Application.new rake[:hello].invoke
Execution of this code leads to the following:
/opt/ruby/1.9.2-p180/lib/ruby/1.9.1/rake.rb:1720:in `[]': Don't know how to build task 'hello' (RuntimeError) from script.rb:7:in `<main>'
pp rake gives the following:
Somehow annoying that @rakefile is nil .
May 20 update, 16:40 CET
After reading the source code of rake for a while, I realized that you need to call Rake :: Application # init to initialize the newly created rake application:
rake = Rake::Application.new rake.init rake.load_rakefile
However, I still cannot invoke any tasks defined in my Rakefile:
rake.top_level_tasks # => ["default"]
I will be happy to take care of any help in this matter.
ruby rake
t6d May 18 '11 at 22:27 2011-05-18 22:27
source share