Class: Apartment::Adapters::PostgresqlSchemaAdapter

Inherits:
AbstractAdapter show all
Defined in:
lib/apartment/adapters/postgresql_adapter.rb

Overview

Separate Adapter for Postgresql when using schemas

Instance Method Summary collapse

Methods inherited from AbstractAdapter

#create, #drop, #each, #environmentify, #process_excluded_models, #seed_data, #switch, #switch!

Constructor Details

#initialize(config) ⇒ PostgresqlSchemaAdapter

Returns a new instance of PostgresqlSchemaAdapter.



28
29
30
31
32
# File 'lib/apartment/adapters/postgresql_adapter.rb', line 28

def initialize(config)
  super

  reset
end

Instance Method Details

#currentObject



52
53
54
# File 'lib/apartment/adapters/postgresql_adapter.rb', line 52

def current
  @current || default_tenant
end

#default_tenantObject



34
35
36
# File 'lib/apartment/adapters/postgresql_adapter.rb', line 34

def default_tenant
  @default_tenant = Apartment.default_tenant || 'public'
end

#initObject



47
48
49
50
# File 'lib/apartment/adapters/postgresql_adapter.rb', line 47

def init
  super
  Apartment.connection.schema_search_path = full_search_path
end

#resetObject

Reset schema search path to the default schema_search_path

@return {String} default schema search path


42
43
44
45
# File 'lib/apartment/adapters/postgresql_adapter.rb', line 42

def reset
  @current = default_tenant
  Apartment.connection.schema_search_path = full_search_path
end