Sha256: 9463e34de8b563c8aad7d8898d80659996300a9737a33199bcc822b63ed69485

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

require 'active_record/connection_adapters/postgresql_adapter'
require 'pg'

class ::ActiveRecord::Base
  # ActiveRecord looks for the postgis_connection factory method in
  # this class.
  #
  # Based on the default `postgresql_connection` definition from
  # activerecord's:
  # lib/active_record/connection_adapters/postgresql_adapter.rb
  def self.postgis_connection(config_)
    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_.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.
    ::ActiveRecord::ConnectionAdapters::PostGISAdapter::MainAdapter.new(nil, logger, [host_, port_, nil, nil, database_, username_, password_], config_)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activerecord-postgis-adapter-0.5.0 lib/active_record/connection_adapters/postgis_adapter/pg_connection.rb