Module: MongoMapper
- Defined in:
- lib/mongo_mapper.rb,
lib/mongo_mapper/query.rb,
lib/mongo_mapper/plugins.rb,
lib/mongo_mapper/document.rb,
lib/mongo_mapper/plugins/keys.rb,
lib/mongo_mapper/support/find.rb,
lib/mongo_mapper/plugins/clone.rb,
lib/mongo_mapper/plugins/dirty.rb,
lib/mongo_mapper/plugins/rails.rb,
lib/mongo_mapper/plugins/logger.rb,
lib/mongo_mapper/plugins/inspect.rb,
lib/mongo_mapper/plugins/equality.rb,
lib/mongo_mapper/embedded_document.rb,
lib/mongo_mapper/plugins/callbacks.rb,
lib/mongo_mapper/plugins/protected.rb,
lib/mongo_mapper/plugins/pagination.rb,
lib/mongo_mapper/plugins/descendants.rb,
lib/mongo_mapper/plugins/validations.rb,
lib/mongo_mapper/plugins/associations.rb,
lib/mongo_mapper/plugins/identity_map.rb,
lib/mongo_mapper/plugins/serialization.rb,
lib/mongo_mapper/plugins/pagination/proxy.rb,
lib/mongo_mapper/plugins/associations/base.rb,
lib/mongo_mapper/plugins/associations/proxy.rb,
lib/mongo_mapper/support/descendant_appends.rb,
lib/mongo_mapper/plugins/associations/one_proxy.rb,
lib/mongo_mapper/plugins/associations/collection.rb,
lib/mongo_mapper/plugins/associations/in_array_proxy.rb,
lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb,
lib/mongo_mapper/plugins/associations/embedded_collection.rb,
lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb,
lib/mongo_mapper/plugins/associations/many_documents_proxy.rb,
lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb,
lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb,
lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb,
lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb,
lib/mongo_mapper/support.rb
Defined Under Namespace
Modules: Document, EmbeddedDocument, Plugins, Support
Classes: DocumentNotFound, DocumentNotValid, KeyNotFound, MongoMapperError, Query
Class Method Summary
collapse
Class Method Details
81
82
83
84
|
# File 'lib/mongo_mapper.rb', line 81
def self.config
raise 'Set config before connecting. MongoMapper.config = {...}' unless defined?(@@config)
@@config
end
|
.config=(hash) ⇒ Object
77
78
79
|
# File 'lib/mongo_mapper.rb', line 77
def self.config=(hash)
@@config = hash
end
|
.connect(environment, options = {}) ⇒ Object
86
87
88
89
90
91
92
93
|
# File 'lib/mongo_mapper.rb', line 86
def self.connect(environment, options={})
raise 'Set config before connecting. MongoMapper.config = {...}' if config.blank?
MongoMapper.connection = Mongo::Connection.new(config[environment]['host'], config[environment]['port'], options)
MongoMapper.database = config[environment]['database']
if config[environment]['username'].present? && config[environment]['password'].present?
MongoMapper.database.authenticate(config[environment]['username'], config[environment]['password'])
end
end
|
.connection ⇒ Object
48
49
50
|
# File 'lib/mongo_mapper.rb', line 48
def self.connection
@@connection ||= Mongo::Connection.new
end
|
.connection=(new_connection) ⇒ Object
53
54
55
|
# File 'lib/mongo_mapper.rb', line 53
def self.connection=(new_connection)
@@connection = new_connection
end
|
69
70
71
72
73
74
75
|
# File 'lib/mongo_mapper.rb', line 69
def self.database
if @@database_name.blank?
raise 'You forgot to set the default database name: MongoMapper.database = "foobar"'
end
@@database ||= MongoMapper.connection.db(@@database_name)
end
|
.database=(name) ⇒ Object
63
64
65
66
|
# File 'lib/mongo_mapper.rb', line 63
def self.database=(name)
@@database = nil
@@database_name = name
end
|
.handle_passenger_forking ⇒ Object
102
103
104
105
106
107
108
|
# File 'lib/mongo_mapper.rb', line 102
def self.handle_passenger_forking
if defined?(PhusionPassenger)
PhusionPassenger.on_event(:starting_worker_process) do |forked|
connection.connect_to_master if forked
end
end
end
|
58
59
60
|
# File 'lib/mongo_mapper.rb', line 58
def self.logger
connection.logger
end
|
.normalize_object_id(value) ⇒ Object
This method is part of a private API.
You should avoid using this method if possible, as it may be removed or be changed in the future.
121
122
123
|
# File 'lib/mongo_mapper.rb', line 121
def self.normalize_object_id(value)
value.is_a?(String) ? Mongo::ObjectID.from_string(value) : value
end
|
.setup(config, environment, options = {}) ⇒ Object
95
96
97
98
99
100
|
# File 'lib/mongo_mapper.rb', line 95
def self.setup(config, environment, options={})
using_passenger = options.delete(:passenger)
handle_passenger_forking if using_passenger
self.config = config
connect(environment, options)
end
|
.time_class ⇒ Object
This method is part of a private API.
You should avoid using this method if possible, as it may be removed or be changed in the future.
116
117
118
|
# File 'lib/mongo_mapper.rb', line 116
def self.time_class
use_time_zone? ? Time.zone : Time
end
|
.use_time_zone? ⇒ Boolean
This method is part of a private API.
You should avoid using this method if possible, as it may be removed or be changed in the future.
111
112
113
|
# File 'lib/mongo_mapper.rb', line 111
def self.use_time_zone?
Time.respond_to?(:zone) && Time.zone ? true : false
end
|