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.
-
#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.
-
#use_utc ⇒ Object
(also: #use_utc?)
Returns whether times are return from the database in UTC.
Instance Method Summary collapse
-
#from_hash(settings) ⇒ Object
Confiure mongoid from a hash that was usually parsed out of yml.
-
#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.
-
#reset ⇒ Object
Reset the configuration options to the defaults.
-
#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.
17 18 19 |
# File 'lib/mongoid/config.rb', line 17 def initialize reset end |
Instance Attribute Details
#allow_dynamic_fields ⇒ Object
Returns the value of attribute allow_dynamic_fields.
8 9 10 |
# File 'lib/mongoid/config.rb', line 8 def allow_dynamic_fields @allow_dynamic_fields end |
#parameterize_keys ⇒ Object
Returns the value of attribute parameterize_keys.
8 9 10 |
# File 'lib/mongoid/config.rb', line 8 def parameterize_keys @parameterize_keys end |
#persist_in_safe_mode ⇒ Object
Returns the value of attribute persist_in_safe_mode.
8 9 10 |
# File 'lib/mongoid/config.rb', line 8 def persist_in_safe_mode @persist_in_safe_mode end |
#raise_not_found_error ⇒ Object
Returns the value of attribute raise_not_found_error.
8 9 10 |
# File 'lib/mongoid/config.rb', line 8 def raise_not_found_error @raise_not_found_error end |
#reconnect_time ⇒ Object
Returns the value of attribute reconnect_time.
8 9 10 |
# File 'lib/mongoid/config.rb', line 8 def reconnect_time @reconnect_time end |
#use_object_ids ⇒ Object
Returns the value of attribute use_object_ids.
8 9 10 |
# File 'lib/mongoid/config.rb', line 8 def use_object_ids @use_object_ids end |
#use_utc ⇒ Object Also known as: use_utc?
Returns whether times are return from the database in UTC. If this setting is false, then times will be returned in the local time zone.
Example:
Config.use_utc
Returns:
A boolean
46 47 48 |
# File 'lib/mongoid/config.rb', line 46 def use_utc @use_utc end |
Instance Method Details
#from_hash(settings) ⇒ Object
Confiure mongoid from a hash that was usually parsed out of yml.
Example:
Mongoid::Config.instance.from_hash({})
116 117 118 119 120 121 122 |
# File 'lib/mongoid/config.rb', line 116 def from_hash(settings) _master(settings) _slaves(settings) settings.except("database").each_pair do |name, value| send("#{name}=", value) if respond_to?(name) end end |
#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
74 75 76 |
# File 'lib/mongoid/config.rb', line 74 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 be set is not a valid Mongo::DB
, then an error will be raised.
Example:
Config.master = Mongo::Connection.db("test")
Returns:
The Master DB instance.
59 60 61 62 |
# File 'lib/mongoid/config.rb', line 59 def master=(db) check_database!(db) @master = db end |
#reset ⇒ Object
Reset the configuration options to the defaults.
Example:
config.reset
129 130 131 132 133 134 135 136 137 |
# File 'lib/mongoid/config.rb', line 129 def reset @allow_dynamic_fields = true @parameterize_keys = true @persist_in_safe_mode = true @raise_not_found_error = true @reconnect_time = 3 @use_object_ids = false @time_zone = nil end |
#slaves ⇒ Object
Returns the slave databases, or if none has been set nil
Example:
Config.slaves
Returns:
The slave Mongo::DBs
107 108 109 |
# File 'lib/mongoid/config.rb', line 107 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.
91 92 93 94 95 96 |
# File 'lib/mongoid/config.rb', line 91 def slaves=(dbs) dbs.each do |db| check_database!(db) end @slaves = dbs end |