class MongoModel::Configuration

Constants

DEFAULTS

Attributes

options[R]

Public Class Methods

defaults() click to toggle source
# File lib/mongomodel/support/configuration.rb, line 67
def self.defaults
  new({})
end
new(options) click to toggle source
# File lib/mongomodel/support/configuration.rb, line 16
def initialize(options)
  @options = DEFAULTS.merge(options).stringify_keys
end

Public Instance Methods

connection() click to toggle source
# File lib/mongomodel/support/configuration.rb, line 55
def connection
  if replicas.any?
    @connection ||= Mongo::MongoReplicaSetClient.new(replicas, connection_options)
  else
    @connection ||= Mongo::MongoClient.new(host, port, connection_options)
  end
end
connection_options() click to toggle source
# File lib/mongomodel/support/configuration.rb, line 63
def connection_options
  options.except('host', 'port', 'database', 'username', 'password', 'replicas').symbolize_keys
end
database() click to toggle source
# File lib/mongomodel/support/configuration.rb, line 28
def database
  options['database']
end
establish_connection() click to toggle source
# File lib/mongomodel/support/configuration.rb, line 44
def establish_connection
  @database = connection.db(database)
  @database.authenticate(username, password) if username.present?
  @database
end
host() click to toggle source
# File lib/mongomodel/support/configuration.rb, line 20
def host
  options['host']
end
password() click to toggle source
# File lib/mongomodel/support/configuration.rb, line 36
def password
  options['password']
end
port() click to toggle source
# File lib/mongomodel/support/configuration.rb, line 24
def port
  options['port']
end
replicas() click to toggle source
# File lib/mongomodel/support/configuration.rb, line 40
def replicas
  options['replicas'] || []
end
use_database(database) click to toggle source
# File lib/mongomodel/support/configuration.rb, line 50
def use_database(database)
  options['database'] = database
  establish_connection
end
username() click to toggle source
# File lib/mongomodel/support/configuration.rb, line 32
def username
  options['username']
end