Tweetegy On the edge of chaos with Ruby, Rails, JavaScript and AngularJS.

| About | Search | Archive | Github | RSS |

The easy way to create a new Ruby Gem!

If 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

  1. Install git core

    apt-get install git-core

  2. Install jeweler gem

    gem install jeweler

  3. 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.

    export JEWLER_OPTS = "--spec"

  4. Setup your global username and email for git

    git config --global user.name "Your Company Name"
    git config --global user.email "yourname@yourcompanyname.com"

  5. Script your new gem using jeweler

    jeweler yourshinynew_gem

  6. Set your init version. I do this so that I can easily generate the gemspec later.

    rake version:write MAJOR=0 MINOR=1 PATCH=0

  7. 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_newgem” 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_newgem” 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

  8. Generate the gemspec

    rake gemspec

  9. 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. ** **

    code.write!

  10. Build the gem

    rake build

  11. Install the gem

    rake install

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!