Class: CouchPotato::View::CustomViewSpec

Inherits:
BaseViewSpec show all
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

Methods inherited from BaseViewSpec

#initialize

Constructor Details

This class inherits a constructor from CouchPotato::View::BaseViewSpec

Instance Method Details

#map_functionObject



8
9
10
# File 'lib/couch_potato/view/custom_view_spec.rb', line 8

def map_function
  options[: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_functionObject



12
13
14
# File 'lib/couch_potato/view/custom_view_spec.rb', line 12

def reduce_function
  options[:reduce]
end

#view_parametersObject



16
17
18
# File 'lib/couch_potato/view/custom_view_spec.rb', line 16

def view_parameters
  {:include_docs => options[:include_docs] || false}.merge(super)
end