Guest User

Untitled

a guest
Sep 9th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. module Mongodb
  2.  
  3. def self.db
  4. config = Rails.configuration.database_configuration["mongodb_#{Rails.env}"]
  5. host = config["host"]
  6. database = config["database"]
  7. username = config["username"]
  8. password = config["password"]
  9. port = config["port"]
  10.  
  11. if Rails.env == "development"
  12. @@connection ||= Mongo::Connection.new host, port, :logger => Rails.logger, :safe => true
  13. else
  14. host.each { |h| h[1] << port }
  15. @@connection ||= Mongo::ReplSetConnection.new(host["primary"], host["secondary"], :logger => Rails.logger, :refresh_mode => :sync)
  16. end
  17.  
  18. @@db ||= @@connection[database]
  19.  
  20. unless username.nil? || password.nil?
  21. @@db.authenticate(username, password)
  22. end
  23.  
  24. @@db
  25. end
  26.  
  27. def self.sent_email
  28. @collection ||= Mongodb.db['sent_email']
  29. end
  30.  
  31. end
Add Comment
Please, Sign In to add comment