Module: CouchCrud
- Defined in:
- lib/couch_crud/errors.rb,
lib/couch_crud.rb,
lib/couch_crud/version.rb
Overview
- Author
-
Iain Gray ([email protected])
- Copyright
-
Copyright © 2015 Quantdeck Systems Ltd
- License
-
Apache License Version 2.0
Defined Under Namespace
Classes: DocConflictError, DocNotFoundError, Error
Constant Summary
collapse
- VERSION =
"0.1.0"
Instance Method Summary
collapse
Instance Method Details
#create_document(doc) ⇒ Object
34
35
36
37
38
39
40
|
# 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) ⇒ Object
78
79
80
81
82
83
84
|
# 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) ⇒ Boolean
91
92
93
94
95
96
97
98
|
# 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) ⇒ Object
50
51
52
53
54
55
56
|
# 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) ⇒ Object
66
67
68
69
|
# File 'lib/couch_crud.rb', line 66
def update_document(doc)
raise DocNotFoundError unless document_exists?(doc['_id'])
connection.save_doc(doc)
end
|