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'
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from BaseViewSpec
#design_document, #list_function, #list_name, #view_name
Instance Method Summary collapse
- #map_function ⇒ Object
- #process_results(results) ⇒ Object
- #reduce_function ⇒ Object
- #view_parameters ⇒ Object
Methods inherited from BaseViewSpec
Constructor Details
This class inherits a constructor from CouchPotato::View::BaseViewSpec
Instance Method Details
#map_function ⇒ Object
22 23 24 25 26 |
# File 'lib/couch_potato/view/model_view_spec.rb', line 22 def map_function map_body do "emit(#{formatted_key(key)}, 1);" end end |
#process_results(results) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/couch_potato/view/model_view_spec.rb', line 34 def process_results(results) if count? results['rows'].first.try(:[], 'value') || 0 else results['rows'].map { |row| row['doc'] || row['id'] } end end |
#reduce_function ⇒ Object
28 29 30 31 32 |
# File 'lib/couch_potato/view/model_view_spec.rb', line 28 def reduce_function "function(key, values) { return sum(values); }" end |
#view_parameters ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/couch_potato/view/model_view_spec.rb', line 13 def view_parameters _super = super if _super[:reduce] _super else {:include_docs => true, :reduce => false}.merge(_super) end end |