class Apartment::Adapters::Sqlite3Adapter
Public Class Methods
new(config)
click to toggle source
Calls superclass method
Apartment::Adapters::AbstractAdapter::new
# File lib/apartment/adapters/sqlite3_adapter.rb, line 14 def initialize(config) @default_dir = File.expand_path(File.dirname(config[:database])) super end
Public Instance Methods
current()
click to toggle source
# File lib/apartment/adapters/sqlite3_adapter.rb, line 29 def current File.basename(Apartment.connection.instance_variable_get(:@config)[:database], '.sqlite3') end
drop(tenant)
click to toggle source
# File lib/apartment/adapters/sqlite3_adapter.rb, line 20 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
Protected Instance Methods
connect_to_new(tenant)
click to toggle source
Calls superclass method
Apartment::Adapters::AbstractAdapter#connect_to_new
# File lib/apartment/adapters/sqlite3_adapter.rb, line 35 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
create_tenant(tenant)
click to toggle source
# File lib/apartment/adapters/sqlite3_adapter.rb, line 46 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
Private Instance Methods
database_file(tenant)
click to toggle source
# File lib/apartment/adapters/sqlite3_adapter.rb, line 61 def database_file(tenant) "#{@default_dir}/#{environmentify(tenant)}.sqlite3" end