tags:

views:

679

answers:

3

So I'm writing a small gem and I have a '/tasks' dir in it with some specific rake tasks. How do I make those tasks available automatically everywhere, where the gem is required? For example I wish I could run 'rake mygemrake:task' inside my rails root dir after I have the gem installed.

+1  A: 

Check out the rdoctask in rake for an example of how to define a task provided by a gem. The task is defined in ruby instead of the rake build language and can be required like so:

require 'rake'             # the gem
require 'rake/rdoctask'    # the task
dbarker
+1  A: 

You can't do that. At least, not with Rake. But that's what Sake is for. Datamapper and Merb have been using Sake with great success.

Bob Aman
A: 

You have to import those tasks in application's Rakefile. This is how it looks in mine (I am using bundler08 to manage my gems):

%w(gem1 gem2 gem3).each do |g|
  Dir[File.dirname(__FILE__) + "/vendor/bundler_gems/**/#{g}*/tasks/*.rake"].each do |f|
    import f
  end
end
skalee