Class: CouchProxy::Rack::DesignDoc
- Inherits:
-
Base
- Object
- Base
- CouchProxy::Rack::DesignDoc
show all
- Defined in:
- lib/couchproxy/rack/design_doc.rb
Constant Summary
collapse
- QUERY =
/_view\/.+$/
- INFO =
/\/_info$/
- VIEW_NAME =
/_view\/(.*)$/
- REDUCE_ERROR =
'{"error":"query_parse_error","reason":"Invalid URL parameter `reduce` for map view."}'.freeze
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
61
62
63
64
65
66
67
68
69
|
# File 'lib/couchproxy/rack/design_doc.rb', line 61
def delete
proxy_to_all_partitions do |responses|
head = .tap do |h|
h['ETag'] = responses.first..etag
end
send_response(responses.first..status,
head, responses.first.response)
end
end
|
#get ⇒ Object
11
12
13
14
15
16
17
|
# File 'lib/couchproxy/rack/design_doc.rb', line 11
def get
case request.path_info
when QUERY then query
when INFO then info
else proxy_to_any_partition
end
end
|
#head ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/couchproxy/rack/design_doc.rb', line 19
def head
case request.path_info
when QUERY
proxy_to_all_partitions do |responses|
etags = responses.map {|r| r..etag }
head = .tap do |h|
h['ETag'] = etag(etags)
end
send_response(responses.first..status, head, [])
end
else proxy_to_any_partition
end
end
|
#post ⇒ Object
33
34
35
|
# File 'lib/couchproxy/rack/design_doc.rb', line 33
def post
end
|
#put ⇒ Object
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/design_doc.rb', line 37
def put
partition = cluster.any_partition
request.rewrite_proxy_url!(partition.num)
uri = "#{partition.node.uri}#{@request.fullpath}"
http = EM::HttpRequest.new(uri).put(:head => ,
:body => request.content)
http.callback do |res|
head =
sender = proc do
send_response(res..status, head, [res.response])
end
if success?(res)
head.tap do |h|
h['ETag'] = res..etag
h['Location'] = rewrite_location(res..location)
end
replicate_to_all_partitions(partition, request.doc_id, &sender)
else
sender.call
end
end
http.errback { send_error_response }
end
|