Class: MinceMongoDb::Config
- Inherits:
-
Object
- Object
- MinceMongoDb::Config
- Includes:
- Singleton
- Defined in:
- lib/mince_mongo_db/config.rb
Overview
Config
Config specifies the configuration settings
The following fields can be changed:
-
database_name - Defaults to ‘mince’
-
database_host - Defaults to ‘127.0.0.1’
-
username - Defaults to nil
-
password - Defaults to nil
The following fields cannot be changed:
-
primary_key
-
test_env_number
You can change a field by passing a hash:
MinceMongoDb::Config. = {
username: 'my_db_user',
password: 'my_db_passw0rd'
}
Or you can change a field individually:
MinceMongoDb::Config.username = 'my_db_user'
If you are running tests in parallel, make sure that ENV is set for the instance number for each parallel test. This number is amended to the database name.
Constant Summary collapse
- OPTIONS =
%w(database_name database_host username password)
Instance Attribute Summary collapse
-
#database_host ⇒ Object
Returns the value of attribute database_host.
-
#database_name ⇒ Object
Returns the value of attribute database_name.
-
#password ⇒ Object
Returns the value of attribute password.
-
#primary_key ⇒ Object
Returns the value of attribute primary_key.
-
#username ⇒ Object
Returns the value of attribute username.
Class Method Summary collapse
- .options ⇒ Object
- .options=(new_options) ⇒ Object
-
.test_env_number ⇒ Object
Returns the test environment number, useful for when testing with multiple processes in parallel.
- .whitelist_keys(options) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
83 84 85 86 87 |
# File 'lib/mince_mongo_db/config.rb', line 83 def initialize self.primary_key = '_id' self.database_name = 'mince' self.database_host = '127.0.0.1' end |
Instance Attribute Details
#database_host ⇒ Object
Returns the value of attribute database_host.
81 82 83 |
# File 'lib/mince_mongo_db/config.rb', line 81 def database_host @database_host end |
#database_name ⇒ Object
Returns the value of attribute database_name.
81 82 83 |
# File 'lib/mince_mongo_db/config.rb', line 81 def database_name @database_name end |
#password ⇒ Object
Returns the value of attribute password.
81 82 83 |
# File 'lib/mince_mongo_db/config.rb', line 81 def password @password end |
#primary_key ⇒ Object
Returns the value of attribute primary_key.
81 82 83 |
# File 'lib/mince_mongo_db/config.rb', line 81 def primary_key @primary_key end |
#username ⇒ Object
Returns the value of attribute username.
81 82 83 |
# File 'lib/mince_mongo_db/config.rb', line 81 def username @username end |
Class Method Details
.options ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/mince_mongo_db/config.rb', line 56 def self. { database_name: database_name, database_host: database_host, username: username, password: password } end |
.options=(new_options) ⇒ Object
65 66 67 68 69 |
# File 'lib/mince_mongo_db/config.rb', line 65 def self.=() whitelist_keys().each do |key, value| send("#{key}=", value) end end |
.test_env_number ⇒ Object
Returns the test environment number, useful for when testing with multiple processes in parallel
77 78 79 |
# File 'lib/mince_mongo_db/config.rb', line 77 def self.test_env_number ENV['TEST_ENV_NUMBER'] end |
.whitelist_keys(options) ⇒ Object
71 72 73 |
# File 'lib/mince_mongo_db/config.rb', line 71 def self.whitelist_keys() .select{|key, value| OPTIONS.include?(key.to_s) } end |