Class: RelaxDB::ViewCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/relaxdb/views.rb

Class Method Summary collapse

Class Method Details

.all(target_class) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/relaxdb/views.rb', line 5

def self.all(target_class)
  template = "  function(doc) {\n    if(doc.class == \"${target_class}\")\n      emit(null, doc);\n  }\n  QUERY\n  template.sub!(\"${target_class}\", target_class.to_s)\nend\n"

.has_many_through(target_class, peers) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/relaxdb/views.rb', line 26

def self.has_many_through(target_class, peers)
  template = "    function(doc) {\n      if(doc.class == \"${target_class}\" && doc.${peers}) {\n        var i;\n        for(i = 0; i < doc.${peers}.length; i++) {\n          emit(doc.${peers}[i], doc);\n        }\n      }\n    }\n  MAP_FUNC\n  template.sub!(\"${target_class}\", target_class).gsub!(\"${peers}\", peers)\nend\n"

.has_n(target_class, relationship_to_client) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/relaxdb/views.rb', line 15

def self.has_n(target_class, relationship_to_client)
  template = "  function(doc) {\n    if(doc.class == \"${target_class}\")\n      emit(doc.${relationship_to_client}_id, doc);\n  }\n  MAP_FUNC\n  template.sub!(\"${target_class}\", target_class)\n  template.sub(\"${relationship_to_client}\", relationship_to_client)\nend\n"