Sha256: 82e21d27de8a1b8aec99fe996c5ebddaba417f53c18376d82efc4d652be2da57

Contents?: true

Size: 716 Bytes

Versions: 3

Compression:

Stored size: 716 Bytes

Contents

require 'uri'

module Dbcp
  class UriEnvironmentProvider
    def find(environment_name)
      uri = URI.parse(environment_name)
      return nil unless uri.scheme

      build_environment environment_name, uri
    end

    private

    def build_environment(environment_name, uri)
      Environment.new({
        environment_name: environment_name,
        database:         Database.build({
          'adapter'  => uri.scheme,
          'username' => uri.user,
          'password' => uri.password,
          'host'     => uri.host,
          'port'     => uri.port,
          'database' => uri.path[1..-1] # Trim leading '/'
        }),
        execution_host:   LocalExecutionHost.new
      })
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dbcp-0.2.1 lib/dbcp/environment_providers/uri_environment_provider.rb
dbcp-0.2.0 lib/dbcp/environment_providers/uri_environment_provider.rb
dbcp-0.1.0 lib/dbcp/environment_providers/uri_environment_provider.rb