Class: PgRls::Solo::Tenant

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

Overview

Set and Fetch Tenant without loading a model

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.tenantObject (readonly)

Returns the value of attribute tenant.



8
9
10
# File 'lib/pg_rls/solo/tenant.rb', line 8

def tenant
  @tenant
end

Class Method Details

.around(resource) ⇒ Object



23
24
25
26
27
28
# File 'lib/pg_rls/solo/tenant.rb', line 23

def around(resource)
  switch_tenant!(resource)
  yield
ensure
  reset_rls!
end

.fetchObject



17
18
19
20
21
# File 'lib/pg_rls/solo/tenant.rb', line 17

def fetch
  @fetch ||= PgRls.connection_class.connection.execute(
    "SELECT current_setting('rls.tenant_id')"
  ).getvalue(0, 0)
end

.switch!(resource) ⇒ Object



10
11
12
13
14
15
# File 'lib/pg_rls/solo/tenant.rb', line 10

def switch!(resource)
  switch_tenant!(resource)
rescue StandardError => e
  Rails.logger.info('connection was not made')
  raise e
end