Class: Mongoid::Config
- Includes:
- Singleton
- Defined in:
- lib/mongoid/config.rb
Overview
:nodoc
Instance Attribute Summary collapse
-
#allow_dynamic_fields ⇒ Object
Returns the value of attribute allow_dynamic_fields.
-
#parameterize_keys ⇒ Object
Returns the value of attribute parameterize_keys.
-
#persist_in_safe_mode ⇒ Object
Returns the value of attribute persist_in_safe_mode.
-
#persist_types ⇒ Object
Returns the value of attribute persist_types.
-
#raise_not_found_error ⇒ Object
Returns the value of attribute raise_not_found_error.
-
#reconnect_time ⇒ Object
Returns the value of attribute reconnect_time.
-
#use_object_ids ⇒ Object
Returns the value of attribute use_object_ids.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
Defaults the configuration options to true.
-
#master ⇒ Object
(also: #database)
Returns the master database, or if none has been set it will raise an error.
-
#master=(db) ⇒ Object
(also: #database=)
Sets the Mongo::DB master database to be used.
-
#slaves ⇒ Object
Returns the slave databases, or if none has been set nil.
-
#slaves=(dbs) ⇒ Object
Sets the Mongo::DB slave databases to be used.
Constructor Details
#initialize ⇒ Config
Defaults the configuration options to true.
16 17 18 19 20 21 22 23 24 |
# File 'lib/mongoid/config.rb', line 16 def initialize @allow_dynamic_fields = true @parameterize_keys = true @persist_in_safe_mode = true @persist_types = true @raise_not_found_error = true @reconnect_time = 3 @use_object_ids = false end |
Instance Attribute Details
#allow_dynamic_fields ⇒ Object
Returns the value of attribute allow_dynamic_fields.
6 7 8 |
# File 'lib/mongoid/config.rb', line 6 def allow_dynamic_fields @allow_dynamic_fields end |
#parameterize_keys ⇒ Object
Returns the value of attribute parameterize_keys.
6 7 8 |
# File 'lib/mongoid/config.rb', line 6 def parameterize_keys @parameterize_keys end |
#persist_in_safe_mode ⇒ Object
Returns the value of attribute persist_in_safe_mode.
6 7 8 |
# File 'lib/mongoid/config.rb', line 6 def persist_in_safe_mode @persist_in_safe_mode end |
#persist_types ⇒ Object
Returns the value of attribute persist_types.
6 7 8 |
# File 'lib/mongoid/config.rb', line 6 def persist_types @persist_types end |
#raise_not_found_error ⇒ Object
Returns the value of attribute raise_not_found_error.
6 7 8 |
# File 'lib/mongoid/config.rb', line 6 def raise_not_found_error @raise_not_found_error end |
#reconnect_time ⇒ Object
Returns the value of attribute reconnect_time.
6 7 8 |
# File 'lib/mongoid/config.rb', line 6 def reconnect_time @reconnect_time end |
#use_object_ids ⇒ Object
Returns the value of attribute use_object_ids.
6 7 8 |
# File 'lib/mongoid/config.rb', line 6 def use_object_ids @use_object_ids end |
Instance Method Details
#master ⇒ Object Also known as: database
Returns the master database, or if none has been set it will raise an error.
Example:
Config.master
Returns:
The master Mongo::DB
51 52 53 |
# File 'lib/mongoid/config.rb', line 51 def master @master || (raise Errors::InvalidDatabase.new(nil)) end |
#master=(db) ⇒ Object Also known as: database=
Sets the Mongo::DB master database to be used. If the object trying to me set is not a valid Mongo::DB
, then an error will be raise.
Example:
Config.master = Mongo::Connection.db("test")
Returns:
The Master DB instance.
36 37 38 39 |
# File 'lib/mongoid/config.rb', line 36 def master=(db) raise Errors::InvalidDatabase.new(db) unless db.kind_of?(Mongo::DB) @master = db end |
#slaves ⇒ Object
Returns the slave databases, or if none has been set nil
Example:
Config.slaves
Returns:
The slave Mongo::DBs
82 83 84 |
# File 'lib/mongoid/config.rb', line 82 def slaves @slaves end |
#slaves=(dbs) ⇒ Object
Sets the Mongo::DB slave databases to be used. If the objects trying to me set are not valid Mongo::DBs
, then an error will be raise.
Example:
Config.slaves = [ Mongo::Connection.db("test") ]
Returns:
The slaves DB instances.
68 69 70 71 |
# File 'lib/mongoid/config.rb', line 68 def slaves=(dbs) dbs.each { |db| raise Errors::InvalidDatabase.new(db) unless db.kind_of?(Mongo::DB) } @slaves = dbs end |