diff --git a/lib/active_record/connection_adapters/percona_adapter.rb b/lib/active_record/connection_adapters/percona_adapter.rb index 74eef3b6..5f31bac1 100644 --- a/lib/active_record/connection_adapters/percona_adapter.rb +++ b/lib/active_record/connection_adapters/percona_adapter.rb @@ -14,12 +14,7 @@ def percona_connection(config) config[:username] = 'root' end adapter = config[:original_adapter] - connection = if Departure::SUPPORTED_ADAPTERS.include?(adapter) - send("#{adapter}_connection", config) - else - raise ArgumentError, "Unsupported adater #{adapter}. Supported Departure " \ - "adapters are #{Departure::SUPPORTED_ADAPTERS.inspect}" - end + connection = send(Departure.connection_method(adapter), config) connection_details = Departure::ConnectionDetails.new(config) verbose = ActiveRecord::Migration.verbose @@ -28,19 +23,12 @@ def percona_connection(config) ] percona_logger = Departure::LoggerFactory.build(sanitizers: sanitizers, verbose: verbose) cli_generator = Departure::CliGenerator.new(connection_details) - - runner = Departure::Runner.new( - percona_logger, - cli_generator, - connection - ) - - connection_options = { mysql_adapter: connection } + runner = Departure::Runner.new(percona_logger, cli_generator, connection) ConnectionAdapters::DepartureAdapter.new( runner, logger, - connection_options, + { mysql_adapter: connection }, config ) end diff --git a/lib/departure.rb b/lib/departure.rb index 9f08bb66..019af156 100644 --- a/lib/departure.rb +++ b/lib/departure.rb @@ -32,6 +32,18 @@ module Departure class << self attr_accessor :configuration + + def connection_method(adapter) + return "#{adapter}_connection" if Departure::SUPPORTED_ADAPTERS.include?(adapter) + + if adapter.blank? + raise ArgumentError, 'You must supply the original_adapter when connecting ' \ + "using the percona adapter. Supported adapters: #{SUPPORTED_ADAPTERS}" + end + + raise ArgumentError, "Unsupported adater #{adapter}. Supported Departure " \ + "adapters are #{Departure::SUPPORTED_ADAPTERS.inspect}" + end end def self.configure