Gem Generator

May 16, 2024 · View on GitHub

Cirrus CI - Base Branch Build Status Codecov branch Code Climate 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.

Installation

Install it globally:

gem install gem_generator

Usage

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 --git

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

Other options

gem_generator inherits project_generator, so please check it's general options, like --indentation, or you can use --help at any moment.

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: alex.wayfer@gmail.com

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 partExample of sourceExample of result
gem_namegem_name.gemspecfaraday-my_middleware.gemspec
gem_pathlib/gem_path/version.rb.erblib/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:

VariableExample of result
namefaraday-my_middleware
titleFaraday My Middleware
pathfaraday/my_middleware
module_nameFaraday::MyMiddleware
modules['Faraday', 'MyMiddleware']
version_constantFaraday::MyMiddleware::VERSION
summaryasked from user
summary_stringsummary wrapped in ' or ", depending on ' inside
descriptionby default is summary with guaranteed dot at the end
indentationtabs or spaces, as user specified by option
github_pathAlexWayfer/faraday-my_middleware
github_namespace_urihttps://github.com/AlexWayfer
github_urihttps://github.com/AlexWayfer/faraday-my_middleware
author_nameAlexander Popov
author_name_stringauthor name wrapped in ' or ", depending on ' inside
author_emailalex.wayfer@gmail.com

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_name 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.

Development

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

Then, run bundle exec 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.

Contributing

Bug reports and pull requests are welcome on GitHub.

License

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