Module: ActiveRecord::ConnectionHandling

Defined in:
lib/active_record/connection_adapters/postgis_adapter/rails4/create_connection.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#postgis_connection(config_) ⇒ Object

Based on the default postgresql_connection definition from ActiveRecord.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/active_record/connection_adapters/postgis_adapter/rails4/create_connection.rb', line 9

def postgis_connection(config_)
  # FULL REPLACEMENT because we need to create a different class.
  conn_params_ = config_.symbolize_keys

  conn_params_.delete_if { |_, v_| v_.nil? }

  # Map ActiveRecords param names to PGs.
  conn_params_[:user] = conn_params_.delete(:username) if conn_params_[:username]
  conn_params_[:dbname] = conn_params_.delete(:database) if conn_params_[:database]

  # Forward only valid config params to PGconn.connect.
  conn_params_.keep_if { |k_, _| VALID_CONN_PARAMS.include?(k_) }

  # The postgres drivers don't allow the creation of an unconnected PGconn object,
  # so just pass a nil connection object for the time being.
  ::ActiveRecord::ConnectionAdapters::PostGISAdapter::MainAdapter.new(nil, logger, conn_params_, config_)
end