Module: CouchRestAdapter::QueryViews::ClassMethods

Defined in:
lib/couch_rest_adapter/query_views.rb

Instance Method Summary collapse

Instance Method Details

#find_by_attribute(attr_name, value, doc_name) ⇒ Object



14
15
16
17
18
# File 'lib/couch_rest_adapter/query_views.rb', line 14

def find_by_attribute attr_name, value, doc_name
  document_name = 'by_attribute'
  key_value = [object_name, attr_name, value]
  view_by_key document_name, key_value, doc_name
end

#query_view(name, doc_name) ⇒ Object



20
21
22
# File 'lib/couch_rest_adapter/query_views.rb', line 20

def query_view name, doc_name
  view_by_key name, object_name, doc_name
end

#view(doc, attrs, reduce = false) ⇒ Object

TODO: method for reduce, and filters



30
31
32
# File 'lib/couch_rest_adapter/query_views.rb', line 30

def view doc, attrs, reduce = false
  database.view(doc, {reduce: reduce, include_docs: true}.merge!(attrs) )
end

#view_by_key(name, key = nil, doc_name = nil) ⇒ Object



24
25
26
27
# File 'lib/couch_rest_adapter/query_views.rb', line 24

def view_by_key name, key = nil, doc_name = nil
  doc = name.namespace_me(doc_name)
  view(doc, {key: key})['rows'].map{ |res| new res['doc'] }
end