class Apartment::Adapters::Sqlite3Adapter
def connect_to_new(tenant)
def connect_to_new(tenant) return reset if tenant.nil? unless File.exist?(database_file(tenant)) raise TenantNotFound, "The tenant #{environmentify(tenant)} cannot be found." end super database_file(tenant) end
def create_tenant(tenant)
def create_tenant(tenant) if File.exist?(database_file(tenant)) raise TenantExists, "The tenant #{environmentify(tenant)} already exists." end begin f = File.new(database_file(tenant), File::CREAT) ensure f.close end end
def current
def current File.basename(Apartment.connection.instance_variable_get(:@config)[:database], '.sqlite3') end
def database_file(tenant)
def database_file(tenant) "#{@default_dir}/#{environmentify(tenant)}.sqlite3" end
def drop(tenant)
def drop(tenant) unless File.exist?(database_file(tenant)) raise TenantNotFound, "The tenant #{environmentify(tenant)} cannot be found." end File.delete(database_file(tenant)) end
def initialize(config)
def initialize(config) @default_dir = File.expand_path(File.dirname(config[:database])) super end