tags:

views:

221

answers:

3

Hi,
I've built my first gem but I don't seem to be able to get it to install correctly. I can issue the command

sudo gem install ceilingfish-toto

Which produces the output

Successfully installed ceilingfish-toto-0.3.6
1 gem installed

But when I then type gem which ceilingfish-toto. I get the output

Can't find ruby library file or shared library ceilingfish-toto

Which is very strange because if I go and look in my gems folder I can see all the files installed there

# ls -l /opt/local/lib/ruby/gems/1.8/gems/ceilingfish-toto-0.3.6/
total 48
-rw-r--r--  1 root  admin  1053 14 Feb 17:16 LICENSE
-rw-r--r--  1 root  admin  6166 14 Feb 17:16 README.md
-rw-r--r--  1 root  admin   879 14 Feb 17:16 Rakefile
-rw-r--r--  1 root  admin     6 14 Feb 17:16 VERSION
-rw-r--r--  1 root  admin  2477 14 Feb 17:16 ceilingfish-toto.gemspec
drwxr-xr-x  7 root  admin   238 14 Feb 17:16 test

Does anyone know what could cause this? I think it's complaining because there is a hyphen in the gem name. You can see the gemspec here http://github.com/ceilingfish/toto

+1  A: 

gem which ceilingfish-toto looks through the gem require path for a file named ceilingfish-toto.rb. Since there isn't one, it returns nothing. What would work for you is gem which toto, but since lib/ is not included in your gem spec, the lib files are not installed, so it doesn't exist.

Rerunning rake gemspec might fix the problem.

As an aside, you can check whether a gem is installed by its name by using gem list ceilingfish-toto which should show you it is installed, regardless of the files it has(it will also list the versions installed).

BaroqueBobcat
Thanks for the advice, this was indeed the problem, but I found it a couple of hours ago.
Ceilingfish
A: 

OK, so the problem here appears to be that there was a problem with my gemspec file. From what I can tell there absolutely has to be a file with the name lib/gem-name.rb so in this case I needed lib/ceilingfish-toto.rb.

This doesn't seem to be true for some other gems to operate correctly. For example mime-types or rest-client but they do not show up with gem which, but they do actually work.

I'm not sure this is entirely correct yet, I'm sure there should be a way to get a gem with a hyphen in the name to behave correctly. If I find out I'll post back and let y'all know.

Ceilingfish
+1  A: 

It's not the hyphen.

gem which searches for library files in gems, not gems. Compare:

$ gem which haml
/home/dave/.gem/ruby/1.8/gems/haml-3.0.12/lib/haml.rb
$ ls haml-3.0.12/lib/h*
haml  haml.rb  haml.rbc

Peachy. Note the existance of lib/haml.rb.

$ gem which rails
ERROR:  Can't find ruby library file or shared library rails
$ ls rails-2.3.8/lib/r*
rails_generator.rb  railties_path.rb  rubyprof_ext.rb  ruby_version_check.rb

There is no lib/rails.rb. But try:

$ gem which railties_path # not a gem
/home/dave/.gem/ruby/1.8/gems/rails-2.3.8/lib/railties_path.rb

So gem which ceilingfish-toto throws an error even when ceilingfish-toto is installed because there is no lib/ceilingfish-toto.rb file (there's not even a lib folder).

Dave Nolan