# Paths for configured gems

**URL:** <https://www.ruby-forum.com/t/paths-for-configured-gems/180516>\
**Category:** Rails\
**Created:** [December 21, 2009, 12:29am UTC](https://www.ruby-forum.com/t/paths-for-configured-gems/180516 "2009-12-21T00:29:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@joshs](https://www.ruby-forum.com/u/joshs)\
**Post date:** [December 21, 2009, 12:29am UTC](https://www.ruby-forum.com/t/paths-for-configured-gems/180516/1 "2009-12-21T00:29:57Z")

</div>

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 removed\_email\_address@domain.invalid.  
To unsubscribe from this group, send email to  
removed\_email\_address@domain.invalid.  
For more options, visit this group at  
[http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

---

<div class="post-metadata">

**Author:** ![joshs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e5b9ba/32.png) [@joshs](https://www.ruby-forum.com/u/joshs)\
**Post date:** [December 21, 2009, 5:48pm UTC](https://www.ruby-forum.com/t/paths-for-configured-gems/180516/2 "2009-12-21T17:48:19Z")

</div>

On Dec 20, 6:28 pm, Josh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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/59)  
[https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2728](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 removed\_email\_address@domain.invalid.  
To unsubscribe from this group, send email to  
removed\_email\_address@domain.invalid.  
For more options, visit this group at  
[http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).
