Module: MongoMapper::Document::InstanceMethods
- Defined in:
- lib/mongomapper/document.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
- #collection ⇒ Object
- #destroy ⇒ Object
- #id ⇒ Object
- #new? ⇒ Boolean
- #save ⇒ Object
- #save! ⇒ Object
- #update_attributes(attrs = {}) ⇒ Object
Instance Method Details
#==(other) ⇒ Object
237 238 239 |
# File 'lib/mongomapper/document.rb', line 237 def ==(other) other.is_a?(self.class) && id == other.id end |
#collection ⇒ Object
210 211 212 |
# File 'lib/mongomapper/document.rb', line 210 def collection self.class.collection end |
#destroy ⇒ Object
232 233 234 235 |
# File 'lib/mongomapper/document.rb', line 232 def destroy collection.remove(:_id => id) unless new? freeze end |
#id ⇒ Object
241 242 243 |
# File 'lib/mongomapper/document.rb', line 241 def id read_attribute('_id') end |
#new? ⇒ Boolean
214 215 216 |
# File 'lib/mongomapper/document.rb', line 214 def new? read_attribute('_id').blank? || self.class.find_by_id(id).blank? end |
#save ⇒ Object
218 219 220 |
# File 'lib/mongomapper/document.rb', line 218 def save create_or_update end |
#save! ⇒ Object
222 223 224 |
# File 'lib/mongomapper/document.rb', line 222 def save! create_or_update || raise(DocumentNotValid.new(self)) end |
#update_attributes(attrs = {}) ⇒ Object
226 227 228 229 230 |
# File 'lib/mongomapper/document.rb', line 226 def update_attributes(attrs={}) self.attributes = attrs save self end |