Module: Couch::Database::Base
- Included in:
- Couch::Database
- Defined in:
- lib/couch/database.rb
Overview
– document CRUD methods
Instance Method Summary collapse
- #create(doc) ⇒ Object
- #destroy(doc) ⇒ Object
-
#read(id) ⇒ Object
read couch document from server.
- #update(doc) ⇒ Object
Instance Method Details
#create(doc) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/couch/database.rb', line 43 def create(doc) raise unless doc.new_record? doc.id ||= UUID.new.generate r = put(doc.id, doc) doc.send :update_rev, r[:rev] end |
#destroy(doc) ⇒ Object
64 65 66 |
# File 'lib/couch/database.rb', line 64 def destroy(doc) delete("#{doc.id}?rev=#{doc.rev}") end |
#read(id) ⇒ Object
read couch document from server
54 55 56 57 |
# File 'lib/couch/database.rb', line 54 def read(id) r = get(id) Couch::Document.instantiate r end |
#update(doc) ⇒ Object
59 60 61 62 |
# File 'lib/couch/database.rb', line 59 def update(doc) r = put(doc.id, doc) doc.send :update_rev, r[:rev] end |