Module: Apartment

Extended by:
Forwardable
Defined in:
lib/apartment.rb,
lib/apartment/railtie.rb,
lib/apartment/version.rb,
lib/apartment/database.rb,
lib/apartment/migrator.rb,
lib/apartment/reloader.rb,
lib/apartment/elevators/domain.rb,
lib/apartment/elevators/generic.rb,
lib/apartment/elevators/host_hash.rb,
lib/apartment/elevators/subdomain.rb,
lib/apartment/adapters/mysql2_adapter.rb,
lib/apartment/adapters/postgis_adapter.rb,
lib/apartment/adapters/sqlite3_adapter.rb,
lib/apartment/adapters/abstract_adapter.rb,
lib/apartment/elevators/first_subdomain.rb,
lib/apartment/adapters/jdbc_mysql_adapter.rb,
lib/apartment/adapters/postgresql_adapter.rb,
lib/apartment/adapters/abstract_jdbc_adapter.rb,
lib/apartment/adapters/jdbc_postgresql_adapter.rb,
lib/generators/apartment/install/install_generator.rb

Defined Under Namespace

Modules: Adapters, Database, Elevators, Migrator Classes: InstallGenerator, Railtie, Reloader

Constant Summary collapse

ACCESSOR_METHODS =
[:use_schemas, :seed_after_create, :prepend_environment, :append_environment]
WRITER_METHODS =
[:tenant_names, :database_schema_file, :excluded_models, :default_schema, :persistent_schemas, :connection_class, :tld_length, :db_migrate_tenants]
ApartmentError =

Exceptions

Class.new(StandardError)
AdapterNotFound =

Raised when apartment cannot find the adapter specified in config/database.yml

Class.new(ApartmentError)
TenantNotFound =

Tenant specified is unknown

Class.new(ApartmentError)
DatabaseNotFound =

Raised when database cannot find the specified database

Class.new(TenantNotFound)
SchemaNotFound =

Raised when database cannot find the specified schema

Class.new(TenantNotFound)
TenantExists =

The Tenant attempting to be created already exists

Class.new(ApartmentError)
DatabaseExists =

Raised when trying to create a database that already exists

Class.new(TenantExists)
SchemaExists =

Raised when trying to create a schema that already exists

Class.new(TenantExists)
VERSION =
"0.24.3"

Class Method Summary collapse

Class Method Details

.configure {|_self| ... } ⇒ Object

configure apartment with available options

Yields:

  • (_self)

Yield Parameters:

  • _self (Apartment)

    the object that the method was called on



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

def configure
  yield self if block_given?
end

.connection_classObject



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

def connection_class
  @connection_class || ActiveRecord::Base
end

.database_namesObject



71
72
73
74
# File 'lib/apartment.rb', line 71

def database_names
  warn "[Deprecation Warning] `database_names` is now deprecated, please use `tenant_names`"
  tenant_names
end

.database_names=(names) ⇒ Object



76
77
78
79
# File 'lib/apartment.rb', line 76

def database_names=(names)
  warn "[Deprecation Warning] `database_names=` is now deprecated, please use `tenant_names=`"
  self.tenant_names=(names)
end

.database_schema_fileObject



56
57
58
59
60
# File 'lib/apartment.rb', line 56

def database_schema_file
  return @database_schema_file if defined?(@database_schema_file)

  @database_schema_file = Rails.root.join('db', 'schema.rb')
end

.db_migrate_tenantsObject

Whether or not db:migrate should also migrate tenants defaults to true



33
34
35
36
37
# File 'lib/apartment.rb', line 33

def db_migrate_tenants
  return @db_migrate_tenants if defined?(@db_migrate_tenants)

  @db_migrate_tenants = true
end

.default_schemaObject



44
45
46
# File 'lib/apartment.rb', line 44

def default_schema
  @default_schema || "public"
end

.excluded_modelsObject

Default to empty array



40
41
42
# File 'lib/apartment.rb', line 40

def excluded_models
  @excluded_models || []
end

.persistent_schemasObject



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

def persistent_schemas
  @persistent_schemas || []
end

.resetObject

Reset all the config for Apartment



67
68
69
# File 'lib/apartment.rb', line 67

def reset
  (ACCESSOR_METHODS + WRITER_METHODS).each{|method| remove_instance_variable(:"@#{method}") if instance_variable_defined?(:"@#{method}") }
end

.tenant_namesObject

Be careful not to use ‘return` here so both Proc and lambda can be used without breaking



27
28
29
# File 'lib/apartment.rb', line 27

def tenant_names
  @tenant_names.respond_to?(:call) ? @tenant_names.call : @tenant_names
end

.tld_lengthObject



62
63
64
# File 'lib/apartment.rb', line 62

def tld_length
  @tld_length || 1
end

.use_postgres_schemasObject



81
82
83
84
# File 'lib/apartment.rb', line 81

def use_postgres_schemas
  warn "[Deprecation Warning] `use_postgresql_schemas` is now deprecated, please use `use_schemas`"
  use_schemas
end

.use_postgres_schemas=(to_use_or_not_to_use) ⇒ Object



86
87
88
89
# File 'lib/apartment.rb', line 86

def use_postgres_schemas=(to_use_or_not_to_use)
  warn "[Deprecation Warning] `use_postgresql_schemas=` is now deprecated, please use `use_schemas=`"
  self.use_schemas = to_use_or_not_to_use
end