Module: MongoMapper::Document::InstanceMethods
- Defined in:
- lib/mongo_mapper/document.rb
Instance Method Summary collapse
-
#_root_document ⇒ Object
Used by embedded docs to find root easily without if/respond_to? stuff.
- #collection ⇒ Object
- #database ⇒ Object
- #delete ⇒ Object
- #destroy ⇒ Object
- #destroyed? ⇒ Boolean
- #reload ⇒ Object
- #save(options = {}) ⇒ Object
- #save!(options = {}) ⇒ Object
Instance Method Details
#_root_document ⇒ Object
Used by embedded docs to find root easily without if/respond_to? stuff. Documents are always root documents.
334 335 336 |
# File 'lib/mongo_mapper/document.rb', line 334 def _root_document self end |
#collection ⇒ Object
290 291 292 |
# File 'lib/mongo_mapper/document.rb', line 290 def collection self.class.collection end |
#database ⇒ Object
294 295 296 |
# File 'lib/mongo_mapper/document.rb', line 294 def database self.class.database end |
#delete ⇒ Object
313 314 315 316 |
# File 'lib/mongo_mapper/document.rb', line 313 def delete @_destroyed = true self.class.delete(id) unless new? end |
#destroy ⇒ Object
309 310 311 |
# File 'lib/mongo_mapper/document.rb', line 309 def destroy delete end |
#destroyed? ⇒ Boolean
318 319 320 |
# File 'lib/mongo_mapper/document.rb', line 318 def destroyed? @_destroyed == true end |
#reload ⇒ Object
322 323 324 325 326 327 328 329 330 |
# File 'lib/mongo_mapper/document.rb', line 322 def reload if attrs = collection.find_one({:_id => _id}) self.class.associations.each { |name, assoc| send(name).reset if respond_to?(name) } self.attributes = attrs self else raise DocumentNotFound, "Document match #{_id.inspect} does not exist in #{collection.name} collection" end end |
#save(options = {}) ⇒ Object
298 299 300 301 302 |
# File 'lib/mongo_mapper/document.rb', line 298 def save(={}) .assert_valid_keys(:validate, :safe) .reverse_merge!(:validate => true) ![:validate] || valid? ? create_or_update() : false end |
#save!(options = {}) ⇒ Object
304 305 306 307 |
# File 'lib/mongo_mapper/document.rb', line 304 def save!(={}) .assert_valid_keys(:safe) save() || raise(DocumentNotValid.new(self)) end |