Here’s my checklist for creating a new gem.
Check the Name
Create a Folder
I organize all my code in source and since I often fork code from others to contribute, create a subfolder with the Github username, including mine.
$ mkdir ~/source/ruby-enum/dblock $ cd ~/source/ruby-enum/dblock
Initialize a Git Repository
$ git init Initialized empty Git repository in /home/dblock/source/ruby-enum/dblock/.git/
Create a Github Repo
Create a new repository on Github.
Add it as a remote.
$ git remote add origin firstname.lastname@example.org:dblock/ruby-enum.git
Create a Readme
Documentation is written in Markdown. Create and commit a README.md.
$ git commit -m "Added README." [master acc5880] Added README. 1 file changed, 4 insertions(+) create mode 100644 README.md
Push the README to Github.
$ git push origin master Counting objects: 6, done. Compressing objects: 100% (5/5), done. Writing objects: 100% (6/6), 963 bytes, done. Total 6 (delta 0), reused 0 (delta 0) To email@example.com:dblock/ruby-enum.git * [new branch] master -> master
Add a License
Every project needs a license. I use the MIT license because it’s short and nobody has time to read licenses. Add a copyright notice to the README, don’t forget future contributors.
Copyright (c) 2013, Daniel Doubrovkine and Contributors. All Rights Reserved. This project is licenced under the [MIT License](LICENSE.md).
A Gemfile is something that comes with Bundler and declares gem dependencies.
$ gem install bundler Fetching: bundler-1.3.5.gem (100%) Successfully installed bundler-1.3.5 1 gem installed Installing ri documentation for bundler-1.3.5... Installing RDoc documentation for bundler-1.3.5...
Create a Gemfile. For now it just says where to get other gems from.
$ bundle install Resolving dependencies... Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
The generated Gemfile.lock should not be included, create a .gitignore.
Create lib/ruby-enum.rb _and _lib/ruby-enum/version.rb.
You. Must. Test.
Add RSpec to Gemfile.
Tests need some setup, specifically to load the code in lib. Create spec/spec_helper.rb.
Create a test in spec/ruby-enum/version.rb.
Add .rspec to pretty-print test output.
--format documentation --color
A ruby-enum.gemspec is a gem declaration.
The declaration can be loaded in Gemfile, so that we can list dependencies in one place.
When running under Bundler, the Gemfile will automatically be loaded, which will automatically load the gem specification.
$ bundle exec irb 1.9.3-p362 :001 > require 'ruby-enum' => true 1.9.3-p362 :002 > Ruby::Enum::VERSION => "0.1.0"
Bundler comes with a number of Rake tasks to release a gem. Add Rake to Gemfile.
Create a Rakefile.
$ rake -T rake build # Build ruby-enum-0.1.0.gem into the pkg directory. rake install # Build and install ruby-enum-0.1.0.gem into system gems. rake release # Create tag v0.1.0 and build and push ruby-enum-0.1.0.gem to Rubygems $ rake build ruby-enum 0.1.0 built to pkg/ruby-enum-0.1.0.gem.
Add pkg to .gitignore.
Default Rakefile to Running Tests
Add .travis.yml, register the project on travis-ci.org and add a badge.
Enum Library Code
Create a CHANGELOG to list current and future updates.
### 0.1.0 (5/14/2013) * Initial public release - [@dblock](https://github.com/dblock).
Add a contributing section to README.
* Fork the project. * Make your feature addition or bug fix with tests. * Update CHANGELOG. * Send a pull request. Bonus points for topic branches.
Release the Gem
$ rake release
Prepare for Next Release
Bump the version, add a Next Release section to CHANGELOG.md.
### Next Release (TBD) * Your Contribution Here
All source code for the above can be found at https://github.com/dblock/ruby-enum.