From 2d1eebfd88861d9eab541041a25f3f57d3cf90c7 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Sat, 30 Mar 2013 15:26:45 -0300 Subject: Refactor index algorithm lookup so that it only builds the available options once This way the available options are only built for actually fetching the algorithm in case the option is given. The options are going to be necessary a second time only in case the option is given but does not exist, which is supposed to be due to a typo or something like that, so no problem. --- .../connection_adapters/abstract/schema_statements.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb') 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 c9eb9ee2f7..9c0c4e3ef0 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb @@ -774,10 +774,10 @@ module ActiveRecord index_name = options[:name].to_s if options.key?(:name) max_index_length = options.fetch(:internal, false) ? index_name_length : allowed_index_name_length - if index_algorithms.key?(options[:algorithm]) - algorithm = index_algorithms[options[:algorithm]] - elsif options[:algorithm].present? - raise ArgumentError.new("Algorithm must be one of the following: #{index_algorithms.keys.map(&:inspect).join(', ')}") + if options.key?(:algorithm) + algorithm = index_algorithms.fetch(options[:algorithm]) { + raise ArgumentError.new("Algorithm must be one of the following: #{index_algorithms.keys.map(&:inspect).join(', ')}") + } end using = "USING #{options[:using]}" if options[:using].present? -- cgit v1.2.3