Skip to content

Instantly share code, notes, and snippets.

@takesato
Created December 7, 2012 05:01
Show Gist options
  • Select an option

  • Save takesato/4230916 to your computer and use it in GitHub Desktop.

Select an option

Save takesato/4230916 to your computer and use it in GitHub Desktop.
DB情報からtextileフォーマットのドキュメントを出力する
# -*- coding: utf-8 -*-
namespace :ar do
namespace :schema do
task :export do
output_dir = File.join(Padrino.root, 'documents')
FileUtils.mkdir_p(output_dir)
tables = ActiveRecord::Base.connection.execute("show tables").to_a.map{|t| t[0]}.reject{ |t| t == 'schema_migrations' }
tables.each do |table|
columns = ActiveRecord::Base.connection.execute("show full columns from #{table}").to_a
rows = [
"%(fc-r)このページは自動生成されたページです。%",
nil,
"h1. #{table}",
nil,
'|_.Field|_.Type|_.Null|_.Key|_.Default|_.Extra|_.Comment|'
]
columns.each do |c|
rows << c.values_at(0,1,3,4,5,6,8).push(nil).unshift(nil).join('|')
end
open(File.join(output_dir, "Dev_WebAPI_schema_#{table}.textile"), 'w') {|f| f.print rows.join("\n") }
end
end
end
desc "export schema definition"
task schema: ["schema:export"]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment