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 }
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.
- #options ⇒ Object
- #password ⇒ Object
- #port ⇒ Object
- #replicas ⇒ Object
- #set_options!(options) ⇒ Object
- #use_database(database) ⇒ Object
- #username ⇒ Object
Constructor Details
#initialize(options) ⇒ Configuration
Returns a new instance of Configuration.
6 7 8 |
# File 'lib/mongomodel/support/configuration.rb', line 6 def initialize() () end |
Class Method Details
.defaults ⇒ Object
78 79 80 |
# File 'lib/mongomodel/support/configuration.rb', line 78 def self.defaults new({}) end |
Instance Method Details
#connection ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/mongomodel/support/configuration.rb', line 45 def connection if replicas.any? @connection ||= Mongo::MongoReplicaSetClient.new(replicas, ) else @connection ||= Mongo::MongoClient.new(host, port, ) end end |
#connection_options ⇒ Object
53 54 55 |
# File 'lib/mongomodel/support/configuration.rb', line 53 def .except('host', 'port', 'database', 'username', 'password', 'replicas').symbolize_keys end |
#database ⇒ Object
18 19 20 |
# File 'lib/mongomodel/support/configuration.rb', line 18 def database ['database'] end |
#establish_connection ⇒ Object
34 35 36 37 38 |
# File 'lib/mongomodel/support/configuration.rb', line 34 def establish_connection @database = connection.db(database) @database.authenticate(username, password) if username.present? @database end |
#host ⇒ Object
10 11 12 |
# File 'lib/mongomodel/support/configuration.rb', line 10 def host ['host'] end |
#options ⇒ Object
57 58 59 |
# File 'lib/mongomodel/support/configuration.rb', line 57 def @options ||= {} end |
#password ⇒ Object
26 27 28 |
# File 'lib/mongomodel/support/configuration.rb', line 26 def password ['password'] end |
#port ⇒ Object
14 15 16 |
# File 'lib/mongomodel/support/configuration.rb', line 14 def port ['port'] end |
#replicas ⇒ Object
30 31 32 |
# File 'lib/mongomodel/support/configuration.rb', line 30 def replicas ['replicas'] || [] end |
#set_options!(options) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/mongomodel/support/configuration.rb', line 61 def () case when Hash @options = DEFAULTS.merge().stringify_keys when String (parse()) end end |
#use_database(database) ⇒ Object
40 41 42 43 |
# File 'lib/mongomodel/support/configuration.rb', line 40 def use_database(database) ['database'] = database establish_connection end |
#username ⇒ Object
22 23 24 |
# File 'lib/mongomodel/support/configuration.rb', line 22 def username ['username'] end |