0

I want to find all models in all namespaces.

Ideas I've considered:

  • Object.constants is not working a good starting point because it does not find my namespaced modules. So this answer isn't working for me.

  • ObjectSpace is a possibility but I'd rather not use it unless necessary, since it seems less portable across Ruby implementations. (See also: ObjectSpace is disabled by default in JRuby.)

Community
  • 1
  • 1
David J.
  • 31,569
  • 22
  • 122
  • 174

1 Answers1

0

Object.constants only shows loaded constants. So I needed to do this first:

Dir["#{Rails.root}/app/models/**/*.rb"].each { |path| require path }
David J.
  • 31,569
  • 22
  • 122
  • 174