Module: Ripple::Document::Persistence::InstanceMethods
- Defined in:
- ripple/lib/ripple/document/persistence.rb
Instance Attribute Summary (collapse)
Instance Method Summary (collapse)
-
- (Object) destroy
Deletes the document from Riak and freezes this instance.
-
- (Object) freeze
Freezes the document, preventing further modification.
-
- (Boolean) new?
Determines whether this is a new document.
- - (Object) really_save(*args)
-
- (Object) reload
Reloads the document from Riak.
-
- (true, false) save(*args)
Saves the document in Riak.
-
- (true, false) update_attribute(attribute, value)
Updates a single attribute and then saves the document NOTE: THIS SKIPS VALIDATIONS! Use with caution.
-
- (true, false) update_attributes(attrs)
Writes new attributes and then saves the document.
Instance Attribute Details
- (Object) robject
110 111 112 113 114 |
# File 'ripple/lib/ripple/document/persistence.rb', line 110 def robject @robject ||= Riak::RObject.new(self.class.bucket, key).tap do |obj| obj.content_type = "application/json" end end |
Instance Method Details
- (Object) destroy
Deletes the document from Riak and freezes this instance
95 96 97 98 99 100 101 |
# File 'ripple/lib/ripple/document/persistence.rb', line 95 def destroy robject.delete(self.class.quorums.slice(:rw)) unless new? freeze true rescue Riak::FailedRequest false end |
- (Object) freeze
Freezes the document, preventing further modification.
104 105 106 |
# File 'ripple/lib/ripple/document/persistence.rb', line 104 def freeze @attributes.freeze; super end |
- (Boolean) new?
Determines whether this is a new document.
51 52 53 |
# File 'ripple/lib/ripple/document/persistence.rb', line 51 def new? @new || false end |
- (Object) really_save(*args)
76 77 78 79 80 81 82 83 |
# File 'ripple/lib/ripple/document/persistence.rb', line 76 def really_save(*args) robject.key = key if robject.key != key robject.data = attributes_for_persistence robject.store(self.class.quorums.slice(:w,:dw)) self.key = robject.key @new = false true end |
- (Object) reload
Reloads the document from Riak
87 88 89 90 91 92 |
# File 'ripple/lib/ripple/document/persistence.rb', line 87 def reload return self if new? robject.reload(:force => true) self.__send__(:attributes=, @robject.data.except("_type"), false) self end |
- (true, false) save(*args)
Saves the document in Riak.
72 73 74 |
# File 'ripple/lib/ripple/document/persistence.rb', line 72 def save(*args) really_save(*args) end |
- (true, false) update_attribute(attribute, value)
Updates a single attribute and then saves the document NOTE: THIS SKIPS VALIDATIONS! Use with caution.
58 59 60 61 |
# File 'ripple/lib/ripple/document/persistence.rb', line 58 def update_attribute(attribute, value) send("#{attribute}=", value) save(:validate => false) end |
- (true, false) update_attributes(attrs)
Writes new attributes and then saves the document
65 66 67 68 |
# File 'ripple/lib/ripple/document/persistence.rb', line 65 def update_attributes(attrs) self.attributes = attrs save end |