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, #language, #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

#libObject



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

def lib
  options[:lib]
end

#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



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/couch_potato/view/custom_view_spec.rb', line 24

def process_results(results)
  processed = if count?
                results['rows'].first.try(:[], 'value') || 0
              else
                results['rows'].map do |row|
                  if row['doc'].kind_of?(klass)
                    row['doc']
                  else
                    result = row['doc'] || (row['value'].merge(:_id => row['id'] || row['key']) unless view_parameters[:include_docs])
                    klass.json_create result if result
                  end
                end.compact
              end
  super processed
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



20
21
22
# File 'lib/couch_potato/view/custom_view_spec.rb', line 20

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