module CouchCrud

Author

Iain Gray (support@quantdeck.com)

Copyright

Copyright © 2015 Quantdeck Systems Ltd

License

Apache License Version 2.0

Constants

VERSION

Public Instance Methods

create_document(doc) click to toggle source
# File lib/couch_crud.rb, line 34
def create_document(doc)     
  if !doc['_id'].nil? && document_exists?(doc['_id']) then
    raise DocConflictError 
  else
    res = connection.save_doc(doc)
  end        
end
delete_document(id) click to toggle source
# File lib/couch_crud.rb, line 78
def delete_document(id)
  begin
  connection.get(id).destroy
rescue RestClient::ResourceNotFound
  raise DocNotFoundError
end
end
document_exists?(id) click to toggle source
# File lib/couch_crud.rb, line 91
def document_exists?(id)
  begin
    connection.get(id)
  rescue RestClient::ResourceNotFound
    return false
  end  
  true
end
read_document(id) click to toggle source
# File lib/couch_crud.rb, line 50
def read_document(id)
  begin
    doc = connection.get(id)
  rescue RestClient::ResourceNotFound
    raise DocNotFoundError
  end        
end
update_document(doc) click to toggle source
# File lib/couch_crud.rb, line 66
def update_document(doc)        
  raise DocNotFoundError unless document_exists?(doc['_id'])
  connection.save_doc(doc)
end

Private Instance Methods

connection() click to toggle source
# File lib/couch_crud.rb, line 102
def connection
  CouchRest.database(@couchdb_url)
end