[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

gems and require

Martin DeMello

3/13/2007 12:41:00 PM

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

11 Answers

Alex Young

3/13/2007 6:52:00 PM

0

Martin DeMello wrote:
> 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...

--
Alex

Ara.T.Howard

3/13/2007 7:16:00 PM

0

Martin DeMello

3/13/2007 7:20:00 PM

0

On 3/14/07, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
> On Wed, 14 Mar 2007, Alex Young wrote:
>
> > 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

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

James Gray

3/13/2007 7:24:00 PM

0

On Mar 13, 2007, at 2:19 PM, Martin DeMello wrote:

> On 3/14/07, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
>> On Wed, 14 Mar 2007, Alex Young wrote:
>>
>> > 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
>
> 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

Alex Young

3/13/2007 7:26:00 PM

0

ara.t.howard@noaa.gov wrote:
> On Wed, 14 Mar 2007, Alex Young wrote:
>
>> Martin DeMello wrote:
>>> 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...
>
> 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.

--
Alex

Martin DeMello

3/13/2007 7:28:00 PM

0

On 3/14/07, James Edward Gray II <james@grayproductions.net> wrote:
>
> 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

Alex Young

3/13/2007 7:38:00 PM

0

James Edward Gray II wrote:
> On Mar 13, 2007, at 2:19 PM, Martin DeMello wrote:
>
>> On 3/14/07, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
>>> On Wed, 14 Mar 2007, Alex Young wrote:
>>>
>>> > 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
>>
>> 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.
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.

--
Alex

Ara.T.Howard

3/13/2007 7:51:00 PM

0

Eric Hodel

3/18/2007 1:21:00 AM

0

On Mar 13, 2007, at 05:41, Martin DeMello wrote:
> 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 [URL] 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


Martin DeMello

3/18/2007 9:16:00 AM

0

On 3/18/07, Eric Hodel <drbrain@segment7.net> wrote:
> > 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 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