aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-03-30 15:26:45 -0300
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-03-30 15:26:46 -0300
commit2d1eebfd88861d9eab541041a25f3f57d3cf90c7 (patch)
tree3b0e9412d62304c9dd350670b15b6bc5e35d4a90 /activerecord
parent07dfc0a05f074101185e90f1bc2559a251233bf9 (diff)
downloadrails-2d1eebfd88861d9eab541041a25f3f57d3cf90c7.tar.gz
rails-2d1eebfd88861d9eab541041a25f3f57d3cf90c7.tar.bz2
rails-2d1eebfd88861d9eab541041a25f3f57d3cf90c7.zip
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.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb8
1 files changed, 4 insertions, 4 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 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?