Class: Djoini::Connection

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/djoini/connection.rb

Overview

Class to manage db connetion to postgres

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#connObject

Returns the value of attribute conn.



14
15
16
# File 'lib/djoini/connection.rb', line 14

def conn
  @conn
end

Instance Method Details

#establish_connection(params) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/djoini/connection.rb', line 16

def establish_connection(params)
  _adapter = params.fetch('adapter', 'postgres')
  _username = params.fetch('username')
  _password = params.fetch('password')
  _host = params.fetch('host', 'localhost')
  _port = params.fetch('port', '5432')
  _db_name = params.fetch('db_name')

  @conn = PG.connect("#{_adapter}://#{_username}:#{_password}@#{_host}:#{_port}/#{_db_name}")
end