No commit activity in last 3 years
No release in over 3 years
Detailed reports for Active Record Associations
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.9
~> 10.5
~> 3.4
~> 1.3

Runtime

~> 0.7
 Project Readme

Association Reporter

Association Reporter wraps the ActiveRecord reflection API, and allows you to describe associations on ActiveRecord models. The description includes a detailed report of the assumptions ActiveRecord is making about your models and associations. It will tell you what it's trying to guess, and when those guesses appear to be wrong!

Install

Association Reporter can be installed as a gem:

gem install association-reporter

Usage

To use AssociationReporter, extend your model with AssociationReporter::Reporter.

require "association-reporter/reporter"

class Article
  extend AssociationReporter::Reporter
  has_many :taggings
  has_many :hashtags, through: :taggings
  has_many :comments
  belongs_to :author, class_name: "User"
end

Load your models up in an IRB session, or simply write a runner file, and try out the newly added ::describe method.

Article.describe(:hashtags)

Colorized output will tell you which guesses succeeded and which guesses failed:

Example output of describe command

In the example above, it appears our has_many :through needs us to specify a source, because it couldn't guess the source name on the Tagging model.

Demo

Demo of a Dev Bootcamp AR challenge

Additional Information

The rake play task will boot a REPL with a few models loaded from spec/factories so you can try this out.

Templates for the output are in templates, they're just ERB files.

The watch command in the demo supports both color and emoji. You'll find the port by @whit537 here.

Caveats

This is brand new and probably full of bugs, inaccuracies, and scary things that go bump in the night. PRs are warmly welcomed!