Class: CouchPotato::View::PropertiesViewSpec
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
#initialize
Instance Method Details
#language ⇒ Object
36
37
38
|
# File 'lib/couch_potato/view/properties_view_spec.rb', line 36
def language
:javascript
end
|
#map_function ⇒ Object
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_function ⇒ Object
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_parameters ⇒ Object
32
33
34
|
# File 'lib/couch_potato/view/properties_view_spec.rb', line 32
def view_parameters
{:include_docs => false}.merge(super)
end
|