module Mysql2xxxx class Config attr_reader :options def initialize(options = {}) @options = options.symbolize_keys end def user options[:user] || active_record_config.try(:[], :username) end def password options[:password] || active_record_config.try(:[], :password) end def host options[:host] || active_record_config.try(:[], :host) end def port options[:port] || active_record_config.try(:[], :port) end def socket options[:socket] || active_record_config.try(:[], :socket) end def database options[:database] || active_record_connection.try(:current_database) end def execute options[:execute] end # Whether to write \N instead of a blank string for NULL. This is helpful for mysqlimport. # # Only applies to CSV def slash_n options.fetch :slash_n, false end private def active_record_connection if defined?(::ActiveRecord) ::ActiveRecord::Base.connection end rescue # oh well end def active_record_config if active_record_connection active_record_connection.instance_variable_get :@config end end end end