I wanted to create an internal gem that only exposes a rake task to share with my colleagues at linkedcare. We are not using Rails for most of our projects, it’s mostly Sinatra and Grape, so I needed a wider solution than Railties.

Lets create the gem:

bundle gem internal_task

Then we will need the DSL to create the task.

This DSL that you are already familiar with, is given by Rake::DSL module.

On your lib/internal_task.rb, extend the Rake::DSL module and you will be able to create your task:

And that’s all.

Add it to your Gemfile and require it on your Rakefile.

Run the task with:

rake internal_task:hello

This example is on github, feel free to clone and test ☺