Gem Integration
This guide explains how to add bake
to a Ruby gem and export standardised tasks for use by other gems and projects.
Exporting Tasks
Adding a bake/
directory to your gem will allow other gems and projects to consume those recipes. In order to prevent collisions, you should prefix your commands with the name of the gem, e.g. in mygem/bake/mygem.rb
:
def setup
# ...
end
Then, in a different project which depends on mygem
, you can run tasks from mygem
by invoking them using bake
:
$ bake mygem:setup
Examples
There are many gems which export tasks in this way. Here are some notable examples:
Variant
The variant gem exposes bake tasks for setting the environment e.g. development
, testing
, or production
.
$ bake list variant Bake::Loader variant-0.1.1 variant:production **overrides Select the production variant. overrides [Hash] any specific variant overrides. variant:staging **overrides Select the staging variant. overrides [Hash] any specific variant overrides. variant:development **overrides Select the development variant. overrides [Hash] any specific variant overrides. variant:testing **overrides Select the testing variant. overrides [Hash] any specific variant overrides. variant:force name **overrides Force a specific variant. name [Symbol] the default variant. overrides [Hash] any specific variant overrides. variant:show Show variant-related environment variables.
Console
The console gem exposes bake tasks to change the log level.
$ bake list console Bake::Loader console-1.8.2 console:info Increase the verbosity of the logger to info. console:debug Increase the verbosity of the logger to debug.