Sha256: 3772ffde36ba45c0198510766c97f3da487dceb2894ef5a8854b5c00985f85aa

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

module Legion
  module Data
    module Connections
      class Base
        def check_gem(gem = adapter)
          Gem::Specification.find_by_name(gem)
        rescue Gem::MissingSpecError, ArgumentError
          false
        end

        def creds_builder(credentials = {})
          creds = {}
          creds = creds.merge(default_creds) if creds.is_a? Hash
          creds = creds.merge(Legion::Settings[:data][:mysql]) if Legion::Settings[:data][:mysql].is_a? Hash
          creds = creds.merge(credentials) if credentials.is_a? Hash
          creds
        end

        def connect(adapter, creds, _options = {})
          creds[:adapter] = adapter
          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
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
legion-data-0.1.1 lib/legion/data/connections/base.rb