Class: CouchRest::Design

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

Instance Method Summary collapse

Instance Method Details

#has_list?(name) ⇒ Boolean

Returns true or false if the view is available.

Returns:

  • (Boolean)


29
30
31
# File 'lib/couchrest/extensions/list.rb', line 29

def has_list?(name)
  !self['lists'][name.to_s].nil?
end

#list(list_name, query = {}, &block) ⇒ Object

Dispatches to any named list. (using the database where this design doc was saved)



7
8
9
# File 'lib/couchrest/extensions/list.rb', line 7

def list list_name, query={}, &block
  list_on database, list_name, query, &block
end

#list_defaults(name) ⇒ Object

Return the hash of default values to include in all queries sent to a list from couchrest.



24
25
26
# File 'lib/couchrest/extensions/list.rb', line 24

def list_defaults(name)
  (self['lists'][name.to_s] && self['lists'][name.to_s]["couchrest-defaults"]) || {}
end

#list_on(db, list_name, view_name, query = {}, &block) ⇒ Object

Dispatches to any named list in a specific database

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
20
# File 'lib/couchrest/extensions/list.rb', line 12

def list_on db, list_name, view_name, query = {}, &block
  raise ArgumentError, "List query options must be set as symbols!" if query.keys.find{|k| k.is_a?(String)}
  list_name = list_name.to_s
  list_slug = "#{name}/#{list_name}/#{view_name}"
  # Set the default query options
  query = list_defaults(list_name).merge(query)

  db.list(list_slug, query, &block)
end