Class: EventMachine::Couchdb::Server
- Inherits:
-
Base
- Object
- Base
- EventMachine::Couchdb::Server
show all
- Defined in:
- lib/em-couchdb-request/server.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, opts = {}) ⇒ Server
Returns a new instance of Server.
8
9
10
11
12
|
# File 'lib/em-couchdb-request/server.rb', line 8
def initialize(uri, opts={})
@uri = uri
@connect_options = opts[:connect_options] || {}
@request_options = opts[:request_options] || {}
end
|
Instance Attribute Details
#uri ⇒ Object
Returns the value of attribute uri.
6
7
8
|
# File 'lib/em-couchdb-request/server.rb', line 6
def uri
@uri
end
|
Instance Method Details
#all_dbs(&callback) ⇒ Object
20
21
22
|
# File 'lib/em-couchdb-request/server.rb', line 20
def all_dbs(&callback)
new_http_request :url => "_all_dbs", &callback
end
|
#create_db(db_name, &callback) ⇒ Object
28
29
30
|
# File 'lib/em-couchdb-request/server.rb', line 28
def create_db(db_name, &callback)
new_http_request :url => db_name, :method => :put, &callback
end
|
#delete_db(db_name, &callback) ⇒ Object
32
33
34
|
# File 'lib/em-couchdb-request/server.rb', line 32
def delete_db(db_name, &callback)
new_http_request :url => db_name, :method => :delete, &callback
end
|
#em_database(db_name) ⇒ Object
14
15
16
|
# File 'lib/em-couchdb-request/server.rb', line 14
def em_database(db_name)
Database.new @uri, db_name, {:connect_options => @connect_options, :request_options => @request_options}
end
|
#ensure_db(db_name, &callback) ⇒ Object
36
37
38
39
40
41
42
43
44
|
# File 'lib/em-couchdb-request/server.rb', line 36
def ensure_db(db_name, &callback)
get_db(db_name) { |resp|
if resp['db_name']
callback.call
else
create_db(db_name, &callback)
end
}
end
|
#get_db(db_name, &callback) ⇒ Object
24
25
26
|
# File 'lib/em-couchdb-request/server.rb', line 24
def get_db(db_name, &callback)
new_http_request :url => db_name, &callback
end
|