Task. Bundler: The best way to manage Ruby applications. Technicalpickles/jeweler - GitHub. How to start writing a ruby gem. If you are a Ruby developer, by now, you have probably used tons of gems in your apps. That's one of the best things of using Ruby, a lot of people writes repeatable code that you can easily integrate into your own apps.
In this brief tutorial, I will try to explain the basic things you need to know in order to start writing your own gems, you know, just in case you have something to share with the world. Setting up the folders We'll start by creating the gem folder structure using Bundler. First thing you have to do is, install bundler itself. Easy. $ gem install bundler Now, bundler comes with a handy command to generate the basic files to start writing a gem. $ bundle gem awesome_gem create awesome_gem/Gemfile create awesome_gem/Rakefile create awesome_gem/.gitignore create awesome_gem/awesome_gem.gemspec create awesome_gem/lib/awesome_gem.rb create awesome_gem/lib/awesome_gem/version.rb The Gemspec All gems have a .gemspec file.
Let's say your gem heavily depends on rails. The code Unit tests. A Different View... Bundler rocks, but you need to think differently about how to start and run your Rails app. The Bundler Way You should realise that Bundler is a library management tool. This has to be in your mind when you are getting a Rails application running on version 3.0.
For example, I had a new Rails application that I want to run with PostgreSQL, so I go in and change database.yml to look at my PostgreSQL database instead of the Sqlite3 database, fairly standard, straight forward opperation. Then starting the application console however, I got a bit of a shock: This confused me for a second, I was sure that the pg gem was installed on my system, and the following confirmed it for me: mikel@baci.lindsaar.net ~ $ gem list pg *** LOCAL GEMS *** pg (0.8.0) OK, but the rails app was complaining that it couldn’t find it. This is an important datum, Bundler is a library management tool, and it allows you to totally bypass the rubygems on your system. So, first things first, bundler gives you some tools: