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

Returns a new instance of Config.



8
9
10
11
# File 'lib/mongoid/config.rb', line 8

def initialize
  @raise_not_found_error = true
  @allow_dynamic_fields = true
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

#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

Instance Method Details

#databaseObject

Returns the Mongo::DB to use or raise an error if none was set.



22
23
24
# File 'lib/mongoid/config.rb', line 22

def database
  @database || (raise Errors::InvalidDatabase.new("No database has been set, please use Mongoid.database="))
end

#database=(db) ⇒ Object

Sets the Mongo::DB to be used.



14
15
16
17
18
19
# File 'lib/mongoid/config.rb', line 14

def database=(db)
  raise Errors::InvalidDatabase.new(
      "Database should be a Mongo::DB, not #{db.class.name}"
    ) unless db.kind_of?(Mongo::DB)
  @database = db
end