Gem Generator

Cirrus CI - Base Branch Build Status Codecov branch Code Climate Depfu license Gem

Gem for new gems generation.

It was created for myself, but you can suggest options for generation to adopt it for your usage.


Install it globally:

gem install gem_generator


With local template

gem_generator --namespace=your_github_nickname name_of_a_new_gem path/to/template

With GitHub template

gem_generator --namespace=your_github_nickname name_of_a_new_gem template_github_org/template_github_repo

Be aware: gem_generator uses template/ directory from the GitHub repo, not the root one.

Config file

You can create a config file, .gem_generator.yaml (or .yml) like this:

## This can be overwriten via `--namespace` CLI option, config just as default
:namespace: AlexWayfer

## These options have defaults from `git config --get user.*`
# :author:
#   :name: Alexander Popov
#   :email: [email protected]

Gem Generator will look for it in each directory from current to the root, so the common place for it in the home directory, but you can redefine it, for example, in some directory for work projects.

Template creation

Example of gem template you can see at AlexWayfer/gem_template.

Available paths:

Path part Example of source Example of result
gem_name gem_name.gemspec faraday-my_middleware.gemspec
gem_path lib/gem_path/version.rb.erb lib/faraday/my_middleware/version.rb

Any *.erb file will be rendered via ERB; if you want an *.erb file as result — name it as *.erb.erb (even if there are no tags).

Available variables:

Variable Example of result
name faraday-my_middleware
title Faraday My Middleware
path faraday/my_middleware
module_name Faraday::MyMiddleware
modules ['Faraday', 'MyMiddleware']
version_constant Faraday::MyMiddleware::VERSION
summary asked from user
summary_string summary wrapped in ' or ", depending on ' inside
description by default is summary with guaranteed dot at the end
indentation tabs or spaces, as user specified by option
github_path AlexWayfer/faraday-my_middleware
author_name Alexander Popov
author_name_string author name wrapped in ' or ", depending on ' inside
author_email [email protected]

By default indentation is tabs, but if a template spaces-indented — option will not affect. So, this option only for tabs-indented templates.

Git templates

You can create public git-templates and then guide users to call gem_generator gem_game your_org/your_repo --git, but be aware that gem_generator will look for template inside template/ directory to allow you having out-of-template README, specs (for the template itself), anything else.


After checking out the repo, run bundle install to install dependencies.

Then, run toys rspec to run the tests.

To install this gem onto your local machine, run toys gem install.

To release a new version, run toys gem release %version%. See how it works here.


Bug reports and pull requests are welcome on GitHub.


The gem is available as open source under the terms of the MIT License.