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_options ⇒ Object
- #database ⇒ Object
- #establish_connection ⇒ Object
- #host ⇒ Object
-
#initialize(options) ⇒ Configuration
constructor
A new instance of Configuration.
- #options ⇒ Object
- #password ⇒ Object
- #port ⇒ 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
67 68 69 |
# File 'lib/mongomodel/support/configuration.rb', line 67 def self.defaults new({}) end |
Instance Method Details
#connection_options ⇒ Object
42 43 44 |
# File 'lib/mongomodel/support/configuration.rb', line 42 def .except('host', 'port', 'database', 'username', 'password').symbolize_keys end |
#database ⇒ Object
18 19 20 |
# File 'lib/mongomodel/support/configuration.rb', line 18 def database ['database'] end |
#establish_connection ⇒ Object
30 31 32 33 34 35 |
# File 'lib/mongomodel/support/configuration.rb', line 30 def establish_connection @connection ||= Mongo::Connection.new(host, port, ) @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
46 47 48 |
# File 'lib/mongomodel/support/configuration.rb', line 46 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 |
#set_options!(options) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/mongomodel/support/configuration.rb', line 50 def () case when Hash @options = DEFAULTS.merge().stringify_keys when String (parse()) end end |
#use_database(database) ⇒ Object
37 38 39 40 |
# File 'lib/mongomodel/support/configuration.rb', line 37 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 |