Class: CouchPotato::View::ModelViewSpec
Overview
A view to return model instances by searching its properties. If you pass reduce => true will count instead
example:
view :my_view, :key => :name
Instance Attribute Summary
Attributes inherited from BaseViewSpec
#design_document, #view_name
Instance Method Summary
collapse
#initialize
Instance Method Details
#map_function ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/couch_potato/view/model_view_spec.rb', line 19
def map_function
"function(doc) {
if(doc.#{JSON.create_id} && doc.#{JSON.create_id} == '#{@klass.name}') {
emit(#{formatted_key(key)}, null);
}
}"
end
|
#process_results(results) ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/couch_potato/view/model_view_spec.rb', line 33
def process_results(results)
if count?
results['rows'].first.try(:[], 'value') || 0
else
results['rows'].map { |row| row['doc'] }
end
end
|
#reduce_function ⇒ Object
27
28
29
30
31
|
# File 'lib/couch_potato/view/model_view_spec.rb', line 27
def reduce_function
"function(key, values) {
return values.length;
}"
end
|
#view_parameters ⇒ Object
10
11
12
13
14
15
16
17
|
# File 'lib/couch_potato/view/model_view_spec.rb', line 10
def view_parameters
_super = super
if _super[:reduce]
_super
else
{:include_docs => true, :reduce => false}.merge(_super)
end
end
|