Sha256: 179da9c65bd7d0a0020859b14f061d56da2b3809624e0b01ad65de9537756919

Contents?: true

Size: 1.61 KB

Versions: 1

Compression:

Stored size: 1.61 KB

Contents

# -*- encoding : utf-8 -*-
require 'ashikawa-core/connection'

module Ashikawa
  module Core
    # Configuration of Ashikawa::Core
    class Configuration
      # The URL of the database instance
      # @api private
      # @return String
      attr_accessor :url

      # The Connection object
      # @api private
      # @return Connection
      attr_writer :connection

      # The logger instance
      # @api private
      # @return Object
      attr_accessor :logger

      # The HTTP adapter instance
      # @api private
      # @return Object
      attr_accessor :adapter

      # The username for authentication
      # @api private
      # @return String
      attr_accessor :username

      # The password for authentication
      # @api private
      # @return String
      attr_accessor :password

      # The Connection object
      # @api private
      # @return Connection
      def connection
        @connection ||= setup_new_connection
        @connection.authenticate_with(username, password) if username && password
        @connection
      end

      private

      # Setup the connection object
      #
      # @param [String] url
      # @param [Logger] logger
      # @param [Adapter] adapter
      # @return [Connection]
      # @api private
      def setup_new_connection
        raise(ArgumentError, 'Please provide either an url or a connection to setup the database') if url.nil?

        Connection.new(url, connection_options)
      end

      def connection_options
        opts = {}
        opts[:logger] = logger if logger
        opts[:adapter] = adapter if adapter
        opts
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ashikawa-core-0.11.0 lib/ashikawa-core/configuration.rb