class CouchRest::Database
Public Instance Methods
list(name, params = {}, payload = {}, &block)
click to toggle source
List based queries¶ ↑
Query a CouchDB list as defined by a _design
document. Accepts paramaters as described in wiki.apache.org/couchdb/HttpViewApi
# File lib/couchrest/extensions/list.rb, line 48 def list(name, params = {}, payload = {}, &block) payload['keys'] = params.delete(:keys) if params[:keys] #params.delete(:keys) # Try recognising the name, otherwise assume already prepared list_path = name_to_list_path(name) url = CouchRest.paramify_url "#{@root}/#{list_path}", params #p [:url, url] if block_given? if !payload.empty? @streamer.post url, payload, &block else @streamer.get url, &block end else if !payload.empty? CouchRest.post url, payload else CouchRest.get url end end end
Private Instance Methods
name_to_list_path(name)
click to toggle source
Convert a simplified list name into a complete list path. If the name already starts with a “_” no alterations will be made.
# File lib/couchrest/extensions/list.rb, line 73 def name_to_list_path(name) name =~ /^([^_].+?)\/(.*)$/ ? "_design/#{$1}/_list/#{$2}" : name end