How to get a file contained in a gem "lib" directory?

Hi, I've build a gem "mylib" which contains a file called "myfile.xml" under
"lib/mylib" dir. Let's imagine that depending on the environment it is stored
(after installed) in:

  /usr/local/lib/ruby1.9/gems/1.9/gems/mylib-1.0.1/lib/mylib/myfile.xml

But of course there could be different versions of the gem:

  /usr/local/lib/ruby1.9/gems/1.9/gems/mylib-1.0.0/lib/mylib/myfile.xml
  /usr/local/lib/ruby1.9/gems/1.9/gems/mylib-1.0.1/lib/mylib/myfile.xml

Then I write a program which does:

  require "mylib"

so the latest version (1.0.1) is loaded.

How would I get "myfile.xml" for the loaded "mylib" gem version? I'm looking
for a Gem class method like "Gem.bin_path(gemname)" but I cannot find it.

Thanks a lot.

···

--
Iñaki Baz Castillo <ibc@aliax.net>

Found it:
  Gem.required_location(gemname,"")

···

El Lunes, 21 de Diciembre de 2009, Iñaki Baz Castillo escribió:

Hi, I've build a gem "mylib" which contains a file called "myfile.xml"
under "lib/mylib" dir. Let's imagine that depending on the environment it
is stored (after installed) in:

  /usr/local/lib/ruby1.9/gems/1.9/gems/mylib-1.0.1/lib/mylib/myfile.xml

But of course there could be different versions of the gem:

  /usr/local/lib/ruby1.9/gems/1.9/gems/mylib-1.0.0/lib/mylib/myfile.xml
  /usr/local/lib/ruby1.9/gems/1.9/gems/mylib-1.0.1/lib/mylib/myfile.xml

Then I write a program which does:

  require "mylib"

so the latest version (1.0.1) is loaded.

How would I get "myfile.xml" for the loaded "mylib" gem version? I'm
looking for a Gem class method like "Gem.bin_path(gemname)" but I cannot
find it.

--
Iñaki Baz Castillo <ibc@aliax.net>

Iñaki Baz Castillo wrote:

Hi, I've build a gem "mylib" which contains a file called "myfile.xml"
under
"lib/mylib" dir. Let's imagine that depending on the environment it is
stored
(after installed) in:

  /usr/local/lib/ruby1.9/gems/1.9/gems/mylib-1.0.1/lib/mylib/myfile.xml

[...]

How would I get "myfile.xml" for the loaded "mylib" gem version?

You can put a method to return it in your mylib.rb:

def self.get_xml_pathname
  File.join(File.dirname(__FILE__), 'mylib.xml')
end

···

--
Posted via http://www.ruby-forum.com/\.