Class: EventMachine::Couchdb::Database
- Inherits:
-
Base
- Object
- Base
- EventMachine::Couchdb::Database
show all
- Defined in:
- lib/em-couchdb-request/database.rb
Constant Summary
Constants inherited
from Base
Base::REQUEST_OPTIONS
Instance Attribute Summary collapse
Attributes inherited from Base
#connect_options, #request_options
Instance Method Summary
collapse
Methods inherited from Base
#log
Constructor Details
#initialize(uri, name, opts = {}) ⇒ Database
Returns a new instance of Database.
8
9
10
11
12
13
|
# File 'lib/em-couchdb-request/database.rb', line 8
def initialize(uri, name, opts={})
@uri = uri
@name = name
@connect_options = opts[:connect_options] || {}
@request_options = opts[:request_options] || {}
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
6
7
8
|
# File 'lib/em-couchdb-request/database.rb', line 6
def name
@name
end
|
Instance Method Details
#all_docs(&callback) ⇒ Object
19
20
21
|
# File 'lib/em-couchdb-request/database.rb', line 19
def all_docs(&callback)
new_http_request :url => "_all_docs", &callback
end
|
#base_uri ⇒ Object
15
16
17
|
# File 'lib/em-couchdb-request/database.rb', line 15
def base_uri
[@uri, @name].join('/')
end
|
#changes(opts, &stream) ⇒ Object
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/em-couchdb-request/database.rb', line 36
def changes(opts, &stream)
http = new_http_request(:url => "_changes?#{paramize(opts)}") {}
http.stream { |chunk|
data = JSON.load(chunk) rescue {}
stream.call data
}
http
end
|
#delete_doc(doc, &callback) ⇒ Object
32
33
34
|
# File 'lib/em-couchdb-request/database.rb', line 32
def delete_doc(doc, &callback)
new_http_request :url => "#{doc['id']}?rev=#{doc['rev']}", :method => :delete, &callback
end
|
#doc(doc_id, &callback) ⇒ Object
23
24
25
|
# File 'lib/em-couchdb-request/database.rb', line 23
def doc(doc_id, &callback)
new_http_request :url => doc_id, &callback
end
|
#save_doc(doc, &callback) ⇒ Object
27
28
29
30
|
# File 'lib/em-couchdb-request/database.rb', line 27
def save_doc(doc, &callback)
method = doc['id'] ? :put : :post
new_http_request :url => doc['id'], :method => method, :body => JSON.dump(doc), &callback
end
|