Class: CouchPotato::View::ModelViewSpec
- Inherits:
-
BaseViewSpec
- Object
- BaseViewSpec
- CouchPotato::View::ModelViewSpec
- Defined in:
- lib/couch_potato/view/model_view_spec.rb
Overview
A view to return model instances by searching its properties. If you pass reduce => true will count instead
example:
view :my_view, :key => :name
in addition you can pass in conditions as a javascript string
view :my_view_only_completed, :key => :name, :conditions => 'doc.completed = true'
and also a results filter (the results will be run through the given proc):
view :my_view, :key => :name, :results_filter => lambda{|results| results.size}
Direct Known Subclasses
Defined Under Namespace
Classes: ErlangGenerator, JavascriptGenerator
Instance Attribute Summary
Attributes inherited from BaseViewSpec
#design_document, #language, #lib, #list_function, #list_name, #view_name
Instance Method Summary collapse
Methods inherited from BaseViewSpec
Constructor Details
This class inherits a constructor from CouchPotato::View::BaseViewSpec
Instance Method Details
#process_results(results) ⇒ Object
141 142 143 144 145 146 147 148 149 150 |
# File 'lib/couch_potato/view/model_view_spec.rb', line 141 def process_results(results) processed = if count? results['rows'].first.try(:[], 'value') || 0 else results['rows'].map {|row| row['doc'] || (row['id'] unless view_parameters[:include_docs]) }.compact end super processed end |
#reduce_function ⇒ Object
137 138 139 |
# File 'lib/couch_potato/view/model_view_spec.rb', line 137 def reduce_function "_sum" end |
#view_parameters ⇒ Object
128 129 130 131 132 133 134 135 |
# File 'lib/couch_potato/view/model_view_spec.rb', line 128 def view_parameters _super = super if _super[:reduce] _super else {:include_docs => true, :reduce => false}.merge(_super) end end |