Skip to content

Instantly share code, notes, and snippets.

@andynu
Created February 1, 2024 15:40
Show Gist options
  • Save andynu/29e55ee95d44a8b085aef5508009e0b3 to your computer and use it in GitHub Desktop.
Save andynu/29e55ee95d44a8b085aef5508009e0b3 to your computer and use it in GitHub Desktop.
Run annotate and erd automatically when you db:migrate (rails)
namespace :doc do
desc 'generate yardoc docs in doc/app/index.html'
task :app do
`yard doc -o doc/app`
puts "see doc/app/index.html"
end
desc 'annotate models'
task :annotate do
run = ->(cmd){
print "Running `#{cmd}` ";
`#{cmd} 2>&1`
puts $?.success? ? Rainbow('[OK]').green : Rainbow('[FAILED]').red
}
if Rails.env.development? && ENV['USER']!='jane'
run.call('annotate --models --position bottom')
run.call('annotate --routes --position bottom')
end
end
end
namespace :db do
task :migrate do
# This appends, it does not redefine.
# Always run doc:annotate after db:migrate
Rake::Task['doc:annotate'].invoke
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment