Module: Innkeeper

Extended by:
Forwardable
Defined in:
lib/innkeeper/tasks/enhancements.rb,
lib/innkeeper.rb,
lib/innkeeper/tenant.rb,
lib/innkeeper/railtie.rb,
lib/innkeeper/version.rb,
lib/innkeeper/migrator.rb,
lib/innkeeper/deprecation.rb,
lib/innkeeper/elevators/domain.rb,
lib/innkeeper/resolvers/schema.rb,
lib/innkeeper/elevators/generic.rb,
lib/innkeeper/resolvers/abstract.rb,
lib/innkeeper/resolvers/database.rb,
lib/innkeeper/elevators/host_hash.rb,
lib/innkeeper/elevators/subdomain.rb,
lib/innkeeper/adapters/mysql2_adapter.rb,
lib/innkeeper/adapters/abstract_adapter.rb,
lib/innkeeper/adapters/postgresql_adapter.rb,
lib/generators/innkeeper/install/install_generator.rb

Overview

Require this file to append Innkeeper rake tasks to ActiveRecord db rake tasks Enabled by default in the initializer

Defined Under Namespace

Modules: Adapters, Deprecation, Elevators, Migrator, Resolvers, Tenant Classes: InstallGenerator, Railtie, RakeTaskEnhancer

Constant Summary collapse

ACCESSOR_METHODS =
[
  :use_sql, :seed_after_create, :tenant_decorator,
  :force_reconnect_on_switch, :pool_per_config
]
WRITER_METHODS =
[
  :tenant_names, :database_schema_file, :excluded_models,
  :persistent_schemas, :connection_class, :tld_length, :db_migrate_tenants,
  :seed_data_file, :default_tenant, :parallel_migration_threads
]
OTHER_METHODS =
[:tenant_resolver, :resolver_class]
InnkeeperError =

Exceptions

Class.new(StandardError)
AdapterNotFound =

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

Class.new(InnkeeperError)
TenantNotFound =

Tenant specified is unknown

Class.new(InnkeeperError)
TenantExists =

The Tenant attempting to be created already exists

Class.new(InnkeeperError)
VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

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

Yields:

  • (_self)

Yield Parameters:

  • _self (Innkeeper)

    the object that the method was called on



28
29
30
# File 'lib/innkeeper.rb', line 28

def configure
  yield self if block_given?
end

.connection_classObject



74
75
76
# File 'lib/innkeeper.rb', line 74

def connection_class
  @connection_class || ActiveRecord::Base
end

.database_schema_fileObject



78
79
80
81
82
# File 'lib/innkeeper.rb', line 78

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



51
52
53
54
55
# File 'lib/innkeeper.rb', line 51

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

  @db_migrate_tenants = true
end

.default_tenantObject



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

def default_tenant
  @default_tenant || tenant_resolver.init_config
end

.excluded_modelsObject

Default to empty array



58
59
60
# File 'lib/innkeeper.rb', line 58

def excluded_models
  @excluded_models || []
end

.parallel_migration_threadsObject



66
67
68
# File 'lib/innkeeper.rb', line 66

def parallel_migration_threads
  @parallel_migration_threads || 0
end

.persistent_schemasObject



70
71
72
# File 'lib/innkeeper.rb', line 70

def persistent_schemas
  @persistent_schemas || []
end

.resetObject



90
91
92
93
94
95
96
# File 'lib/innkeeper.rb', line 90

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

  Thread.current[:_innkeeper_connection_specification_name] = nil
end

.seed_data_fileObject



84
85
86
87
88
# File 'lib/innkeeper.rb', line 84

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

  @seed_data_file = Rails.root.join('db', 'seeds.rb')
end

.tenant_namesObject



41
42
43
# File 'lib/innkeeper.rb', line 41

def tenant_names
  @tenant_names.respond_to?(:call) ? @tenant_names.call : (@tenant_names || [])
end

.tenant_resolverObject



32
33
34
# File 'lib/innkeeper.rb', line 32

def tenant_resolver
  @tenant_resolver ||= @resolver_class.new(connection_config)
end

.tenant_resolver=(resolver_class) ⇒ Object



36
37
38
39
# File 'lib/innkeeper.rb', line 36

def tenant_resolver=(resolver_class)
  remove_instance_variable(:@tenant_resolver) if instance_variable_defined?(:@tenant_resolver)
  @resolver_class = resolver_class
end

.tenants_with_configObject



45
46
47
# File 'lib/innkeeper.rb', line 45

def tenants_with_config
  extract_tenant_config
end