How can we automate generation of AASM diagrams, so our documentation will always be up to date with our code?
This gist does two main things that the aasm-diagram repo doesn't do on its own as of today (May 2025):
- Finds all of the uses of aasm in our Rails models itself, so we don't have to list them out
- Updates a markdown file that embeds each of the AASM diagrams
When should we generate this?
rails-erd
uses database migrations as the moment to auto-generate an ERD diagram, which makes a ton of sense!
We didn't find a great hook to use for aasm diagrams, but we considered a few options:
- In a pre-commit hook, like via lint-staged, anytime a file in
models/
is changed? - In a database migration, just because it's frequent on our application? But AASM can change in the model without a DB change so it's not semantically correct
- In CI?
Manually seems okay for us, for now.
Who did this work?
I contributed a bit of this, but most of this was done by a coworker who asked me to share this out.