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, #reduce_function, #view_name

Instance Method Summary collapse

Methods inherited from ModelViewSpec

#reduce_function

Methods inherited from BaseViewSpec

#initialize

Constructor Details

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

Instance Method Details

#map_functionObject



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

def map_function
  "function(doc) {
     if(doc.ruby_class && doc.ruby_class == '#{@klass.name}') {
       emit(#{formatted_key(key)}, #{properties_for_map(properties)});
     }
   }"
end

#process_results(results) ⇒ Object



16
17
18
19
20
# File 'lib/couch_potato/view/properties_view_spec.rb', line 16

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

#view_parametersObject



22
23
24
# File 'lib/couch_potato/view/properties_view_spec.rb', line 22

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