How to refer a local gem in ruby?

user810923 picture user810923 · Jun 22, 2011 · Viewed 7.5k times · Source

I pack some ruby code into a gem. I want to refer the code in the gem in some other code. So in the Gemfile I specify the gem's name, version, and local path. Like:

gem 'gemname','0.x', :path => 'RELATIVE_PATH_TO_GEM_FILE'

After bundle install, I see

Using gemname (0.x) from source at RELATIVE_PATH_TO_GEM_FILE

But when I run the code, it can't find the code in the gem. LOAD_PATH shows ABSOLUTE_PATH_TO_GEM_FILE/lib.

No wonder it can't find the code, there's only gem file under ABSOLUTE_PATH_TO_GEM_FILE. it's not unpacked. So there's no lib directory.

if I gem install that gem file into my system, then all works fine. I can see the gem file was unpacked into source code files. But my question is if it can refer the local gem file directly somehow?

Answer

Seamus Abshere picture Seamus Abshere · Jun 22, 2011

No, you can't refer to a .gem file directly.

In your terminology, you need to use an "unpacked" gem.

:path => '/foo/bar/'

where /foo/bar/ is a (gem) directory with lib/, etc.