Gemsmith

Gem Version Code Climate GPA Code Climate Coverage Gemnasium Status Travis CI Status Patreon

A command line interface for smithing new Ruby gems.

Table of Contents

Features

  • Builds a gem skeleton with enhanced Bundler functionality.
  • Supports common settings to be applied when creating new gems.
  • Supports Thor command line interface (CLI) functionality.
  • Supports Ruby on Rails.
  • Supports Pry.
  • Supports Guard.
  • Supports RSpec.
  • Supports Rubocop.
  • Supports Code Climate.
  • Supports Gemnasium.
  • Supports Travis CI.
  • Supports Patreon.
  • Provides the ability to open the source code of any gem within your favorite editor.
  • Provides the ability to read the documentation of any gem within your default browser.
  • Adds commonly needed README, CHANGELOG, CONTRIBUTING, CODE OF CONDUCT, LICENSE, etc. documentation.

Requirements

  1. A UNIX-based system
  2. MRI 2.x.x
  3. RubyGems
  4. Bundler

Setup

For a secure install, type the following from the command line (recommended):

gem cert --add <(curl -Ls https://www.alchemists.io/gem-public.pem)
gem install gemsmith --trust-policy MediumSecurity

NOTE: A HighSecurity trust policy would be best but MediumSecurity enables signed gem verification while allowing the installation of unsigned dependencies since they are beyond the scope of this gem.

For an insecure install, type the following (not recommended):

gem install gemsmith

You can configure common settings for future gem builds by creating the following file:

~/.gemsmithrc

...using the following settings (as a simple example):

:author:
  :name: "Joe Smith"
  :email: "[email protected]"
  :url: "https://www.example.com"
:organization:
  :name: "ExampleSoft"
  :url: "https://www.example.com"

The following defaults are used when no options are configured:

:year: <current year>
:github_user: <git config GitHub user>
:gem:
  :platform: "Gem::Platform::RUBY"
  :home_url: ""
  :license: "MIT"
  :private_key: "~/.ssh/gem-private.pem"
  :public_key: "~/.ssh/gem-public.pem"
:author:
  :name: <git config user name>
  :email: <git config user email>
  :url: ""
:organization:
  :name: ""
  :url: ""
:versions:
  :ruby: <current Ruby version>
  :rails: "4.2"
:create:
  :cli: false
  :rails: false
  :security: true
  :pry: true
  :guard: true
  :rspec: true
  :rubocop: true
  :code_climate: true
  :gemnasium: true
  :travis: true
  :patreon: true

While Gemsmith is fully customizable, please keep in mind that these are global settings and, once set, will affect all future gem creations. Further customization is also provided via the CLI for a customizable experience per gem if necessary.

Usage

Command Line Interface (CLI)

From the command line, type: gemsmith --help

gemsmith -c, [create=CREATE]  # Create new gem.
gemsmith -e, [--edit]         # Edit Gemsmith settings in default editor.
gemsmith -h, [--help=HELP]    # Show this message or get help for a command.
gemsmith -o, [open=OPEN]      # Open a gem in default editor.
gemsmith -r, [read=READ]      # Open a gem in default browser.
gemsmith -v, [--version]      # Show Gemsmith version.

For more gem creation options, type: gemsmith --help --create

-c, [--cli], [--no-cli]                    # Add CLI support.
-r, [--rails], [--no-rails]                # Add Rails support.
-S, [--security], [--no-security]          # Add security support.
                                           # Default: true
-p, [--pry], [--no-pry]                    # Add Pry support.
                                           # Default: true
-g, [--guard], [--no-guard]                # Add Guard support.
                                           # Default: true
-s, [--rspec], [--no-rspec]                # Add RSpec support.
                                           # Default: true
-R, [--rubocop], [--no-rubocop]            # Add Rubocop support.
                                           # Default: true
-C, [--code-climate], [--no-code-climate]  # Add Code Climate support.
                                           # Default: true
-G, [--gemnasium], [--no-gemnasium]        # Add Gemnasium support.
                                           # Default: true
-t, [--travis], [--no-travis]              # Add Travis CI support.
                                           # Default: true
-P, [--patreon], [--no-patreon]            # Add Patreon support.
                                           # Default: true

Rake

Once a gem skeleton has been created, the following tasks are available within the project via Bundler (i.e. rake -T):

rake build                 # Build gemsmith-6.0.0.gem into the pkg directory
rake clean                 # Clean gem artifacts
rake doc                   # Update README (table of contents)
rake install               # Build and install gemsmith-6.0.0.gem into system gems
rake install:local         # Build and install gemsmith-6.0.0.gem into system gems without network access
rake publish               # Build, tag v6.0.0 (signed), and push gemsmith-6.0.0.gem to RubyGems
rake release               # Create tag v6.0.0 and build and push gemsmith-6.0.0.gem to Rubygems
rake rubocop               # Run RuboCop
rake rubocop:auto_correct  # Auto-correct RuboCop offenses
rake spec                  # Run RSpec code examples

Run bundle exec rake to run everything (includes all specs and code quality checks).

Upgrades

For those upgrading from Gemsmith 5.6.0 please be aware of the following changes:

  • Move your ~/.gemsmith/settings.yml settings to the new ~/.gemsmithrc file. Refer to the Setup documentation mentioned above for details.
  • The --cli/-c create option has been replaced with the --bin/-b create option.
  • The --code-climate create option shortcut is now -C instead of -c.
  • Tocer has replaced DocToc as a pure Ruby implementation for generating README table of contents and removing the dependency on NPM.
  • The rake readme:toc task has been replaced with rake doc.
  • Using Rake to build or publish a gem will fail if uncommitted Git changes are detected helping to prevent you from publishing a gem with missing changes.

Tests

To test, run:

bundle exec rake

Security

Git Signing Key

To sign your Git tags, start by installing and configuring GPG:

brew install gpg
gpg --gen-key

When setting up your GPG key, here is an example of safe defaults:

  • Key kind: RSA and RSA (default)
  • Key size: 4096
  • Key validity: 0
  • Real Name: <your name>
  • Email: <your email>
  • Passphrase: <your passphrase>

To obtain your key, run the following and take the part after the forward slash:

gpg --list-keys | grep pub

Add your key to your global Git configuration in the [user] section. Example:

[user]
  signingkey = <your GPG key>

Now, when publishing your gems with Gemsmith (i.e. bundle exec rake publish), signing of your Git tag will happen automatically. Should you not want to sign your tags, use bundle exec rake release which is the same as bundle exec rake publish except the Git tag is not signed.

Gem Certificates

To create a certificate for your gems, run the following:

cd ~/.ssh
gem cert --build [email protected]
chmod 600 gem-*.pem

The resulting *.pem key files can be referenced via the :private_key: and :public_key: keys within the ~/.gemsmithrc file.

To learn more about gem certificates, read the following:

Promotion

Once your gem is released, you might want to let the world know about your awesomeness. Here are several resources:

Versioning

Read Semantic Versioning for details. Briefly, it means:

  • Patch (x.y.Z) - Incremented for small, backwards compatible bug fixes.
  • Minor (x.Y.z) - Incremented for new, backwards compatible public API enhancements and/or bug fixes.
  • Major (X.y.z) - Incremented for any backwards incompatible public API changes.

Code of Conduct

Please note that this project is released with a CODE OF CONDUCT. By participating in this project you agree to abide by its terms.

Contributions

Read CONTRIBUTING for details.

License

Copyright (c) 2011 Alchemists. Read the LICENSE for details.

History

Read the CHANGELOG for details.

Credits

Developed by Brooke Kuhlmann at Alchemists.