The easy way to create a new Ruby Gem!
11 Jan 2010If you want to make a Ruby Gem and want to do it in a very easy way then here’s is one very good option – use Jeweler! Thanks to John Nunemaker at RailsTips for pointing me in the right direction with his post Building API Wrapping Gems
- Install git core
- Install jeweler gem
- Now add the following line to your bashrc file to ensure that you always use spec (that if you do use spec). Otherwise the default is shoulda and if your happy using that then you can skip this part.
- Setup your global username and email for git
- Script your new gem using jeweler
- Set your init version. I do this so that I can easily generate the gemspec later.
- Modify the new gem rake file to add the meta info for your project [source lang=”ruby”] begin require ‘jeweler’ Jeweler::Tasks.new do |gem| gem.name = “your_shiny_new_gem” gem.summary = %Q{A simple gem to access the Shiny API} gem.description = %Q{Use this gem to access our Shiny API !!} gem.email = “yourname@yourcompanyname.com” gem.homepage = “http://bitbucket.org/yourrepo/your_shiny_new_gem” gem.authors = [“Your Company Name”] gem.add_development_dependency “rspec”, “>= 1.2.9″ # gem is a Gem::Specification… see http://www.rubygems.org/read/chapter/20 for additional settings end Jeweler::GemcutterTasks.new rescue LoadError puts “Jeweler (or a dependency) not available. Install it with: gem install jeweler” end
- Generate the gemspec
- Write the code that goes into your gem. This is where your own imagination comes in! See the Google Weather API Gem for an example. When your gem is finished (including all your tests passing!) move on to building and testing the installation of the Gem. ** **
- Build the gem
- Install the gem
You can deploy to github (the easiest solution when using Jeweler). However, you can still deploy to other repositories like Bitbucket for example. Then, as recommended by the author of Jeweler, Josh Nichols, have a delicious beverage!
Happy Gem stone cutting!