diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-12-03 07:08:30 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-12-03 07:08:30 +0900 |
commit | 33a3f7123bc4cc49b99b01a40bbfd463b2e73f76 (patch) | |
tree | 254c6b0f4b0a5e17831763c9b77176e1c7753ceb /activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb | |
parent | 3040446cece8e7a6d9e29219e636e13f180a1e03 (diff) | |
download | rails-33a3f7123bc4cc49b99b01a40bbfd463b2e73f76.tar.gz rails-33a3f7123bc4cc49b99b01a40bbfd463b2e73f76.tar.bz2 rails-33a3f7123bc4cc49b99b01a40bbfd463b2e73f76.zip |
Extract duplicated index column options normalization as `options_for_index_columns`
And placed `add_options_for_index_columns` in `schema_statements.rb`
consistently to ease to find related code.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb index efc934c34c..4f58b0242c 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -1197,17 +1197,18 @@ module ActiveRecord end def add_index_sort_order(quoted_columns, **options) - if order = options[:order] - case order - when Hash - order = order.symbolize_keys - quoted_columns.each { |name, column| column << " #{order[name].upcase}" if order[name].present? } - else - quoted_columns.each { |name, column| column << " #{order.upcase}" if order.present? } - end + orders = options_for_index_columns(options[:order]) + quoted_columns.each do |name, column| + column << " #{orders[name].upcase}" if orders[name].present? end + end - quoted_columns + def options_for_index_columns(options) + if options.is_a?(Hash) + options.symbolize_keys + else + Hash.new { |hash, column| hash[column] = options } + end end # Overridden by the MySQL adapter for supporting index lengths and by |