Module: MongoMapper::Document::InstanceMethods
- Defined in:
- lib/mongo_mapper/document.rb
Instance Method Summary collapse
- #collection ⇒ Object
- #database ⇒ Object
- #delete ⇒ Object
- #destroy ⇒ Object
- #reload ⇒ Object
- #save(options = {}) ⇒ Object
- #save!(options = {}) ⇒ Object
Instance Method Details
#collection ⇒ Object
353 354 355 |
# File 'lib/mongo_mapper/document.rb', line 353 def collection self.class.collection end |
#database ⇒ Object
357 358 359 |
# File 'lib/mongo_mapper/document.rb', line 357 def database self.class.database end |
#delete ⇒ Object
376 377 378 |
# File 'lib/mongo_mapper/document.rb', line 376 def delete self.class.delete(id) unless new? end |
#destroy ⇒ Object
372 373 374 |
# File 'lib/mongo_mapper/document.rb', line 372 def destroy delete end |
#reload ⇒ Object
380 381 382 383 384 385 386 387 388 |
# File 'lib/mongo_mapper/document.rb', line 380 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
361 362 363 364 365 |
# File 'lib/mongo_mapper/document.rb', line 361 def save(={}) .assert_valid_keys(:validate, :safe) .reverse_merge!(:validate => true) ![:validate] || valid? ? create_or_update() : false end |
#save!(options = {}) ⇒ Object
367 368 369 370 |
# File 'lib/mongo_mapper/document.rb', line 367 def save!(={}) .assert_valid_keys(:safe) save() || raise(DocumentNotValid.new(self)) end |