Class: CouchProxy::Rack::Database
- Inherits:
-
Base
- Object
- Base
- CouchProxy::Rack::Database
show all
- Defined in:
- lib/couchproxy/rack/database.rb
Constant Summary
Constants inherited
from Base
Base::APPLICATION_JSON, Base::DESIGN_ID, Base::INVALID_JSON, Base::METHODS, Base::SERVER_VERSION, Base::TEXT_PLAIN
Instance Attribute Summary
Attributes inherited from Base
#cluster, #request
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #method_missing, #proxy_to, #proxy_to_all_nodes, #proxy_to_all_partitions, #proxy_to_any_node, #proxy_to_any_partition, #replicate_to_all_partitions, #rewrite_location, #send_error_response, #send_response, #uuids
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class CouchProxy::Rack::Base
Instance Method Details
#delete ⇒ Object
71
72
73
74
75
76
|
# File 'lib/couchproxy/rack/database.rb', line 71
def delete
proxy_to_all_partitions do |responses|
send_response(responses.first..status,
, responses.first.response)
end
end
|
#get ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/couchproxy/rack/database.rb', line 6
def get
proxy_to_all_partitions do |responses|
doc = {
:db_name => request.db_name,
:disk_size => 0,
:doc_count => 0,
:doc_del_count => 0,
:compact_running => false,
:compact_running_partitions => []}
responses.each do |res|
result = JSON.parse(res.response)
doc[:compact_running] ||= result['compact_running']
doc[:compact_running_partitions] << result['db_name'] if result['compact_running']
%w[disk_size doc_count doc_del_count].each do |k|
doc[k.to_sym] += result[k]
end
doc[:compact_running_partitions].sort!
end
send_response(responses.first..status,
, [doc.to_json])
end
end
|
#head ⇒ Object
78
79
80
|
# File 'lib/couchproxy/rack/database.rb', line 78
def head
end
|
#post ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/couchproxy/rack/database.rb', line 30
def post
begin
doc = JSON.parse(request.content)
rescue
send_response(400, , INVALID_JSON)
return
end
unless doc['_id']
uuids(1) do |uuids|
if uuids
doc['_id'] = uuids.first
partition = cluster.partition(doc['_id'])
request.content = doc.to_json
request.rewrite_proxy_url!(partition.num)
proxy_to(partition.node)
else
send_error_response
end
end
else
partition = cluster.partition(doc['_id'])
request.rewrite_proxy_url!(partition.num)
proxy_to(partition.node) do
if design?(doc['_id'])
replicate_to_all_partitions(partition, doc['_id'])
end
end
end
end
|
#put ⇒ Object
61
62
63
64
65
66
67
68
69
|
# File 'lib/couchproxy/rack/database.rb', line 61
def put
proxy_to_all_partitions do |responses|
res = responses.first
head = .tap do |h|
h['Location'] = rewrite_location(res..location)
end
send_response(res..status, head, res.response)
end
end
|