Module: MongoMapper::Document::InstanceMethods
- Defined in:
- lib/novelys_mongo_mapper/document.rb
Instance Method Summary collapse
- #collection ⇒ Object
- #database ⇒ Object
- #delete ⇒ Object
- #destroy ⇒ Object
- #reload ⇒ Object
- #save(options = {}) ⇒ Object
- #save!(options = {}) ⇒ Object
- #update_attributes(attrs = {}) ⇒ Object
- #update_attributes!(attrs = {}) ⇒ Object
Instance Method Details
#collection ⇒ Object
349 350 351 |
# File 'lib/novelys_mongo_mapper/document.rb', line 349 def collection self.class.collection end |
#database ⇒ Object
353 354 355 |
# File 'lib/novelys_mongo_mapper/document.rb', line 353 def database self.class.database end |
#delete ⇒ Object
382 383 384 |
# File 'lib/novelys_mongo_mapper/document.rb', line 382 def delete self.class.delete(id) unless new? end |
#destroy ⇒ Object
378 379 380 |
# File 'lib/novelys_mongo_mapper/document.rb', line 378 def destroy delete end |
#reload ⇒ Object
386 387 388 389 390 391 392 393 394 |
# File 'lib/novelys_mongo_mapper/document.rb', line 386 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
357 358 359 360 361 |
# File 'lib/novelys_mongo_mapper/document.rb', line 357 def save(={}) .assert_valid_keys(:validate, :safe) .reverse_merge!(:validate => true) ![:validate] || valid? ? create_or_update() : false end |
#save!(options = {}) ⇒ Object
363 364 365 366 |
# File 'lib/novelys_mongo_mapper/document.rb', line 363 def save!(={}) .assert_valid_keys(:safe) save() || raise(DocumentNotValid.new(self)) end |
#update_attributes(attrs = {}) ⇒ Object
368 369 370 371 |
# File 'lib/novelys_mongo_mapper/document.rb', line 368 def update_attributes(attrs={}) self.attributes = attrs save end |
#update_attributes!(attrs = {}) ⇒ Object
373 374 375 376 |
# File 'lib/novelys_mongo_mapper/document.rb', line 373 def update_attributes!(attrs={}) self.attributes = attrs save! end |