module Apartment::Database
The main entry point to Apartment
functions
Public Class Methods
jdbcpostgresql_adapter(config)
click to toggle source
# File lib/apartment/adapters/jdbcpostgresql_adapter.rb, line 5 def self.jdbcpostgresql_adapter(config) Apartment.use_postgres_schemas ? Adapters::PostgresqlSchemaAdapter.new(config, :schema_search_path => ActiveRecord::Base.connection.schema_search_path) : Adapters::PostgresqlAdapter.new(config) end
mysql_adapter(config)
click to toggle source
# File lib/apartment/adapters/mysql_adapter.rb, line 5 def self.mysql_adapter(config) Adapters::MysqlAdapter.new config end
postgresql_adapter(config)
click to toggle source
# File lib/apartment/adapters/postgresql_adapter.rb, line 5 def self.postgresql_adapter(config) Apartment.use_postgres_schemas ? Adapters::PostgresqlSchemaAdapter.new(config, :schema_search_path => ActiveRecord::Base.connection.schema_search_path) : Adapters::PostgresqlAdapter.new(config) end
Public Instance Methods
adapter()
click to toggle source
Fetch the proper multi-tenant adapter based on Rails config
@return {subclass of Apartment::AbstractAdapter}
# File lib/apartment/database.rb, line 22 def adapter @adapter ||= begin adapter_method = "#{config[:adapter]}_adapter" begin require "apartment/adapters/#{adapter_method}" rescue LoadError => e raise "The adapter `#{config[:adapter]}` is not yet supported" end unless respond_to?(adapter_method) raise AdapterNotFound, "database configuration specifies nonexistent #{config[:adapter]} adapter" end send(adapter_method, config) end end
init()
click to toggle source
Initialize Apartment
config options such as excluded_models
# File lib/apartment/database.rb, line 14 def init process_excluded_models end
reload!()
click to toggle source
Reset config and adapter so they are regenerated
# File lib/apartment/database.rb, line 42 def reload! @adapter = nil @config = nil end
Private Instance Methods
config()
click to toggle source
Fetch the rails database configuration
# File lib/apartment/database.rb, line 51 def config @config ||= Rails.configuration.database_configuration[Rails.env].symbolize_keys end