aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/schema_dumper.rb
diff options
context:
space:
mode:
authorTim Petricola <tim.petricola@gmail.com>2016-07-01 11:24:12 +0200
committerTim Petricola <tim.petricola@gmail.com>2016-08-17 10:09:34 +0200
commitdde3bdf214e7376cb2fccf0068da340efa06ec28 (patch)
treed7854016d24daf32ce36074a21854ecc89127388 /activerecord/lib/active_record/schema_dumper.rb
parent6eee67318483c64bd864dc845550f27d45fa984c (diff)
downloadrails-dde3bdf214e7376cb2fccf0068da340efa06ec28.tar.gz
rails-dde3bdf214e7376cb2fccf0068da340efa06ec28.tar.bz2
rails-dde3bdf214e7376cb2fccf0068da340efa06ec28.zip
Option not to line up column types and attributes in schema.rb
Diffstat (limited to 'activerecord/lib/active_record/schema_dumper.rb')
-rw-r--r--activerecord/lib/active_record/schema_dumper.rb48
1 files changed, 38 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/schema_dumper.rb b/activerecord/lib/active_record/schema_dumper.rb
index 01f788a424..be74922453 100644
--- a/activerecord/lib/active_record/schema_dumper.rb
+++ b/activerecord/lib/active_record/schema_dumper.rb
@@ -16,6 +16,22 @@ module ActiveRecord
cattr_accessor :ignore_tables
@@ignore_tables = []
+ ##
+ # :singleton-method:
+ # Define whether column arguments are lined up in dump.
+ # Acceptable values are true or false.
+ # This setting is only used if ActiveRecord::Base.schema_format == :ruby
+ cattr_accessor :standardized_argument_widths
+ @@standardized_argument_widths = true
+
+ ##
+ # :singleton-method:
+ # Define whether columns types are lined up in dump.
+ # Acceptable values are true or false.
+ # This setting is only used if ActiveRecord::Base.schema_format == :ruby
+ cattr_accessor :standardized_type_widths
+ @@standardized_type_widths = true
+
class << self
def dump(connection=ActiveRecord::Base.connection, stream=STDOUT, config = ActiveRecord::Base)
new(connection, generate_options(config)).dump(stream)
@@ -146,20 +162,32 @@ HEADER
keys = @connection.migration_keys
# figure out the lengths for each column based on above keys
- lengths = keys.map { |key|
- column_specs.map { |spec|
- spec[key] ? spec[key].length + 2 : 0
- }.max
- }
+ lengths = if standardized_argument_widths
+ keys.map { |key|
+ column_specs.map { |spec|
+ spec[key] ? spec[key].length + 2 : 0
+ }.max
+ }
+ else
+ [0] * keys.length
+ end
# the string we're going to sprintf our values against, with standardized column widths
- format_string = lengths.map { |len| "%-#{len}s" }
-
- # find the max length for the 'type' column, which is special
- type_length = column_specs.map { |column| column[:type].length }.max
+ format_string = if standardized_argument_widths
+ lengths.map { |len| "%-#{len}s" }
+ else
+ ["%s"] * keys.length
+ end
# add column type definition to our format string
- format_string.unshift " t.%-#{type_length}s "
+ if standardized_type_widths
+ # find the max length for the 'type' column, which is special
+ type_length = column_specs.map { |column| column[:type].length }.max
+
+ format_string.unshift " t.%-#{type_length}s "
+ else
+ format_string.unshift " t.%s "
+ end
format_string *= ""