aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorMarcel Molina <marcel@vernix.org>2006-04-26 06:15:51 +0000
committerMarcel Molina <marcel@vernix.org>2006-04-26 06:15:51 +0000
commitf274a89f8b23cedf020a1d59a8fe0438d6bc9be9 (patch)
tree21cef2c22632ee0f882f32e94134a4bcc791ad26 /activerecord/lib
parent5d61d2336cceebf388369f22fa4cfbc07983bde5 (diff)
downloadrails-f274a89f8b23cedf020a1d59a8fe0438d6bc9be9.tar.gz
rails-f274a89f8b23cedf020a1d59a8fe0438d6bc9be9.tar.bz2
rails-f274a89f8b23cedf020a1d59a8fe0438d6bc9be9.zip
Prettify output of schema_dumper by making things line up. Closes #4241 [Caio Chassot <caio@v2studio.com>]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4273 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/schema_dumper.rb22
1 files changed, 17 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb
index 06fdd3f813..718669a1b7 100644
--- a/activerecord/lib/active_record/schema_dumper.rb
+++ b/activerecord/lib/active_record/schema_dumper.rb
@@ -82,13 +82,25 @@ HEADER
tbl.print ", :force => true"
tbl.puts " do |t|"
- columns.each do |column|
+ column_specs = columns.map do |column|
raise StandardError, "Unknown type '#{column.sql_type}' for column '#{column.name}'" if @types[column.type].nil?
next if column.name == pk
- tbl.print " t.column #{column.name.inspect}, #{column.type.inspect}"
- tbl.print ", :limit => #{column.limit.inspect}" if column.limit != @types[column.type][:limit]
- tbl.print ", :default => #{column.default.inspect}" if !column.default.nil?
- tbl.print ", :null => false" if !column.null
+ spec = {}
+ spec[:name] = column.name.inspect
+ spec[:type] = column.type.inspect
+ spec[:limit] = column.limit.inspect if column.limit != @types[column.type][:limit]
+ spec[:default] = column.default.inspect if !column.default.nil?
+ spec[:null] = 'false' if !column.null
+ (spec.keys - [:name, :type]).each{ |k| spec[k].insert(0, "#{k.inspect} => ")}
+ spec
+ end.compact
+ keys = [:name, :type, :limit, :default, :null] & column_specs.map{ |spec| spec.keys }.inject([]){ |a,b| a | b }
+ lengths = keys.map{ |key| column_specs.map{ |spec| spec[key] ? spec[key].length + 2 : 0 }.max }
+ format_string = lengths.map{ |len| "%-#{len}s" }.join("")
+ column_specs.each do |colspec|
+ values = keys.zip(lengths).map{ |key, len| colspec.key?(key) ? colspec[key] + ", " : " " * len }
+ tbl.print " t.column "
+ tbl.print((format_string % values).gsub(/,\s*$/, ''))
tbl.puts
end