LoginSignup
2
1

More than 5 years have passed since last update.

Railsでmigrate時にクラス図を自動生成する設定

Last updated at Posted at 2019-01-12

目的

  • ドキュメントとシステムが乖離する要因を消す。
  • 視覚的に把握する。
  • 共有の手間をなくす。

手順

  1. graphvizをインストールする
  2. gemを指定する
  3. タスクを定義する

1. graphvizをインストールする

# ディストリビューションに合わせて
yum install graphviz
 or
apt-get install graphviz

2. gemを指定する

Gemfile

group :development do
  gem 'yard'
end

3. タスクを定義する

Rakefile
require_relative 'config/application'

Rails.application.load_tasks

# migrateのタスクをフックする
Rake::Task['db:migrate'].enhance do
  if Rails.env.development?
    Rake::Task[:after_migrate].invoke
  end
end

# migrateの後のタスク
task :after_migrate do
  Rake::Task[:create_classd].invoke
end

task :create_classd do
  sh 'yard doc'
  sh 'yard graph --full -f bookshelf-classd.dot'
  sh 'dot -Tpng bookshelf-classd.dot -o bookshelf-classd.png'
end

実行する

rails db:migrate
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1