Class: ActiveRecord::Base

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

Class Method Summary collapse

Class Method Details

.em_postgresql_connection(config) ⇒ Object

Establishes a connection to the database that’s used by all Active Record objects



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/active_record/connection_adapters/em_postgresql_adapter.rb', line 97

def self.em_postgresql_connection(config) # :nodoc:
  config = config.symbolize_keys
  host     = config[:host]
  port     = config[:port] || 5432
  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

  # The postgres drivers don't allow the creation of an unconnected PGconn object,
  # so just pass a nil connection object for the time being.
  ConnectionAdapters::EmPostgreSQLAdapter.new(nil, logger, [host, port], [database, username, password], config)
end