The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
LocalGem Loads Your Current Code Now!

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Gabriel Horner

Posts: 62
Nickname: cldwaker
Registered: Feb, 2009

Gabriel Horner is an independent consultant who can't get enough of Ruby
LocalGem Loads Your Current Code Now! Posted: Feb 5, 2009 2:11 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Gabriel Horner.
Original Post: LocalGem Loads Your Current Code Now!
Feed Title: Tagaholic
Feed URL: http://feeds2.feedburner.com/tagaholic
Feed Description: My ruby/rails/knowledge management thoughts
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Gabriel Horner
Latest Posts From Tagaholic

Advertisement
The other day while actively developing a gem, I got tired of rake reinstalling it to test its effect in irb with some other gems. I wanted to use the edge version of my gem, version now. So I hacked up $LOAD_PATH:


$LOAD_PATH.unshift '/my/path/to/gem/lib'


This effectively made my live gem directory a gem, as far as requiring files is concerned. However once I did this in irb a couple of times and even in a file, it started to feel dirty and repetitious. Why couldn't I just require my local gem just like I do when it's installed in my gem directories? So I hacked on it later and out came LocalGem.

LocalGem simply maps names to file paths and when given a name, adds its corresponding path to $LOAD_PATH like above. You can setup the name-path mapping via a yaml config file or a method call.


require 'local_gem'
LocalGem.setup_config do |c|
c.gems = {'mygem'=>'/path/to/mygem', 'anothergem'=>'/path/to/anothergem'}
end


LocalGem then provides two methods, local_gem() and local_require() to act like gem() and require() but with knowledge of your local gems. You can use these two methods in one of three ways, depending on how much you want LocalGem to invade your namespace:

Peace time:

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


Diplomacy is fading:

include LocalGem
local_gem 'mygem'
local_require 'anothergem'


You're fscked:

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


Give it a whirl with:

sudo gem install cldwalker-local_gem -s http://gems.github.com


Since LocalGem effectively lets you make any subset of Ruby code gem-like, some other cool uses for it could be:
  • To gemify all those cloned Github projects that aren't gems. You may want to look at coral if you're doing this enough.
  • Wrap up a subsection of a gem as a local gem.
  • Wrap up any group of unloved Ruby files in the same directory as a local gem.


Feel free to check the purty docs and github page as well.

Read: LocalGem Loads Your Current Code Now!

Topic: Amethyst Flex Designer - The Full Monty! Previous Topic   Next Topic Topic: Can We Share Our Extensions Without Monkey Patching?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use