Class: CouchPotato::View::PropertiesViewSpec

Inherits:
ModelViewSpec show all
Defined in:
lib/couch_potato/view/properties_view_spec.rb

Overview

A view to return model instances with only some properties poulated by searching its properties, e.g. for very large documents where you are only interested in some of their data

example:

view :my_view, :key => :name, :properties => [:name, :author], :type => :properties

Instance Attribute Summary

Attributes inherited from BaseViewSpec

#design_document, #lib, #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

#languageObject



36
37
38
# File 'lib/couch_potato/view/properties_view_spec.rb', line 36

def language
  :javascript
end

#map_functionObject



8
9
10
11
12
# File 'lib/couch_potato/view/properties_view_spec.rb', line 8

def map_function
  map_body do
    "emit(#{formatted_key}, #{properties_for_map(properties)});"
  end
end

#process_results(results) ⇒ Object



26
27
28
29
30
# File 'lib/couch_potato/view/properties_view_spec.rb', line 26

def process_results(results)
  results['rows'].map do |row|
    klass.json_create row['value'].merge(:_id => row['id'])
  end
end

#reduce_functionObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/couch_potato/view/properties_view_spec.rb', line 14

def reduce_function
  <<-JS
    function(key, values, rereduce) {
      if(rereduce) {
        return sum(values);
      } else {
        return values.length;
      }
    }
  JS
end

#view_parametersObject



32
33
34
# File 'lib/couch_potato/view/properties_view_spec.rb', line 32

def view_parameters
  {:include_docs => false}.merge(super)
end