Paths for configured gems

I would like to get a list of the paths of configured gems.

A list of gem dependencies can be found by:

Rails.configuration.gems

…which returns a bunch of Rails::GemDependency but I can’t figure
out how to get a path to the root of the gem.

I can get the gem root from ENV[‘GEM_HOME’] but I can only get the
name of the gem and the version requirement from the GemDependency.
The version requirement isn’t necessarily the same version that is
being loaded, since it could be a >= requirement.
Any suggestions?

For what it’s worth, I’m trying to hack something that will auto-load
rake tasks from configured gems.

Thanks!

You received this message because you are subscribed to the Google
Groups “Ruby on Rails: Talk” group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.

On Dec 20, 6:28 pm, Josh [email protected] wrote:

I would like to get a list of the paths of configured gems.

A list of gem dependencies can be found by:

Rails.configuration.gems

…which returns a bunch of Rails::GemDependency but I can’t figure
out how to get a path to the root of the gem.

If you’ve got a Rails::GemDependency object, you can grab the
specification and get the path you’re looking for:

@gem_dep.specification.full_gem_path

This will work on both vendor and system gems.

For what it’s worth, I’m trying to hack something that will auto-load
rake tasks from configured gems.

Note that this is a consistent issue with the 2.x gem loader; there
are a number of tickets along the same lines:

https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/59
https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2728

The ultimate problem is that Rake doesn’t (by default) actually load
the Rails environment (tasks can, by specifying a dependency on
the :environment task). So the gems aren’t “configured” by default.
The same problem pops up when trying to load generators from vendor/
gems.

–Matt J.

You received this message because you are subscribed to the Google
Groups “Ruby on Rails: Talk” group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.