gems and require

M

Martin DeMello

Finally gotten around to changing my 'require_gem' code, and I've
noticed that for many gems, the name of the file to "require" is not
the same as the gem's name. Furthermore, there's no way to find out
what file I *do* need to require other than looking at the directory
structure of the gem. An option to gem that would list all requirable
files would be a nice addition.

martin
 
A

Alex Young

Martin said:
Finally gotten around to changing my 'require_gem' code, and I've
noticed that for many gems, the name of the file to "require" is not
the same as the gem's name. Furthermore, there's no way to find out
what file I *do* need to require other than looking at the directory
structure of the gem. An option to gem that would list all requirable
files would be a nice addition.
Personally, I'd prefer that a require 'gemname' just loaded all files in
the gem's lib directory, but that's probably just me...
 
A

ara.t.howard

Personally, I'd prefer that a require 'gemname' just loaded all files in the
gem's lib directory, but that's probably just me...

yikes! i've got about 80 libs installed!

considering that rails, for instance, takes about 1/2 second to load it's libs,
we could be looking at __tens__ of seconds of startup delay for every ruby
script on a large system


-a
 
M

Martin DeMello

yikes! i've got about 80 libs installed!

considering that rails, for instance, takes about 1/2 second to load it's libs,
we could be looking at __tens__ of seconds of startup delay for every ruby
script on a large system

I think he meant the files in the individual gem's
lib/ruby/gems/...../gemname/lib folder, not all the files in
lib/ruby/gems :)

martin
 
J

James Edward Gray II

I think he meant the files in the individual gem's
lib/ruby/gems/...../gemname/lib folder, not all the files in
lib/ruby/gems :)

But we still don't want to do that. Some libraries provide alternate
interfaces or features based on which file you require.

James Edward Gray II
 
A

Alex Young

yikes! i've got about 80 libs installed!
Not *all* the gems... just the named one :)

F'rinstance, from my machine:

require 'activerecord'

would load gems/activerecord-1.15-1/lib/active_record.rb, and

require 'actionpack'

would load gems/actionpack-1.13.1/lib/{action_controller.rb,
action_pack.rb, action_view.rb}

and so on. It's just one way around the disconnect between the gem's
name and the name of the file you need to require, which keeps catching
me off guard. Mainly because I'm lazy.
 
M

Martin DeMello

But we still don't want to do that. Some libraries provide alternate
interfaces or features based on which file you require.

Yep. Which is why what I want is an argument to gem that will list a
gem's requirable files.

martin
 
A

Alex Young

James said:
But we still don't want to do that. Some libraries provide alternate
interfaces or features based on which file you require.
Oh, I realise I'm not likely to get my wish - there's too much code
already out there that wouldn't work like I'm suggesting.
 
A

ara.t.howard

I think he meant the files in the individual gem's
lib/ruby/gems/...../gemname/lib folder, not all the files in
lib/ruby/gems :)

ayyyyy

need more coffee...



-a
 
E

Eric Hodel

Finally gotten around to changing my 'require_gem' code, and I've
noticed that for many gems, the name of the file to "require" is not
the same as the gem's name.

99.9% of the time you don't need require_gem.
Furthermore, there's no way to find out
what file I *do* need to require other than looking at the directory
structure of the gem. An option to gem that would list all requirable
files would be a nice addition.

You mean "gem contents"?

$ gem help contents
Usage: gem contents [options]

Options:
-v, --version VERSION Specify version of gem to contents
-l, --list List the files inside a Gem
-s, --spec-dir a,b,c Search for gems under specific
paths
-V, --verbose Be verbose when showing status

Common Options:
--source URL Use URL as the remote source
for gems
-p, --[no-]http-proxy Use HTTP proxy for remote
operations
-h, --help Get help on this command
--config-file FILE Use this config file instead of
default
--backtrace Show stack backtrace on errors
--debug Turn on Ruby debugging

Summary:
Display the contents of the installed gems
$ gem contents memcache-client
/usr/local/lib/ruby/gems/1.8/gems/memcache-client-1.3.0/History.txt
/usr/local/lib/ruby/gems/1.8/gems/memcache-client-1.3.0/LICENSE.txt
/usr/local/lib/ruby/gems/1.8/gems/memcache-client-1.3.0/Manifest.txt
/usr/local/lib/ruby/gems/1.8/gems/memcache-client-1.3.0/README.txt
/usr/local/lib/ruby/gems/1.8/gems/memcache-client-1.3.0/Rakefile
/usr/local/lib/ruby/gems/1.8/gems/memcache-client-1.3.0/lib/memcache.rb
/usr/local/lib/ruby/gems/1.8/gems/memcache-client-1.3.0/lib/
memcache_util.rb
/usr/local/lib/ruby/gems/1.8/gems/memcache-client-1.3.0/test/
test_mem_cache.rb
 
M

Martin DeMello

You mean "gem contents"?
$ gem contents memcache-client
/usr/local/lib/ruby/gems/1.8/gems/memcache-client-1.3.0/History.txt
/usr/local/lib/ruby/gems/1.8/gems/memcache-client-1.3.0/LICENSE.txt
/usr/local/lib/ruby/gems/1.8/gems/memcache-client-1.3.0/Manifest.txt
/usr/local/lib/ruby/gems/1.8/gems/memcache-client-1.3.0/README.txt
/usr/local/lib/ruby/gems/1.8/gems/memcache-client-1.3.0/Rakefile
/usr/local/lib/ruby/gems/1.8/gems/memcache-client-1.3.0/lib/memcache.rb
/usr/local/lib/ruby/gems/1.8/gems/memcache-client-1.3.0/lib/
memcache_util.rb
/usr/local/lib/ruby/gems/1.8/gems/memcache-client-1.3.0/test/
test_mem_cache.rb

No - that just spits out everything in the gem. What's needed is a
command that just lists those files in the directories that 'gem' adds
to $:

martin
 
E

Eric Hodel

No - that just spits out everything in the gem. What's needed is a
command that just lists those files in the directories that 'gem' adds
to $:

Have you filed a bug? I guarantee it won't get added without it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,238
Messages
2,571,192
Members
47,829
Latest member
wyattmoon

Latest Threads

Top