Class: PgRls::ConnectionConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/pg_rls/connection_config.rb

Overview

The ConnectionConfig class provides methods to configure and manage the connection settings for Row Level Security (RLS) in PostgreSQL. It includes methods to look up and validate the connection configuration, as well as helper methods to build the configuration hash based on different modes.

Instance Method Summary collapse

Constructor Details

#initialize(db_config = ::ActiveRecord::Base.connection_db_config) ⇒ ConnectionConfig

Returns a new instance of ConnectionConfig.



9
10
11
12
# File 'lib/pg_rls/connection_config.rb', line 9

def initialize(db_config = ::ActiveRecord::Base.connection_db_config)
  @db_config = db_config
  @connection_name = db_config.name
end

Instance Method Details

#connection_config?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/pg_rls/connection_config.rb', line 22

def connection_config?
  PgRls.connects_to&.key?(:database) || false
end

#invalid_connection_configObject



26
27
28
29
30
# File 'lib/pg_rls/connection_config.rb', line 26

def invalid_connection_config
  raise PgRls::Error::InvalidConnectionConfig,
        "you must edit your database.yml file to include the RLS configuration, " \
        "or set the RLS configuration manually in the PgRls initializer"
end

#look_up_connection_configObject



14
15
16
17
18
19
20
# File 'lib/pg_rls/connection_config.rb', line 14

def look_up_connection_config
  config_hash = build_config_hash(@db_config, @connection_name)

  return invalid_connection_config unless config_hash

  PgRls.connects_to = config_hash.deep_transform_values(&:to_sym)
end