Class: MinceMongoDb::Config

Inherits:
Object
  • Object
show all
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.options = {
  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.

Author:

  • Matt Simpson

Constant Summary collapse

OPTIONS =
%w(database_name database_host username password)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

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_hostObject

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_nameObject

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

#passwordObject

Returns the value of attribute password.



81
82
83
# File 'lib/mince_mongo_db/config.rb', line 81

def password
  @password
end

#primary_keyObject

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

#usernameObject

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

.optionsObject



56
57
58
59
60
61
62
63
# File 'lib/mince_mongo_db/config.rb', line 56

def self.options
  {
    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.options=(new_options)
  whitelist_keys(new_options).each do |key, value|
    send("#{key}=", value)
  end
end

.test_env_numberObject

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(options)
  options.select{|key, value| OPTIONS.include?(key.to_s) }
end