class ExchangeRate::DatabaseConnection
Database connection management for ::ExchangeRate
.
Public Class Methods
apply_migrations(connection)
click to toggle source
Apply the schema definitions to the database.
Returns nothing
# File lib/exchange_rate/database_connection.rb, line 32 def self.apply_migrations(connection) return if connection.nil? Sequel::Migrator.run(connection, 'lib/exchange_rate/db/migrate/') end
connection()
click to toggle source
Establish a connection to the database, and ensure the schema is loaded. The connection is cached and kept open.
Returns nothing
# File lib/exchange_rate/database_connection.rb, line 16 def self.connection database_url = ExchangeRate.configuration.datastore_url @connection ||= Sequel.connect(database_url).tap { |connection| apply_migrations(connection) } end
disconnect()
click to toggle source
Closes any open connections to the database and removes the cached connection.
# File lib/exchange_rate/database_connection.rb, line 23 def self.disconnect @connection&.disconnect @connection = nil end