Sha256: c0aec4a03c70878dd509a76cd7d25f30d015eb15c606325949957e300ba09e46
Contents?: true
Size: 1.81 KB
Versions: 1
Compression:
Stored size: 1.81 KB
Contents
module Legion module Data module Connections class Base attr_reader :sequel def check_gem(gem = adapter) Gem::Specification.find_by_name(gem) rescue Gem::MissingSpecError, ArgumentError false end def creds_builder(credentials = {}) # rubocop:disable Metrics/AbcSize creds = {} if Legion::Settings[:vault][:connected] && ::Vault.sys.mounts.key?(:database) creds = Legion::Crypt.read('database/creds/legion') Legion::Logging.info 'Grabbing database creds from vault' end creds = creds.merge(default_creds) if creds.is_a? Hash creds = creds.merge(Legion::Settings[:data][:creds]) if Legion::Settings[:data][:creds].is_a? Hash creds = creds.merge(credentials) if credentials.is_a? Hash creds end def connect(adapter, creds, _options = {}) creds[:adapter] = adapter @sequel = Sequel.connect(creds) end def settings(options, _connection = @connection) raise ArgumentError unless options.is_a? Hash end def debug_logging(enabled = true, connection = @connection, _options = {}) if enabled connection.logger = Legion::Logging connection.sql_log_level = :debug elsif enabled == false connection.logger = nil connection.sql_log_level = :debug end connection end def adapter 'mysql2' end def default_creds { data: { creds: { host: '127.0.0.1', user: 'legion', password: 'legion', max_connections: 1000, database: 'legion' } } } end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
legion-data-0.2.0 | lib/legion/data/connections/base.rb |