Class: Lamed::DM

Inherits:
Object
  • Object
show all
Includes:
DataMapper
Defined in:
lib/lamed/model.rb

Overview

Support for DataMapper

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ DM

Setup the database connection using DataMapper



23
24
25
26
27
28
29
30
31
# File 'lib/lamed/model.rb', line 23

def initialize(params = {})
  @host          = params[:host]      || 'localhost'
  @port          = (params[:port]     || 3306).to_i
  @user          = params[:username]  || 'root'
  @password      = params[:password]  || 'pwd'
  @database      = params[:database]  || 'ithingy'
  @adapter       = params[:adapter]   || 'mysql'
  self.connect
end

Instance Method Details

#connect(params = {}) ⇒ Object



33
34
35
# File 'lib/lamed/model.rb', line 33

def connect(params = {})
  DataMapper.setup(:default, "#{@adapter}://#{@user}:#{@password}@#{@host}:#{@port}/#{@database}")
end