Module: LooseChange::PersistenceClassMethods
- Included in:
- Base
- Defined in:
- lib/loose_change/persistence.rb
Instance Attribute Summary collapse
-
#_attachments ⇒ Object
Returns the value of attribute _attachments.
-
#_id ⇒ Object
Returns the value of attribute _id.
-
#_rev ⇒ Object
Returns the value of attribute _rev.
-
#database ⇒ Object
Returns the value of attribute database.
-
#destroyed ⇒ Object
Returns the value of attribute destroyed.
-
#id ⇒ Object
Returns the value of attribute id.
-
#new_record ⇒ Object
Returns the value of attribute new_record.
Instance Method Summary collapse
-
#destroy ⇒ Object
Destroy the record on CouchDB by sending an HTTP DELETE request.
- #destroyed? ⇒ Boolean
- #new_record? ⇒ Boolean
- #persisted? ⇒ Boolean
-
#save ⇒ Object
Persist the record to CouchDB, including saving of any attachments.
-
#save! ⇒ Object
Persist the record to CouchDB, including saving of any attachments.
Instance Attribute Details
#_attachments ⇒ Object
Returns the value of attribute _attachments.
59 60 61 |
# File 'lib/loose_change/persistence.rb', line 59 def @_attachments end |
#_id ⇒ Object
Returns the value of attribute _id.
59 60 61 |
# File 'lib/loose_change/persistence.rb', line 59 def _id @_id end |
#_rev ⇒ Object
Returns the value of attribute _rev.
59 60 61 |
# File 'lib/loose_change/persistence.rb', line 59 def _rev @_rev end |
#database ⇒ Object
Returns the value of attribute database.
59 60 61 |
# File 'lib/loose_change/persistence.rb', line 59 def database @database end |
#destroyed ⇒ Object
Returns the value of attribute destroyed.
59 60 61 |
# File 'lib/loose_change/persistence.rb', line 59 def destroyed @destroyed end |
#id ⇒ Object
Returns the value of attribute id.
59 60 61 |
# File 'lib/loose_change/persistence.rb', line 59 def id @id end |
#new_record ⇒ Object
Returns the value of attribute new_record.
59 60 61 |
# File 'lib/loose_change/persistence.rb', line 59 def new_record @new_record end |
Instance Method Details
#destroy ⇒ Object
Destroy the record on CouchDB by sending an HTTP DELETE request.
89 90 91 92 93 94 95 |
# File 'lib/loose_change/persistence.rb', line 89 def destroy _run_destroy_callbacks do raise DatabaseNotSet.new("Cannot destroy without database set.") unless @database result = JSON.parse(RestClient.delete("#{ database.uri }/#{ CGI.escape(id) }?rev=#{ @_rev }", default_headers))['ok'] @destroyed = result end end |
#destroyed? ⇒ Boolean
62 |
# File 'lib/loose_change/persistence.rb', line 62 def destroyed?() @destroyed end |
#new_record? ⇒ Boolean
61 |
# File 'lib/loose_change/persistence.rb', line 61 def new_record?() @new_record end |
#persisted? ⇒ Boolean
64 65 66 |
# File 'lib/loose_change/persistence.rb', line 64 def persisted? !(new_record? || destroyed?) end |
#save ⇒ Object
Persist the record to CouchDB, including saving of any attachments.
69 70 71 72 73 74 75 |
# File 'lib/loose_change/persistence.rb', line 69 def save if new_record? _run_create_callbacks { _run_save_callbacks { _save } } else _run_save_callbacks { _save } end end |
#save! ⇒ Object
Persist the record to CouchDB, including saving of any attachments. If the record is not valid, a RecordInvalid
error will be thrown.
80 81 82 83 84 85 86 |
# File 'lib/loose_change/persistence.rb', line 80 def save! if new_record? _run_create_callbacks { _run_save_callbacks { _save! } } else _run_save_callbacks { _save! } end end |