design doc ids fixed throughout
This commit is contained in:
parent
d1f8970c84
commit
bca68cf1a9
1 changed files with 11 additions and 11 deletions
|
@ -75,7 +75,7 @@ module CouchRest
|
||||||
|
|
||||||
# GET a document from CouchDB, by id. Returns a Ruby Hash.
|
# GET a document from CouchDB, by id. Returns a Ruby Hash.
|
||||||
def get id
|
def get id
|
||||||
slug = /^_design\/(.*)/ =~ id ? "_design/#{CGI.escape($1)}" : CGI.escape(id)
|
slug = escape_docid(id)
|
||||||
hash = CouchRest.get("#{@root}/#{slug}")
|
hash = CouchRest.get("#{@root}/#{slug}")
|
||||||
doc = if /^_design/ =~ hash["_id"]
|
doc = if /^_design/ =~ hash["_id"]
|
||||||
Design.new(hash)
|
Design.new(hash)
|
||||||
|
@ -87,15 +87,15 @@ module CouchRest
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET an attachment directly from CouchDB
|
# GET an attachment directly from CouchDB
|
||||||
def fetch_attachment doc, name
|
def fetch_attachment docid, name
|
||||||
doc = CGI.escape(doc)
|
slug = escape_docid(docid)
|
||||||
name = CGI.escape(name)
|
name = CGI.escape(name)
|
||||||
RestClient.get "#{@root}/#{doc}/#{name}"
|
RestClient.get "#{@root}/#{slug}/#{name}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# PUT an attachment directly to CouchDB
|
# PUT an attachment directly to CouchDB
|
||||||
def put_attachment doc, name, file, options = {}
|
def put_attachment doc, name, file, options = {}
|
||||||
docid = CGI.escape(doc['_id'])
|
docid = escape_docid(doc['_id'])
|
||||||
name = CGI.escape(name)
|
name = CGI.escape(name)
|
||||||
uri = if doc['_rev']
|
uri = if doc['_rev']
|
||||||
"#{@root}/#{docid}/#{name}?rev=#{doc['_rev']}"
|
"#{@root}/#{docid}/#{name}?rev=#{doc['_rev']}"
|
||||||
|
@ -127,7 +127,7 @@ module CouchRest
|
||||||
bulk_save
|
bulk_save
|
||||||
end
|
end
|
||||||
result = if doc['_id']
|
result = if doc['_id']
|
||||||
slug = CGI.escape(doc['_id'])
|
slug = escape_docid(doc['_id'])
|
||||||
CouchRest.put "#{@root}/#{slug}", doc
|
CouchRest.put "#{@root}/#{slug}", doc
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
|
@ -168,7 +168,7 @@ module CouchRest
|
||||||
def delete doc
|
def delete doc
|
||||||
raise ArgumentError, "_id and _rev required for deleting" unless doc['_id'] && doc['_rev']
|
raise ArgumentError, "_id and _rev required for deleting" unless doc['_id'] && doc['_rev']
|
||||||
|
|
||||||
slug = CGI.escape(doc['_id'])
|
slug = escape_docid(doc['_id'])
|
||||||
CouchRest.delete "#{@root}/#{slug}?rev=#{doc['_rev']}"
|
CouchRest.delete "#{@root}/#{slug}?rev=#{doc['_rev']}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@ module CouchRest
|
||||||
# hash with a '_rev' key
|
# hash with a '_rev' key
|
||||||
def copy doc, dest
|
def copy doc, dest
|
||||||
raise ArgumentError, "_id is required for copying" unless doc['_id']
|
raise ArgumentError, "_id is required for copying" unless doc['_id']
|
||||||
slug = CGI.escape(doc['_id'])
|
slug = escape_docid(doc['_id'])
|
||||||
destination = if dest.respond_to?(:has_key?) && dest['_id'] && dest['_rev']
|
destination = if dest.respond_to?(:has_key?) && dest['_id'] && dest['_rev']
|
||||||
"#{dest['_id']}?rev=#{dest['_rev']}"
|
"#{dest['_id']}?rev=#{dest['_rev']}"
|
||||||
else
|
else
|
||||||
|
@ -191,7 +191,7 @@ module CouchRest
|
||||||
# hash with a '_rev' key
|
# hash with a '_rev' key
|
||||||
def move doc, dest
|
def move doc, dest
|
||||||
raise ArgumentError, "_id and _rev are required for moving" unless doc['_id'] && doc['_rev']
|
raise ArgumentError, "_id and _rev are required for moving" unless doc['_id'] && doc['_rev']
|
||||||
slug = CGI.escape(doc['_id'])
|
slug = escape_docid(doc['_id'])
|
||||||
destination = if dest.respond_to?(:has_key?) && dest['_id'] && dest['_rev']
|
destination = if dest.respond_to?(:has_key?) && dest['_id'] && dest['_rev']
|
||||||
"#{dest['_id']}?rev=#{dest['_rev']}"
|
"#{dest['_id']}?rev=#{dest['_rev']}"
|
||||||
else
|
else
|
||||||
|
@ -214,7 +214,7 @@ module CouchRest
|
||||||
private
|
private
|
||||||
|
|
||||||
def escape_docid id
|
def escape_docid id
|
||||||
|
/^_design\/(.*)/ =~ id ? "_design/#{CGI.escape($1)}" : CGI.escape(id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def encode_attachments attachments
|
def encode_attachments attachments
|
||||||
|
|
Loading…
Reference in a new issue