Class: Mongoid::Config::ReplsetDatabase
- Defined in:
- lib/mongoid/config/replset_database.rb
Instance Method Summary collapse
-
#authenticating? ⇒ true, false
Do we need to authenticate against the database?.
-
#configure ⇒ Array<Mongo::DB, nil ] The Mongo databases.
Configure the database connections.
-
#initialize(options = {}) ⇒ ReplsetDatabase
constructor
Create the new db configuration class.
-
#method_missing(name, *args, &block) ⇒ Object
Convenience for accessing the hash via dot notation.
Methods included from Extensions::Hash::Scoping
Methods included from Extensions::Hash::CriteriaHelpers
#expand_complex_criteria, #extract_id
Constructor Details
#initialize(options = {}) ⇒ ReplsetDatabase
Create the new db configuration class.
replSet does not supports auth
…
77 78 79 |
# File 'lib/mongoid/config/replset_database.rb', line 77 def initialize( = {}) merge!() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Convenience for accessing the hash via dot notation.
54 55 56 |
# File 'lib/mongoid/config/replset_database.rb', line 54 def method_missing(name, *args, &block) self[name.to_s] end |
Instance Method Details
#authenticating? ⇒ true, false
Do we need to authenticate against the database?
42 43 44 |
# File 'lib/mongoid/config/replset_database.rb', line 42 def authenticating? username || password end |
#configure ⇒ Array<Mongo::DB, nil ] The Mongo databases.
Configure the database connections. This will return an array containing one Mongo::DB and nil (to keep compatibility with Mongoid::Config::Database) If you want the reads to go to a secondary node use the :read_secondary(true): option
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mongoid/config/replset_database.rb', line 16 def configure # yes, construction is weird but the driver wants # "A list of host-port pairs ending with a hash containing any options" # mongo likes symbols = self.inject({ :logger => Mongoid::Logger.new }) do |memo, (k, v)| memo[k.to_sym] = v memo end connection = Mongo::ReplSetConnection.new(*(hosts.clone << )) if authenticating? connection.add_auth(database, username, password) connection.apply_saved_authentication end [ DatabaseProxy.new(connection, database), nil ] end |