Skip to content

Commit

Permalink
Refactor index algorithm lookup so that it only builds the available …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
carlosantoniodasilva committed Mar 30, 2013
1 parent 07dfc0a commit 2d1eebf
Showing 1 changed file with 4 additions and 4 deletions.
Expand Up @@ -774,10 +774,10 @@ def add_index_options(table_name, column_name, options = {})
index_name = options[:name].to_s if options.key?(:name) index_name = options[:name].to_s if options.key?(:name)
max_index_length = options.fetch(:internal, false) ? index_name_length : allowed_index_name_length max_index_length = options.fetch(:internal, false) ? index_name_length : allowed_index_name_length


if index_algorithms.key?(options[:algorithm]) if options.key?(:algorithm)
algorithm = index_algorithms[options[:algorithm]] algorithm = index_algorithms.fetch(options[:algorithm]) {
elsif options[:algorithm].present? raise ArgumentError.new("Algorithm must be one of the following: #{index_algorithms.keys.map(&:inspect).join(', ')}")
raise ArgumentError.new("Algorithm must be one of the following: #{index_algorithms.keys.map(&:inspect).join(', ')}") }
end end


using = "USING #{options[:using]}" if options[:using].present? using = "USING #{options[:using]}" if options[:using].present?
Expand Down

0 comments on commit 2d1eebf

Please sign in to comment.