Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Mongodb
- def self.db
- config = Rails.configuration.database_configuration["mongodb_#{Rails.env}"]
- host = config["host"]
- database = config["database"]
- username = config["username"]
- password = config["password"]
- port = config["port"]
- if Rails.env == "development"
- @@connection ||= Mongo::Connection.new host, port, :logger => Rails.logger, :safe => true
- else
- host.each { |h| h[1] << port }
- @@connection ||= Mongo::ReplSetConnection.new(host["primary"], host["secondary"], :logger => Rails.logger, :refresh_mode => :sync)
- end
- @@db ||= @@connection[database]
- unless username.nil? || password.nil?
- @@db.authenticate(username, password)
- end
- @@db
- end
- def self.sent_email
- @collection ||= Mongodb.db['sent_email']
- end
- end
Add Comment
Please, Sign In to add comment