Module: Innkeeper::Tenant

Extended by:
Forwardable, Tenant
Included in:
Tenant
Defined in:
lib/innkeeper/tenant.rb

Overview

The main entry point to Innkeeper functions

Instance Method Summary collapse

Instance Method Details

#adapterObject

Fetch the proper multi-tenant adapter based on Rails config

@return {subclass of Innkeeper::AbstractAdapter}


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/innkeeper/tenant.rb', line 26

def adapter
  Thread.current[:innkeeper_adapter] ||= begin
    config = Innkeeper.default_tenant

    adapter_name = "#{config[:adapter]}_adapter"

    begin
      require "innkeeper/adapters/#{adapter_name}"
      adapter_class = Adapters.const_get(adapter_name.classify)
    rescue LoadError, NameError
      raise AdapterNotFound, "The adapter `#{adapter_name}` is not yet supported"
    end

    adapter_class.new
  end
end

#initObject

Initialize Innkeeper config options such as excluded_models



17
18
19
20
# File 'lib/innkeeper/tenant.rb', line 17

def init
  adapter.setup_connection_specification_name
  adapter.process_excluded_models
end

#reload!Object



43
44
45
# File 'lib/innkeeper/tenant.rb', line 43

def reload!
  Thread.current[:innkeeper_adapter] = nil
end