Class: Mongoid::Config

Inherits:
Object show all
Includes:
Singleton
Defined in:
lib/mongoid/config.rb

Overview

:nodoc

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

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_fieldsObject

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_keysObject

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_modeObject

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_typesObject

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_errorObject

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_timeObject

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_idsObject

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

#masterObject 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

#slavesObject

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