Created
May 9, 2012 08:48
-
-
Save zaius/2643079 to your computer and use it in GitHub Desktop.
Allow requiring of global gems from outside of the Gemfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Include this in your .irbrc | |
def unbundled_require(gem) | |
if defined?(::Bundler) | |
spec_path = Dir.glob("#{Gem.dir}/specifications/#{gem}-*.gemspec").last | |
if spec_path.nil? | |
warn "Couldn't find #{gem}" | |
return | |
end | |
spec = Gem::Specification.load spec_path | |
spec.activate | |
end | |
begin | |
require gem | |
yield if block_given? | |
rescue Exception => err | |
warn "Couldn't load #{gem}: #{err}" | |
end | |
end | |
# Then use like this | |
unbundled_require 'wirb' do | |
Wirb.start | |
end |
NoMethodError: undefined method `activate' for #Gem::Specification:0x1334b3bb8
@danielribeiro - Which gem are you trying to load? Which version of ruby are you using?
On both Ree and Ruby 1.8.7 with Bundler version 1.0.21. I get this with all gems, in particular with wirble. The os is mac Lion (Mac OS X Lion 10.7.4 (11E53))
Ah ok. I've well and truly given up on 1.8, so this will probably only work on 1.9. But let me know if you get it working!
I added a fix à la the Gemfile for requiring a gem with a different name than the gem itself: https://gist.github.com/3894925
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice! Works for me for now =)