Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/connection_adapters/em_mysqlplus_adapter.rb

Class Method Summary collapse

Class Method Details

.em_mysqlplus_connection(config) ⇒ Object

:nodoc:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/active_record/connection_adapters/em_mysqlplus_adapter.rb', line 39

def self.em_mysqlplus_connection(config) # :nodoc:
  config = config.symbolize_keys
  host     = config[:host]
  port     = config[:port]
  username = config[:username].to_s if config[:username]
  password = config[:password].to_s if config[:password]

  if config.has_key?(:database)
    database = config[:database]
  else
    raise ArgumentError, "No database specified. Missing argument: database."
  end

  if EM.reactor_running?
    ConnectionAdapters::EmMysqlAdapter.new(nil, logger, [host, port], [database, username, password], config)
  else
    mysql = Mysql.init
    if config[:sslca] || config[:sslkey]
      mysql.ssl_set(config[:sslkey], config[:sslcert], config[:sslca], config[:sslcapath], config[:sslcipher])
    end

    default_flags = Mysql.const_defined?(:CLIENT_MULTI_RESULTS) ? Mysql::CLIENT_MULTI_RESULTS : 0
    options = [host, username, password, database, port, nil, default_flags]
    ConnectionAdapters::MysqlAdapter.new(mysql, logger, options, config)
  end
end