Class: MongoModel::Configuration
- Inherits:
-
Object
- Object
- MongoModel::Configuration
- Defined in:
- lib/mongomodel/support/configuration.rb
Constant Summary collapse
- DEFAULTS =
{ 'host' => 'localhost', 'port' => 27017, 'database' => 'mongomodel-default', 'pool_size' => 5, 'pool_timeout' => 5 }
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #connection ⇒ Object
- #connection_options ⇒ Object
- #database ⇒ Object
- #establish_connection ⇒ Object
- #host ⇒ Object
-
#initialize(options) ⇒ Configuration
constructor
A new instance of Configuration.
- #password ⇒ Object
- #port ⇒ Object
- #replicas ⇒ Object
- #use_database(database) ⇒ Object
- #username ⇒ Object
Constructor Details
#initialize(options) ⇒ Configuration
Returns a new instance of Configuration.
16 17 18 |
# File 'lib/mongomodel/support/configuration.rb', line 16 def initialize() @options = DEFAULTS.merge().stringify_keys end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
14 15 16 |
# File 'lib/mongomodel/support/configuration.rb', line 14 def @options end |
Class Method Details
.defaults ⇒ Object
67 68 69 |
# File 'lib/mongomodel/support/configuration.rb', line 67 def self.defaults new({}) end |
Instance Method Details
#connection ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/mongomodel/support/configuration.rb', line 55 def connection if replicas.any? @connection ||= Mongo::MongoReplicaSetClient.new(replicas, ) else @connection ||= Mongo::MongoClient.new(host, port, ) end end |
#connection_options ⇒ Object
63 64 65 |
# File 'lib/mongomodel/support/configuration.rb', line 63 def .except('host', 'port', 'database', 'username', 'password', 'replicas').symbolize_keys end |
#database ⇒ Object
28 29 30 |
# File 'lib/mongomodel/support/configuration.rb', line 28 def database ['database'] end |
#establish_connection ⇒ Object
44 45 46 47 48 |
# 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 ⇒ Object
20 21 22 |
# File 'lib/mongomodel/support/configuration.rb', line 20 def host ['host'] end |
#password ⇒ Object
36 37 38 |
# File 'lib/mongomodel/support/configuration.rb', line 36 def password ['password'] end |
#port ⇒ Object
24 25 26 |
# File 'lib/mongomodel/support/configuration.rb', line 24 def port ['port'] end |
#replicas ⇒ Object
40 41 42 |
# File 'lib/mongomodel/support/configuration.rb', line 40 def replicas ['replicas'] || [] end |
#use_database(database) ⇒ Object
50 51 52 53 |
# File 'lib/mongomodel/support/configuration.rb', line 50 def use_database(database) ['database'] = database establish_connection end |
#username ⇒ Object
32 33 34 |
# File 'lib/mongomodel/support/configuration.rb', line 32 def username ['username'] end |