Class: CouchRest::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/couchrest/extensions/list.rb

Instance Method Summary collapse

Instance Method Details

#list(name, params = {}, payload = {}, &block) ⇒ Object

List based queries

Query a CouchDB list as defined by a _design document. Accepts paramaters as described in wiki.apache.org/couchdb/HttpViewApi



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 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