Module: PG::AzureWorkloadIdentity::ConnectionInfo

Defined in:
lib/pg/azure_workload_identity/connection_info.rb,
lib/pg/azure_workload_identity/connection_info/uri.rb,
lib/pg/azure_workload_identity/connection_info/key_value_string.rb,
lib/pg/azure_workload_identity/connection_info/active_record_configuration_hash.rb

Overview

Factory methods that wrap a PostgreSQL connection description (a connection string or an ActiveRecord configuration hash) in an object exposing a uniform accessor contract (user, host, port, azure_workload_identity, ...).

Concrete return types are URI, KeyValueString, and ActiveRecordConfigurationHash.

Defined Under Namespace

Classes: ActiveRecordConfigurationHash, KeyValueString, URI

Class Method Summary collapse

Class Method Details

.from_active_record_configuration_hash(configuration_hash) ⇒ ActiveRecordConfigurationHash

Wraps an ActiveRecord database configuration hash.

Parameters:

  • configuration_hash (Hash{Symbol => Object})

    an ActiveRecord database configuration hash (as produced from database.yml).

Returns:



41
42
43
# File 'lib/pg/azure_workload_identity/connection_info.rb', line 41

def self.from_active_record_configuration_hash(configuration_hash)
  ActiveRecordConfigurationHash.new(configuration_hash)
end

.from_connection_string(connection_string) ⇒ URI, KeyValueString

Wraps a PostgreSQL connection string, dispatching to the URI or key=value parser based on its format.

Parameters:

  • connection_string (String)

    either a URI-style connection string (e.g. "postgres://user@host/db") or a libpq key=value string (e.g. "host=localhost user=admin").

Returns:



27
28
29
30
31
32
33
# File 'lib/pg/azure_workload_identity/connection_info.rb', line 27

def self.from_connection_string(connection_string)
  if URI.matches?(connection_string)
    URI.new(connection_string)
  else
    KeyValueString.new(connection_string)
  end
end