Gemfile Builder (Ruby)

Generate a Gemfile for a Ruby or Rails project

Create a Bundler Gemfile with source, Ruby version, the Rails gem and database driver, plus common gems for authentication (Devise), background jobs (Sidekiq) and testing (RSpec) in the right groups.

What does the pessimistic operator ~> mean?

The ~> operator allows updates that do not change the leftmost specified part. ~> 7.2 permits any 7.x at or above 7.2, while ~> 7.2.2 permits 7.2.x only. It lets Bundler pick up bug-fix releases automatically while blocking breaking version jumps.

The Gemfile Builder generates a Bundler Gemfile for a Ruby or Rails project, with the right gems placed in the right groups. Pick your Ruby and Rails versions, your database, and toggles for authentication, background jobs and testing.

How it works

A Gemfile starts with a source (RubyGems) and a ruby version directive, then declares gems. For Rails, the tool adds the rails gem pinned with the pessimistic ~> operator, the database driver (pg, mysql2 or sqlite3), puma, bootsnap and redis. Optional gems — devise for auth, sidekiq for jobs — are added at the top level, while testing and tooling gems go into group :development, :test, group :development and group :test blocks so they never ship to production.

The ~> operator is what keeps versioning safe: ~> 7.2 allows any 7.x from 7.2 up but blocks 8.0, so you pick up bug fixes without breaking changes.

Example

After saving the Gemfile, resolve and lock versions:

bundle install                       # writes Gemfile.lock
bundle install --without development test   # production deploy

Tips and notes

Commit Gemfile.lock for applications so every environment installs identical gems. The database gem must match the adapter in config/database.yml or Rails will fail to boot. Keep rubocop, capybara and selenium-webdriver in their groups so production never loads test tooling, and run bundle update <gem> to bump a single dependency within its pessimistic constraint.