[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

RubyGem, find path of installed gem through ruby.

warhero

1/16/2009 12:19:00 AM

Hey All,

First, where is there some api docs for rubygem related methods and
classes?

Second, I have a gem that bundles some required files for the gem. How
do I find the path of the installed gem, so that I can load the bundled
files. For example, I have one executable file, that needs to load some
files that were included (in the lib) dir. But I do I know what the path
of my gem is?

Thanks all
--
Posted via http://www.ruby-....

10 Answers

Tom Cloyd

1/16/2009 3:21:00 PM

0

Aaron Smith wrote:
> Hey All,
>
> First, where is there some api docs for rubygem related methods and
> classes?
>
>
/usr/lib/ruby/gems/1.8/doc/rubygems-1.3.1/rdoc (Linux - Kubuntu)

> Second, I have a gem that bundles some required files for the gem. How
> do I find the path of the installed gem, so that I can load the bundled
> files. For example, I have one executable file, that needs to load some
> files that were included (in the lib) dir. But I do I know what the path
> of my gem is?
>
> Thanks all
>
~$ gen env

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


warhero

1/16/2009 5:07:00 PM

0

Hey Tom, Thanks, that information is definitely what I'm looking for.
How would I get that info from within a ruby script. Specifically the
"GEM PATH" is what I would need. Is there a method to get that?

thanks.
--
Posted via http://www.ruby-....

warhero

1/16/2009 5:08:00 PM

0

or rather, the "INSTALLATION DIRECTORY."
--
Posted via http://www.ruby-....

Tom Cloyd

1/16/2009 5:40:00 PM

0

Aaron Smith wrote:

Hey Tom, Thanks, that information is definitely what I'm looking for.
How would I get that info from within a ruby script. Specifically the
"GEM PATH" is what I would need. Is there a method to get that?

or rather, the "INSTALLATION DIRECTORY."

===========================

If you had any idea how paltry my knowledge of Ruby really is you would
ask me such questions! But...I got us this far, so...

I think I'd try a system call to "gem env", and put the output in a
string, then locate "INSTALLATION DIRECTORY:" with StringScanner, and
take everything after that, up to the EOL as the path you're after.
Easy, actually.

Only I'm momentarily stumped as to how to make the system call AND
capture the output. Thomas (Pickaxe 2) says it can be done using
backtics. I tried it in irb and got nothing. Still trying to figure it
out. It'd be a good trick to know.

t.

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Tom Cloyd

1/16/2009 5:47:00 PM

0

Tom Cloyd wrote:
> Aaron Smith wrote:
>
> Hey Tom, Thanks, that information is definitely what I'm looking for.
> How would I get that info from within a ruby script. Specifically the
> "GEM PATH" is what I would need. Is there a method to get that?
>
> or rather, the "INSTALLATION DIRECTORY."
>
> ===========================
>
> If you had any idea how paltry my knowledge of Ruby really is you
> would ask me such questions! But...I got us this far, so...
>
> I think I'd try a system call to "gem env", and put the output in a
> string, then locate "INSTALLATION DIRECTORY:" with StringScanner, and
> take everything after that, up to the EOL as the path you're after.
> Easy, actually.
>
> Only I'm momentarily stumped as to how to make the system call AND
> capture the output. Thomas (Pickaxe 2) says it can be done using
> backtics. I tried it in irb and got nothing. Still trying to figure it
> out. It'd be a good trick to know.
>
> t.
>
Bummer. In order to preserve my reputation, I managed to get irb a bit
hung up, so of course it didn't perform `gem env` as I expected.
Ungummed, as it were, it works fine. E.g.:

irb(main):001:0> a=`gem env`
=> "RubyGems Environment:\n - RUBYGEMS VERSION: 1.3.1\n - RUBY
VERSION: 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]\n - INSTALLATION
DIRECTORY: /usr/lib/ruby/gems/1.8\n - RUBY EXECUTABLE:
/usr/bin/ruby1.8\n - EXECUTABLE DIRECTORY: /usr/bin\n - RUBYGEMS
PLATFORMS:\n - ruby\n - x86-linux\n - GEM PATHS:\n -
/usr/lib/ruby/gems/1.8\n - /home/tomc/.gem/ruby/1.8\n - GEM
CONFIGURATION:\n - :update_sources=> true\n - :verbose =>
true\n - :benchmark => false\n - :backtrace => false\n -
:bulk_threshold => 1000\n - REMOTE SOURCES:\n -
http://gems.ruby...\n"
irb(main):002:0>

I leave it to you to get the code to have StringScanner find and return
the path. Somehow I keep thinking regular expressions might be helpful
here, but I dare not there. I think I hear the ice cracking already.

t.

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Tom Cloyd

1/16/2009 5:51:00 PM

0

Tom Cloyd wrote:
> Tom Cloyd wrote:
>> Aaron Smith wrote:
>>
>> Hey Tom, Thanks, that information is definitely what I'm looking for.
>> How would I get that info from within a ruby script. Specifically the
>> "GEM PATH" is what I would need. Is there a method to get that?
>>
>> or rather, the "INSTALLATION DIRECTORY."
>>
>> ===========================
>>
>> If you had any idea how paltry my knowledge of Ruby really is you
>> would ask me such questions! But...I got us this far, so...
>>
>> I think I'd try a system call to "gem env", and put the output in a
>> string, then locate "INSTALLATION DIRECTORY:" with StringScanner, and
>> take everything after that, up to the EOL as the path you're after.
>> Easy, actually.
>>
>> Only I'm momentarily stumped as to how to make the system call AND
>> capture the output. Thomas (Pickaxe 2) says it can be done using
>> backtics. I tried it in irb and got nothing. Still trying to figure
>> it out. It'd be a good trick to know.
>>
>> t.
>>
> Bummer. In order to preserve my reputation, I managed to get irb a bit
> hung up, so of course it didn't perform `gem env` as I expected.
> Ungummed, as it were, it works fine. E.g.:
>
> irb(main):001:0> a=`gem env`
> => "RubyGems Environment:\n - RUBYGEMS VERSION: 1.3.1\n - RUBY
> VERSION: 1.8.7 (2008-08-11 patchlevel 72) [i486-linux]\n -
> INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8\n - RUBY EXECUTABLE:
> /usr/bin/ruby1.8\n - EXECUTABLE DIRECTORY: /usr/bin\n - RUBYGEMS
> PLATFORMS:\n - ruby\n - x86-linux\n - GEM PATHS:\n -
> /usr/lib/ruby/gems/1.8\n - /home/tomc/.gem/ruby/1.8\n - GEM
> CONFIGURATION:\n - :update_sources=> true\n - :verbose =>
> true\n - :benchmark => false\n - :backtrace => false\n -
> :bulk_threshold => 1000\n - REMOTE SOURCES:\n -
> http://gems.ruby...\n"
> irb(main):002:0>
>
> I leave it to you to get the code to have StringScanner find and
> return the path. Somehow I keep thinking regular expressions might be
> helpful here, but I dare not there. I think I hear the ice cracking
> already.
>
> t.
>
Also, you might find something useful here:
http://tech.natemurray.com/2007/03/ruby-shell-com...

t.

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


warhero

1/16/2009 5:58:00 PM

0

there should be something that's part of the rubygem api, so I don't
have to call system commands. I see where you're going with the regex on
the gem env command, but there has to be a better way.
--
Posted via http://www.ruby-....

warhero

1/16/2009 6:11:00 PM

0

found it. try this:

$ irb
$ require "rubygems"
$ puts Gem.default_path

-A
--
Posted via http://www.ruby-....

Tom Cloyd

1/16/2009 6:21:00 PM

0

Aaron Smith wrote:
> found it. try this:
>
> $ irb
> $ require "rubygems"
> $ puts Gem.default_path
>
> -A
>
Super - easier. I do get 2 paths, though -
/home/tomc/.gem/ruby/1.8
/usr/lib/ruby/gems/1.8

So you'll still have to locate and extract, but that's nothing (and
maybe your install is set up differently...?)

Good luck.

t.

--

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Tom Cloyd, MS MA, LMHC - Private practice Psychotherapist
Bellingham, Washington, U.S.A: (360) 920-1226
<< tc@tomcloyd.com >> (email)
<< TomCloyd.com >> (website)
<< sleightmind.wordpress.com >> (mental health weblog)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Andrew Goodnough

1/16/2009 7:23:00 PM

0

Tom Cloyd wrote:
> Aaron Smith wrote:
>> found it. try this:
>>
>> $ irb
>> $ require "rubygems"
>> $ puts Gem.default_path
>>
>> -A
>>
> Super - easier. I do get 2 paths, though -
> /home/tomc/.gem/ruby/1.8
> /usr/lib/ruby/gems/1.8
>
> So you'll still have to locate and extract, but that's nothing (and
> maybe your install is set up differently...?)
>

Thanks for this thread - exactly what I needed as well. I think code to
find the particular library should try prepending the paths returned
from Gem.default_path in order they are returned, as a gem installed in
a user directory should trump a system gem.

Andy
--
Posted via http://www.ruby-....