Tweetegy On the edge of chaos with Blockchain, Dapps, DeFi, JavaScript

| 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
  1. Install jeweler gem
gem install jeweler
  1. 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"
  1. Setup your global username and email for git
git config --global user.name "Your Company Name"
git config --global user.email "yourname@yourcompanyname.com"
  1. Script your new gem using jeweler
jeweler your_shiny_new_gem
  1. 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
  1. 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
  2. Generate the gemspec
rake gemspec
  1. 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!
  1. Build the gem
rake build
  1. 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!