Module: ActiveRecord::ConnectionHandling

Defined in:
lib/active_record/connection_adapters/pgcrypto_adapter/rails_4.rb

Instance Method Summary collapse

Instance Method Details

#pgcrypto_connection(config, *args, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/active_record/connection_adapters/pgcrypto_adapter/rails_4.rb', line 4

def pgcrypto_connection(config, *args, &block)
  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.
  PGCrypto::Adapter.new(nil, logger, conn_params, config)
end