Class: Humanoid::Config

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

Overview

:nodoc

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Defaults the configuration options to true.



15
16
17
18
19
20
21
22
# File 'lib/humanoid/config.rb', line 15

def initialize
  @allow_dynamic_fields = true
  @parameterize_keys = true
  @persist_in_safe_mode = 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/humanoid/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/humanoid/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/humanoid/config.rb', line 6

def persist_in_safe_mode
  @persist_in_safe_mode
end

#raise_not_found_errorObject

Returns the value of attribute raise_not_found_error.



6
7
8
# File 'lib/humanoid/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/humanoid/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/humanoid/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



49
50
51
# File 'lib/humanoid/config.rb', line 49

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.



34
35
36
37
# File 'lib/humanoid/config.rb', line 34

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



80
81
82
# File 'lib/humanoid/config.rb', line 80

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.



66
67
68
69
# File 'lib/humanoid/config.rb', line 66

def slaves=(dbs)
  dbs.each { |db| raise Errors::InvalidDatabase.new(db) unless db.kind_of?(Mongo::DB) }
  @slaves = dbs
end