Module: Boxlet::Db

Extended by:
Db
Includes:
Mongo
Included in:
Db
Defined in:
lib/boxlet/db.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dbObject

Returns the value of attribute db.



9
10
11
# File 'lib/boxlet/db.rb', line 9

def db
  @db
end

Instance Method Details

#connectObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/boxlet/db.rb', line 15

def connect
  config = Boxlet.config
  db_config = config[:db][config[:environment].to_sym || :development]

  host = db_config[:host] || 'localhost'
  port = db_config[:port] || MongoClient::DEFAULT_PORT
  Boxlet.log(:info, "INFO: Connecting to #{host}:#{port}")
  client  = MongoClient.new(host, port)
  db = client.db(db_config[:db] || 'boxlet_development')
  return db
end

#connectionObject



11
12
13
# File 'lib/boxlet/db.rb', line 11

def connection
  @db ||= self.connect
end