Class: C3s::DatabaseAdapter

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

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ DatabaseAdapter

Returns a new instance of DatabaseAdapter.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/databaseadapter.rb', line 5

def initialize(config)
  log_file = File.join(C3S_LOG_DIR, "database.log")
  db_file = File.join(C3S_COMPONENT_DIR, config['database'])
  
  ActiveRecord::Base.colorize_logging = false
  ActiveRecord::Base.logger = Logger.new(File.open(log_file, 'a'))
  
  ActiveRecord::Base.establish_connection(
    :adapter  => config['adapter'],
    :host     => config['host'],
    :username => config['username'],
    :password => config['password'],
    :database => db_file, # TODO works only for sqlite3 dbs!
    :encoding => config['encoding']
  )
end