Is there any way to tell which gems and plugins are loaded at runtime for a Rails process?
Asked Answered
A

3

30

Is there any command either in debugger or ruby-debug to get a list of all gems and/or plugins loaded in memory for a Rails process? I understand only the 'require' gems are loaded but I would like to quickly see what got loaded during runtime.

Alveolate answered 30/4, 2010 at 22:13 Comment(0)
O
41

This should get you everything loaded through rubygems:

Gem.loaded_specs.keys

I don't know of a universal way to see which rails plugins are loaded, you can look at the source for Rails::Initializer (pre 3.0) & figure out what your version of rails is doing. Hopefully you know which plugins should be loading & can confirm that from the console when debugging.

Ouphe answered 1/5, 2010 at 16:2 Comment(1)
I think @sreid has an important point in his answer below, if I'm understanding what's going on correctly. The number of gems on the the load path is not necessarily equal to the number of gems loaded into memory. For example, if particular groups are excluded from in a Bundler.require, won't Gem.loaded_specs still show them?Cutlass
G
27

With versions:

Gem.loaded_specs.values.map {|x| "#{x.name} #{x.version}"}
Gilemette answered 11/5, 2011 at 9:23 Comment(0)
S
3

I think the above answers using Gem.loaded_specs.keys show the gems on the "load path".

However, you originally asked about gems loaded into memory, and this answer may be more helpful.

Scipio answered 6/4, 2012 at 18:41 Comment(1)
No, the other answers correctly list only required gems. I have tested this with ruby 2.3. But +1 for your answer because $LOADED_FEATURES is rather useful too.Aerograph

© 2022 - 2024 — McMap. All rights reserved.