Class: SimplyCouch::Model::View::ModelViewSpec
- Inherits:
-
BaseViewSpec
- Object
- BaseViewSpec
- SimplyCouch::Model::View::ModelViewSpec
- Defined in:
- lib/simply_couch/model/view/model_view_spec.rb
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
in addition you can pass in conditions as a javascript string
view :my_view_only_completed, :key => :name, :conditions => 'doc.completed = true'
and also a results filter (the results will be run through the given proc):
view :my_view, :key => :name, :results_filter => lambda{|results| results.size}
Direct Known Subclasses
PropertiesViewSpec, SimplyCouch::Model::Views::ArrayPropertyViewSpec, SimplyCouch::Model::Views::DeletedModelViewSpec
Defined Under Namespace
Classes: JavascriptGenerator
Constant Summary collapse
- RUBY_CLASS_KEY =
The key simply_couch uses for class identification in CouchDB documents
'ruby_class'
Constants inherited from BaseViewSpec
BaseViewSpec::DEFAULT_DIGEST_VIEW_NAMES, BaseViewSpec::DEFAULT_LANGUAGE
Instance Attribute Summary
Attributes inherited from BaseViewSpec
#design_document, #language, #lib, #list_function, #list_name, #view_name
Instance Method Summary collapse
Methods inherited from BaseViewSpec
Constructor Details
This class inherits a constructor from SimplyCouch::Model::View::BaseViewSpec
Instance Method Details
#process_results(results) ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/simply_couch/model/view/model_view_spec.rb', line 83 def process_results(results) processed = if count? results['rows'].first.try(:[], 'value') || 0 else results['rows'].map {|row| row['doc'] || (row['id'] unless view_parameters[:include_docs]) }.compact end super processed end |
#reduce_function ⇒ Object
79 80 81 |
# File 'lib/simply_couch/model/view/model_view_spec.rb', line 79 def reduce_function "_sum" end |
#view_parameters ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/simply_couch/model/view/model_view_spec.rb', line 70 def view_parameters _super = super if _super[:reduce] _super else {:include_docs => true, :reduce => false}.merge(_super) end end |