Kuripai

Calling Rake Tasks in a Script

To call a rake task within a script just require rake and your rake file then invoke it using

Rake::Task[task_name].invoke

For example given the following rake file (my_tasks.rake)

desc "Prints 'Hello'"
task :hello do
  puts "Hello"
end

and the script (my_script.rb)

#!/usr/bin/env ruby

require 'rubygems'
require 'rake'

load 'my_tasks.rake'

Rake::Task['hello'].invoke

Running it produces:

~ $ ruby my_script.rb 
Hello
blog comments powered by Disqus