Module: SimplyStored::InstanceMethods
- Defined in:
- lib/simply_stored/instance_methods.rb
Instance Method Summary collapse
- #==(other) ⇒ Object
- #attributes=(attr) ⇒ Object
- #deleted? ⇒ Boolean
- #destroy(override_soft_delete = false) ⇒ Object (also: #delete)
- #eql?(other) ⇒ Boolean
- #initialize(attributes = {}, &blk) ⇒ Object
- #reload ⇒ Object
- #save(validate = true) ⇒ Object
- #save! ⇒ Object
- #update_attributes(attributes = {}) ⇒ Object
Instance Method Details
#==(other) ⇒ Object
9 10 11 |
# File 'lib/simply_stored/instance_methods.rb', line 9 def ==(other) other.kind_of?(SimplyStored::Couch) && other._id == _id && other._rev == _rev end |
#attributes=(attr) ⇒ Object
56 57 58 |
# File 'lib/simply_stored/instance_methods.rb', line 56 def attributes=(attr) super(_remove_protected_attributes(attr)) end |
#deleted? ⇒ Boolean
71 72 73 74 75 76 77 |
# File 'lib/simply_stored/instance_methods.rb', line 71 def deleted? if self.class.soft_deleting_enabled? !send(self.class.soft_delete_attribute).nil? else false end end |
#destroy(override_soft_delete = false) ⇒ Object Also known as: delete
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/simply_stored/instance_methods.rb', line 33 def destroy(override_soft_delete=false) check_and_destroy_dependents if self.class.soft_deleting_enabled? && !override_soft_delete # soft-delete _mark_as_deleted else if self.class.soft_deleting_enabled? && deleted? # really deleting a previously soft-deleted object - skipping callbacks CouchPotato.database.destroy_document(self, false) else # deleting a normal object or a soft-deletable object that was not soft-deleted before CouchPotato.database.destroy_document(self, true) end freeze end self end |
#eql?(other) ⇒ Boolean
13 14 15 |
# File 'lib/simply_stored/instance_methods.rb', line 13 def eql?(other) self.==(other) end |
#initialize(attributes = {}, &blk) ⇒ Object
4 5 6 7 |
# File 'lib/simply_stored/instance_methods.rb', line 4 def initialize(attributes = {}, &blk) super(_remove_protected_attributes(attributes)) blk.call(self) if blk end |
#reload ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/simply_stored/instance_methods.rb', line 60 def reload instance = self.class.find(_id, :with_deleted => true) instance.attributes.each do |attribute, value| send "#{attribute}=", value end self._rev = instance._rev reset_dirty_attributes reset_association_caches self end |
#save(validate = true) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/simply_stored/instance_methods.rb', line 17 def save(validate = true) retry_on_conflict do retry_on_connection_error do CouchPotato.database.save_document(self, validate) end end end |
#save! ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/simply_stored/instance_methods.rb', line 25 def save! retry_on_conflict do retry_on_connection_error do CouchPotato.database.save_document!(self) end end end |
#update_attributes(attributes = {}) ⇒ Object
51 52 53 54 |
# File 'lib/simply_stored/instance_methods.rb', line 51 def update_attributes(attributes = {}) self.attributes = attributes save end |