Class: CouchPotato::View::ModelViewSpec

Inherits:
BaseViewSpec show all
Defined in:
lib/couch_potato/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

Defined Under Namespace

Classes: ErlangGenerator, JavascriptGenerator

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

#initialize

Constructor Details

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

Instance Method Details

- (Object) process_results(results)



141
142
143
144
145
146
147
148
149
150
# File 'lib/couch_potato/view/model_view_spec.rb', line 141

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

- (Object) reduce_function



137
138
139
# File 'lib/couch_potato/view/model_view_spec.rb', line 137

def reduce_function
  "_sum"
end

- (Object) view_parameters



128
129
130
131
132
133
134
135
# File 'lib/couch_potato/view/model_view_spec.rb', line 128

def view_parameters
  _super = super
  if _super[:reduce]
    _super
  else
    {:include_docs => true, :reduce => false}.merge(_super)
  end
end