Class: SimplyCouch::Model::Views::DeletedModelViewSpec

Inherits:
SimplyCouch::Model::View::ModelViewSpec show all
Defined in:
lib/simply_couch/model/views/deleted_model_view_spec.rb

Constant Summary

Constants inherited from SimplyCouch::Model::View::ModelViewSpec

SimplyCouch::Model::View::ModelViewSpec::RUBY_CLASS_KEY

Constants inherited from SimplyCouch::Model::View::BaseViewSpec

SimplyCouch::Model::View::BaseViewSpec::DEFAULT_DIGEST_VIEW_NAMES, SimplyCouch::Model::View::BaseViewSpec::DEFAULT_LANGUAGE

Instance Attribute Summary

Attributes inherited from SimplyCouch::Model::View::BaseViewSpec

#design_document, #language, #lib, #list_function, #list_name, #view_name

Instance Method Summary collapse

Methods inherited from SimplyCouch::Model::View::BaseViewSpec

#initialize

Constructor Details

This class inherits a constructor from SimplyCouch::Model::View::BaseViewSpec

Instance Method Details

#map_functionObject



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/simply_couch/model/views/deleted_model_view_spec.rb', line 5

def map_function
  <<-eos
    function(doc) {
      if (doc.ruby_class && doc.ruby_class == '#{@klass.name}') {
        if (doc['#{@klass.soft_delete_attribute}'] && doc['#{@klass.soft_delete_attribute}'] != null){
          // "soft" deleted
        }else{
          emit(doc.created_at, 1);
        }
      }
    }
  eos
end

#process_results(results) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/simply_couch/model/views/deleted_model_view_spec.rb', line 32

def process_results(results)
  if count?
    results['rows'].first.try(:[], 'value') || 0
  else
    results['rows'].map { |row| row['doc'] || row['id'] }
  end
end

#reduce_functionObject



19
20
21
# File 'lib/simply_couch/model/views/deleted_model_view_spec.rb', line 19

def reduce_function
  '_sum'
end

#view_parametersObject



23
24
25
26
27
28
29
30
# File 'lib/simply_couch/model/views/deleted_model_view_spec.rb', line 23

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