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.
相关问题
- How to specify memcache server to Rack::Session::M
- Why am I getting a “C compiler cannot create execu
- reference to a method?
- ruby 1.9 wrong file encoding on windows
- gem cleanup shows error: Unable to uninstall bundl
相关文章
- Ruby using wrong version of openssl
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- “No explicit conversion of Symbol into String” for
- Segmentation fault with ruby 2.0.0p247 leading to
- How to detect if an element exists in Watir
- uninitialized constant Mysql2::Client::SECURE_CONN
- ruby - simplify string multiply concatenation
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):
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:
That's what Sake is for. Datamapper and Merb have been using Sake with success.
For Rails3 applications, you might want to look into making a Railtie for your gem.
You can do so with:
lib/your_gem/railtie.rb
lib/your_gem.rb
Though, I had my share of difficulties with requiring the
rake.task
file in myrailtie.rb
. I opted to just define my measley one or two tasks within therake_tasks
block.You can write normal rake tasks for a gem and load them like this:
Also, take a look at thor vs. rake.