Description

You have the beginnings of a ruby library and you want to access it quick. You don’t want to bother making a gemspec for it and uninstalling/reinstalling its gem while you mess with it. Simply tell LocalGem what paths it should load for your local gem and they will be loaded. Note that it doesn’t matter how gem-like your project is ie lib and bin directories etc. LocalGem only needs to know the full path to your gem/library.

Setup

Install the gem with:

sudo gem install local_gem

To setup your local gem paths, give LocalGem a hash of gem names pointing to a path or an array of paths to load. You can do this with LocalGem.setup_config

LocalGem.setup_config do |c|
  c.gems = {'gem1'=>"/gem1/path/lib", 'gem2'=> ["/gem2/path/lib", "/gem2/path/bin"] }
end

Or a config file at either a local local_gem.yml or ~/.local_gem.yml . See local_gem.yml.example for an example config file.

Usage

The two main methods that LocalGem provides are local_gem() and local_require() which map to gem() and require() respectively. Both methods will attempt to load local gems that you have defined. If no gem is found than they resort to default gem/require behavior.

There are 3 ways to use this library, depending on how much you want LocalGem to invade your namespace:

1. Peace time:

    require 'local_gem'
    LocalGem.local_gem 'mygem'
    LocalGem.local_require 'anothergem'

2. Diplomacy is fading:

    require 'local_gem'
    include LocalGem
    local_gem 'mygem'
    local_require 'anothergem'

3. You're fscked (Don't worry, they should default to their normal behavior, should being the
   keyword):

    require 'local_gem'
    require 'local_gem/override'
    gem 'mygem'
    require 'anothergem'

All three ways would add my local alias library to $LOAD_PATH. These three ways also apply to local_require().

Motivation

Got tired of installing/uninstalling the latest version of a gem I’m actively working on. This also makes it easy to treat any random directory of ruby files as a gem.

tagaholic.me/2009/02/05/local-gem-loads-your-current-code-now.html

Limitations

The override and rcov don’t play nicely.