module Innkeeper::Tenant

The main entry point to Innkeeper functions

Public Instance Methods

adapter() click to toggle source

Fetch the proper multi-tenant adapter based on Rails config

@return {subclass of Innkeeper::AbstractAdapter}

# 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
init() click to toggle source

Initialize Innkeeper config options such as excluded_models

# File lib/innkeeper/tenant.rb, line 17
def init
  adapter.setup_connection_specification_name
  adapter.process_excluded_models
end
reload!() click to toggle source
# File lib/innkeeper/tenant.rb, line 43
def reload!
  Thread.current[:innkeeper_adapter] = nil
end