This Makefile aids in developing a ruby gem. It's pretty opinionated to my workflow, but it might be useful to you, so here it goes.
- Assumes you use of
gs
(orgst
) for managing gemsets. - Assumes you use
dep
for installing dependencies. Because fuck Bundler. - Assumes the directory in which the source code is located is named
after the gem. So
basename $(dirname $(pwd))
would returnfoo
if you wouldgem install foo
. - Assumes the existance of a
lib/*/version.rb
that has a line that defines aVERSION
constant.
If All those assumptions / prerequisites are met, then you can:
make test
: run your tests. By default this Makefile assumes the use of [cutest
][cutest], but you can change that to whatever strikes your fancy.make pkg/foo-1.0.0.gem
: Build the gem. This will properly track any changes to the gemspec and to thelib/foo/version.rb
file.make all
(or justmake
): Run tests and then build all the gems.make release
: Build gems and then push them to https://rubygems.org.make clean
: Delete any built gems.
The tests will dep install
before running, but only if the .gems
file
changed. In order to avoid polluting the global namespace and installing
gems in your root GEM_HOME, all the tasks in this Makefile will fail if
you're not inside a gemset (i.e. GS_NAME
isn't set).
The Makefile will also run tasks with ./lib
and ./test
added to your
ruby include path (via expanding the RUBYLIB
env var). This should allow
you to work without needing to touch the $LOAD_PATH
inside your project,
which is a horrible practice.
In case your directory doesn't exactly match the gem name, you can just
redefine the PACKAGES
variable to list the names of the package(s) to be
built.
You can also change the VERSION_FILE
variable in order to change the
pattern to find the version.rb
file. This defaults to lib/*/version.rb
.