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 12 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 25 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 18 def drop(tenant) raise TenantNotFound, "The tenant #{environmentify(tenant)} cannot be found." unless File.exists?(database_file(tenant)) 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 31 def connect_to_new(tenant) raise TenantNotFound, "The tenant #{environmentify(tenant)} cannot be found." unless File.exists?(database_file(tenant)) super database_file(tenant) end
create_tenant(tenant)
click to toggle source
# File lib/apartment/adapters/sqlite3_adapter.rb, line 38 def create_tenant(tenant) raise TenantExists, "The tenant #{environmentify(tenant)} already exists." if File.exists?(database_file(tenant)) 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 51 def database_file(tenant) "#{@default_dir}/#{environmentify(tenant)}.sqlite3" end