Class: CouchPotato::View::CustomViewSpec
- Inherits:
-
BaseViewSpec
- Object
- BaseViewSpec
- CouchPotato::View::CustomViewSpec
- Defined in:
- lib/couch_potato/view/custom_view_spec.rb
Overview
a view for custom map/reduce functions that still returns model instances
example:
view :my_custom_view, :map => "function(doc) { emit(doc._id, null); }", :include_docs => true, :type => :custom, :reduce => nil
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
8 9 10 |
# File 'lib/couch_potato/view/custom_view_spec.rb', line 8 def map_function [:map] end |
#process_results(results) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/couch_potato/view/custom_view_spec.rb', line 20 def process_results(results) if count? results['rows'].first.try(:[], 'value') || 0 else results['rows'].map do |row| if row['doc'].instance_of?(klass) row['doc'] else klass.json_create row['doc'] || row['value'].merge(:_id => row['id'] || row['key']) end end end end |
#reduce_function ⇒ Object
12 13 14 |
# File 'lib/couch_potato/view/custom_view_spec.rb', line 12 def reduce_function [:reduce] end |
#view_parameters ⇒ Object
16 17 18 |
# File 'lib/couch_potato/view/custom_view_spec.rb', line 16 def view_parameters {:include_docs => [:include_docs] || false}.merge(super) end |