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 cldwalker-local_gem -s http://gems.github.com

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:

1. Mild: Call LocalGem with its class methods.

    require 'local_gem'
    LocalGem.local_gem 'alias' 

2. Hot: Call methods directly having included it into your Kernel namespace.

    require 'local_gem'
    include LocalGem
    local_gem 'alias'

3. Spicy: Override require() and gem() with local_require() and local_gem() respectively.

    require 'local_gem'
    require 'local_gem/override'
    gem 'alias'

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.

Limitations

The override and rcov don’t play nicely.