Class: SimplyStored::Couch::Views::DeletedModelViewSpec

Inherits:
CouchPotato::View::CustomViewSpec
  • Object
show all
Defined in:
lib/simply_stored/couch/views/deleted_model_view_spec.rb

Instance Method Summary collapse

Instance Method Details

#map_functionObject



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/simply_stored/couch/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_stored/couch/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_stored/couch/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_stored/couch/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