Class: Lotus::Model::Migrator::Connection Private

Inherits:
Object
  • Object
show all
Defined in:
lib/lotus/model/migrator/connection.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Sequel connection wrapper

Normalize external adapters interfaces

Since:

  • 0.5.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter_connection) ⇒ Connection

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Connection.

Since:

  • 0.5.0



13
14
15
# File 'lib/lotus/model/migrator/connection.rb', line 13

def initialize(adapter_connection)
  @adapter_connection = adapter_connection
end

Instance Attribute Details

#adapter_connectionObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 0.5.0



11
12
13
# File 'lib/lotus/model/migrator/connection.rb', line 11

def adapter_connection
  @adapter_connection
end

Instance Method Details

#databaseObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns DB name from conenction

Even when adapter doesn’t provide it explicitly it tries to parse

Since:

  • 0.5.0



43
44
45
# File 'lib/lotus/model/migrator/connection.rb', line 43

def database
  @database ||= opts.fetch(:database, parsed_uri.path[1..-1])
end

#database_typeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns DB type

Examples:

connection.database_type
# => 'postgres'

Since:

  • 0.5.0



55
56
57
# File 'lib/lotus/model/migrator/connection.rb', line 55

def database_type
  adapter_connection.database_type
end

#global_uriObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns DB connection wihout specifying database name

Since:

  • 0.5.0



91
92
93
# File 'lib/lotus/model/migrator/connection.rb', line 91

def global_uri
  adapter_connection.uri.sub(parsed_uri.select(:path).first, '')
end

#hostObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns DB connection host

Even when adapter doesn’t provide it explicitly it tries to parse

Since:

  • 0.5.0



23
24
25
# File 'lib/lotus/model/migrator/connection.rb', line 23

def host
  @host ||= opts.fetch(:host, parsed_uri.host)
end

#jdbc?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a boolean telling if a DB connection is from JDBC or not

Returns:

  • (Boolean)

Since:

  • 0.5.0



99
100
101
# File 'lib/lotus/model/migrator/connection.rb', line 99

def jdbc?
  !adapter_connection.uri.scan('jdbc:').empty?
end

#parsed_uriObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns database connection URI instance without JDBC namespace

Since:

  • 0.5.0



107
108
109
# File 'lib/lotus/model/migrator/connection.rb', line 107

def parsed_uri
  @uri ||= URI.parse(adapter_connection.uri.sub('jdbc:', ''))
end

#passwordObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns user from DB connection

Even when adapter doesn’t provide it explicitly it tries to parse

Since:

  • 0.5.0



75
76
77
# File 'lib/lotus/model/migrator/connection.rb', line 75

def password
  @password ||= opts.fetch(:password, parsed_opt('password'))
end

#portObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns DB connection port

Even when adapter doesn’t provide it explicitly it tries to parse

Since:

  • 0.5.0



33
34
35
# File 'lib/lotus/model/migrator/connection.rb', line 33

def port
  @port ||= opts.fetch(:port, parsed_uri.port)
end

#uriObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns DB connection URI directly from adapter

Since:

  • 0.5.0



83
84
85
# File 'lib/lotus/model/migrator/connection.rb', line 83

def uri
  adapter_connection.uri
end

#userObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns user from DB connection

Even when adapter doesn’t provide it explicitly it tries to parse

Since:

  • 0.5.0



65
66
67
# File 'lib/lotus/model/migrator/connection.rb', line 65

def user
  @user ||= opts.fetch(:user, parsed_opt('user'))
end