Module: Sinatra::MongoExtension

Defined in:
lib/sinatra/mongo.rb

Instance Method Summary collapse

Instance Method Details

#mongoObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sinatra/mongo.rb', line 18

def mongo
  synchronize do
    @mongo ||= (
      url = URI(mongo_url)
      connection = Mongo::Connection.new(url.host, url.port)
      mongo = connection.db(url.path[1..-1], mongo_settings)
      if url.user && url.password
        mongo.authenticate(url.user, url.password)
      end
      mongo
    )
  end
end

#mongo=(url) ⇒ Object



12
13
14
15
16
# File 'lib/sinatra/mongo.rb', line 12

def mongo=(url)
  @mongo = nil
  set :mongo_url, url
  mongo
end