ModelDiscovery Gem Version

ModelDiscovery is a simple yet flexible and fast solution to model discovery problem in Ruby on Rails applications. Detecting applications model in a Rails application is a bit hard because of autoload convention, specially when you use set of gems which add their own models to your application.

ModelDiscovery provides a solution to this problem without loading models in runtime. If you're familiar with Django framework, you can think ok ModelDiscovery as something like ContentType application in Django.

Installation

Add this line to your application's Gemfile:

gem 'model_discovery'

And then execute:

$ bundle

Or install it yourself as:

$ gem install model_discovery

Then add this line to your db/seeds.rb file:

ModelDiscovery::Engine.load_seed

Usage

ModelDiscovery will add a model to your application which will contains all the models class name. So you can use active record's query to fetch model names like:

# Fetch all models class names
models = ApplicationModels.all
# => ["User", "Group", "SomeGem::ModelExample"]

# Access to actual class of a model
model_class = models[0].constantize
# => "User"

# It's like User.all
model_class.all

It's simple isn't it ?

Bugs

If you find any bug or have any issue using this gem I'll be happy to know. Please file an issue in Issue Tracker

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request