Conceptric
  1. Bundler for Sinatra dependencies

    Package dependencies are always a nightmare and with multiple applications on my server, each with their own set of Ruby gems, controlling the version they’re using has become important.

    I’ve been using Sinatra for more and more projects, but there came a point this week when I realised that I was in danger of accidentally upgrading gem versions without testing first.

    Dependencies in crisis

    You see, my applications all use the system gems, and require "gem_name" to load the most recent local version.

    As the number of applications on the server grew, I found that this had the effect of automatically upgrading all my applications whenever I upgraded a gem, whether intentional or otherwise.

    Now I like to take advantage of bug fixes and new features of the latest releases whenever possible, but I don’t necessarily want to upgrade every application in a single mammoth coding session, or have to hold back the deployment of a new application until the others have been upgraded and fully tested.

    Gem and version dependency control

    It dawned on me that I needed some control over both the actual gems and the versions each application used.

    Simplicity

    The simplest approach is to control what it available in the application load path before loading it in the usual way, and these are the commands for the job.

    gem "gem_name", "gem_version" require "gem_name"

    I tried this with some success, and quite a few of my applications are still using this method for now. But I decided to try using Bundler as a long term solution.

    Bundler

    If you want to know about Bundler I suggest you try the github repository or some of the posts on Yehuda Katz blog.

    I found it pretty easy to integrate with Sinatra by following these instructions, and my Gemfile looked like this.

    source "http://rubygems.org" gem 'sinatra', '1.0' gem 'haml', '3.0.13' group :test do gem 'rspec', '1.3.0', :require => 'spec' gem 'rspec-rails', '1.3.2' gem 'cucumber', '0.8.3' gem 'cucumber-rails', '0.3.2' gem 'webrat', '0.7.1' end

    Testing with WEBrick went like clockwork, working smoothly with both RSpec and Cucumber, but when I tried to get things running on Passenger this is what I saw.

    BundlerLoadError.JPEG

    This had me stumped for quite a while. I reinstalled Bundler; checked out the installation of Passenger, my $GEM_PATH, and the Ruby environment; nothing worked.

    The solution turned out to be much simpler than all that: add the Bundler gem to the Gemfile dependencies.

    gem 'bundler', '0.9.26' gem 'sinatra', '1.0' gem 'haml', '3.0.13'

    I wish it had occurred to me earlier, but the simple ones never do. Anyhow, my Passenger deployments work perfectly, and I’ll be migrating all my Sinatra apps over to Bundler.

    Capistrano integration

    And if you, like me, want to use Bundler to manage dependencies during Capistrano deployment, you might like to try these useful recipes.

    There are no comment for this post at the moment. Please feel free to let me know what you think.

    What do you think?

    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.