The first thing you should do when need something during development is search for a gem. For this task, you can use ruby-toolbox.com, which rates and group gems, and rubygems.org, that hosts all the community gems.
So, if you don’t find what you want or maybe if you just want something with a different approach, you can use Jeweler to create a new gem. It helps you with the scaffold project template and tasks like, for example, release.
In order to start with Jeweler, you will need a Git configuration (get a Github account), but you don’t have to worry since it prompts as needed. After installing it (gem install jeweler), create your new gem project:
You can also use Rspec instead for testing:
jeweler --rspec your_gem_name
The following folders and files will be created:
- lib/: place your ruby files
- lib/your_gem_name.rb: the default gem ruby file, you could use it to require all the other stuff
- test or spec/: test files
- Gemfile: the gem development dependencies
- LICENSE.txt: license description
- Rakefile: contain the Rake tasks, configurations that you will have to set (gem summary, description, author details, etc) and you should also place the runtime gem dependencies here (adding for example gem.add_dependency ‘nokogiri’, ‘>= 1.2.1′)
- README.rdoc: the project documentation. If you are using Github, it will be displayed in the main page
- VERSION: version in string format, like major.minor.patch
Configure your development dependencies on the Gemfile and configurations on the Rakefile. I would recommend to set the dependency version needed instead of leaving blank, so you can guarantee that your gem will work. Then call:
If you want to configure the version, you can update VERSION file directly or use:
rake version:write MAJOR=0 MINOR=1 PATCH=0
After working on the gem, it is time to shiiiip it! This release task will tag your project version and push it to rubygems.org. If you don’t have an account yet, you can just create it.
To learn more about Jeweler, check https://github.com/technicalpickles/jeweler
Start a gem today! Have fun!