Module: Ircbot::DM::Connection

Defined in:
lib/ircbot/dm.rb

Instance Method Summary collapse

Instance Method Details

#connect(*models) ⇒ Object



36
37
38
# File 'lib/ircbot/dm.rb', line 36

def connect(*models)
  @models = models
end

#establish_connection(path = nil, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ircbot/dm.rb', line 21

def establish_connection(path = nil, &block)
  path = path.to_s
  path = 'unknown' if path.empty?
  if DM.connection != path
    DM.connection = path
    path = (path[0] == ?/) ? Pathname(path) : Pathname(Dir.getwd) + "db" + "#{path}.db"
    path = path.expand_path
    path.parent.mkpath
    DataMapper.setup(:default, "sqlite3://#{path}")
  end

  @models.each(&:auto_upgrade!) if @models
  return DataMapper.repository(:default)
end