Class: MysqlConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/database_fork/mysql_connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ MysqlConnection

Returns a new instance of MysqlConnection.



2
3
4
# File 'lib/database_fork/mysql_connection.rb', line 2

def initialize(config)
  @config = config
end

Instance Method Details

#paramsObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/database_fork/mysql_connection.rb', line 6

def params
  key_mapping = {
    'username' => 'user',
    'password' => 'password',
    'socket' => 'socket',
    'host' => 'host',
    'port' => 'port'
  }

  @config.inject(Hash.new) do |akk, tupel|
    key, value = *tupel

    akk[key_mapping[key.to_s]] = value if key_mapping.key?(key.to_s)
    akk
  end.map do |tupel|
    key, value = *tupel

    "--#{key}=#{value}"
  end.sort.join(' ')
end